Botcraft 1.21.11
Loading...
Searching...
No Matches
Settings.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <functional>
5#include <mutex>
6#include <string>
7
8namespace Botcraft::Renderer
9{
10 class RenderingManager;
11
13 {
14 public:
15 static bool IsEnabled();
16
17 /// @brief Set the renderer enabled state the for next client
18 /// @param enable If true, next Client will try to create a renderer
19 static void Enable(const bool enable = true);
20 /// @brief Disable the rendering for all future clients
21 static void Disable();
22 /// @brief Make the renderer headless (hide the display window).
23 /// @param headless If true, the window will be hidden (headless mode).
24 /// Note that you still need *some* display device available to create the rendering context
25 static void Headless(const bool headless = true);
26 /// @brief Show/hide the rendering window
27 /// @param show If true, the window will be shown, will be hidden otherwise (headless mode).
28 /// Note that you still need *some* display device available to create the rendering context
29 static void ShowWindow(const bool show = true);
30 /// @brief Hide the rendering window
31 static void HideWindow();
32 /// @brief Try to change the resolution of the rendering window. This can be limited by specific OS constraints or a user resizing the window.
33 static void SetResolution(const int width, const int height);
34 /// @brief Get the current resolution of the renderer
35 /// @return A pair of int, { width, height }
36 static std::pair<int, int> GetResolution();
37 /// @brief Render and save the next rendered frame
38 /// @param path Path to save the PNG image to
39 static void TakeScreenshot(const std::string& path);
40 /// @brief Render the next image and pass the raw pixels to the given callback. Pixels are in HWC order
41 /// @param callback Function to call with the frame raw pixels. Params are pixels, height, width
42 static void TakeScreenshot(const std::function<void(const std::vector<unsigned char>& pixels, const int height, const int width)>& callback);
43 /// @brief Enable/disable the vsync for the rendering loop
44 /// @param enable If true, vsync will be enabled
45 static void EnableVsync(const bool enable = true);
46 /// @brief Disable the vsync for the rendering loop
47 static void DisableVsync();
48 /// @brief Set the max framerate for the rendering loop. Set to 0 for no limit
49 static void SetMaxFramerate(const double fps);
50
52
53 private:
54 static std::atomic<bool> enabled;
55 static std::atomic<int> height;
56 static std::atomic<int> width;
57 static std::atomic<bool> headless;
58 static std::atomic<bool> vsync;
59 static std::atomic<double> target_fps;
60 static std::mutex screenshot_mutex;
61 static std::string screenhsot_path;
62 static std::function<void(const std::vector<unsigned char>& pixels, const int height, const int width)> screenshot_callback;
63 };
64}
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 void TakeScreenshot(const std::function< void(const std::vector< unsigned char > &pixels, const int height, const int width)> &callback)
Render the next image and pass the raw pixels to the given callback.
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