Botcraft 1.21.11
Loading...
Searching...
No Matches
Settings.cpp
Go to the documentation of this file.
3
4#if USE_GUI
6#endif
7
8namespace Botcraft::Renderer
9{
10#if !USE_GUI
11 static bool settings_first_time = true;
12#define CHECK_GUI if (settings_first_time) { LOG_WARNING("Botcraft compiled without UI support. Rendering function call ignored. Recompile with BOTCRAFT_USE_GUI to enable GUI support."); } settings_first_time = false
13#else
14 #define CHECK_GUI static_assert(true, "requires ; after call")
15#endif
16
17 std::atomic<bool> Settings::enabled = false;
18 std::atomic<int> Settings::width = 800;
19 std::atomic<int> Settings::height = 600;
20 std::atomic<bool> Settings::headless = false;
21 std::atomic<bool> Settings::vsync = true;
22 std::atomic<double> Settings::target_fps = 60.0;
23
25 std::string Settings::screenhsot_path = "";
26 std::function<void(const std::vector<unsigned char>& pixels, const int height, const int width)> Settings::screenshot_callback = nullptr;
27
29 {
31#if !USE_GUI
32 return false;
33#else
34 return enabled.load(std::memory_order_relaxed);
35#endif
36 }
37
38 void Settings::Enable(const bool enable)
39 {
41#if USE_GUI
42 enabled = enable;
43#endif
44 }
45
47 {
49 enabled = false;
50 }
51
52 void Settings::Headless(const bool headless)
53 {
56 }
57
58 void Settings::ShowWindow(const bool show)
59 {
61 headless = !show;
62 }
63
65 {
67 headless = true;
68 }
69
70 void Settings::SetResolution(const int width, const int height)
71 {
75 }
76
77 std::pair<int, int> Settings::GetResolution()
78 {
79 return { width, height };
80 }
81
82 void Settings::TakeScreenshot(const std::string& path)
83 {
85 std::scoped_lock<std::mutex> lock(screenshot_mutex);
86 screenhsot_path = path;
87 }
88
89 void Settings::TakeScreenshot(const std::function<void(const std::vector<unsigned char>&, const int, const int)>& callback)
90 {
92 std::scoped_lock<std::mutex> lock(screenshot_mutex);
93 screenshot_callback = callback;
94 }
95
96 void Settings::EnableVsync(const bool enable)
97 {
99 vsync = enable;
100 }
101
103 {
104 CHECK_GUI;
105 vsync = false;
106 }
107
108 void Settings::SetMaxFramerate(const double fps)
109 {
110 CHECK_GUI;
111 target_fps = fps;
112 }
113}
#define CHECK_GUI
Definition Settings.cpp:14
static void SetMaxFramerate(const double fps)
Set the max framerate for the rendering loop. Set to 0 for no limit.
Definition Settings.cpp:108
static void SetResolution(const int width, const int height)
Try to change the resolution of the rendering window. This can be limited by specific OS constraints ...
Definition Settings.cpp:70
static std::string screenhsot_path
Definition Settings.hpp:61
static void Enable(const bool enable=true)
Set the renderer enabled state the for next client.
Definition Settings.cpp:38
static void TakeScreenshot(const std::string &path)
Render and save the next rendered frame.
Definition Settings.cpp:82
static void HideWindow()
Hide the rendering window.
Definition Settings.cpp:64
static void DisableVsync()
Disable the vsync for the rendering loop.
Definition Settings.cpp:102
static std::mutex screenshot_mutex
Definition Settings.hpp:60
static std::function< void(const std::vector< unsigned char > &pixels, const int height, const int width)> screenshot_callback
Definition Settings.hpp:62
static std::atomic< bool > enabled
Definition Settings.hpp:54
static void ShowWindow(const bool show=true)
Show/hide the rendering window.
Definition Settings.cpp:58
static void EnableVsync(const bool enable=true)
Enable/disable the vsync for the rendering loop.
Definition Settings.cpp:96
static std::atomic< int > height
Definition Settings.hpp:55
static std::atomic< bool > vsync
Definition Settings.hpp:58
static void Headless(const bool headless=true)
Make the renderer headless (hide the display window).
Definition Settings.cpp:52
static std::atomic< int > width
Definition Settings.hpp:56
static std::atomic< bool > headless
Definition Settings.hpp:57
static std::pair< int, int > GetResolution()
Get the current resolution of the renderer.
Definition Settings.cpp:77
static std::atomic< double > target_fps
Definition Settings.hpp:59
static void Disable()
Disable the rendering for all future clients.
Definition Settings.cpp:46