diff --git a/botcraft/include/botcraft/Renderer/RenderingManager.hpp b/botcraft/include/botcraft/Renderer/RenderingManager.hpp index 9bbc30e0..56e0534b 100644 --- a/botcraft/include/botcraft/Renderer/RenderingManager.hpp +++ b/botcraft/include/botcraft/Renderer/RenderingManager.hpp @@ -74,6 +74,7 @@ namespace Botcraft // Take a screenshot of the current frame and save it to path void Screenshot(const std::string& path); + void Screenshot(std::function &, void *arg)> callback, void *arg); void SetCurrentBehaviourTree(const BaseNode* root) const; void ResetBehaviourState() const; @@ -182,8 +183,10 @@ namespace Botcraft std::function MouseCallback; std::function(KEY_CODE::NUMBER_OF_KEYS)>, double)> KeyboardCallback; - std::string screenshot_path; - bool take_screenshot; + std::string screenshot_path; + std::optional &, void *arg)>> screenshot_callback; + void *screenshot_arg { nullptr }; + bool take_screenshot; bool running; diff --git a/botcraft/src/Renderer/RenderingManager.cpp b/botcraft/src/Renderer/RenderingManager.cpp index 632317aa..d3c330f9 100644 --- a/botcraft/src/Renderer/RenderingManager.cpp +++ b/botcraft/src/Renderer/RenderingManager.cpp @@ -341,7 +341,10 @@ namespace Botcraft std::vector pixels(current_window_height * current_window_width * 3); glReadPixels(0, 0, current_window_width, current_window_height, GL_RGB, GL_UNSIGNED_BYTE, pixels.data()); - WriteImage(screenshot_path, current_window_height, current_window_width, 3, pixels.data(), true); + if (screenshot_path.empty() == false) + WriteImage(screenshot_path, current_window_height, current_window_width, 3, pixels.data(), true); + else + screenshot_callback.value()(current_window_width, current_window_height, pixels, screenshot_arg); take_screenshot = false; } @@ -385,6 +388,16 @@ namespace Botcraft void RenderingManager::Screenshot(const std::string& path) { screenshot_path = path; + screenshot_callback.reset(); + screenshot_arg = nullptr; + take_screenshot = true; + } + + void RenderingManager::Screenshot(std::function &, void *args)> callback, void *arg) + { + screenshot_path.clear(); + screenshot_callback = callback; + screenshot_arg = arg; take_screenshot = true; }