From f50b98cb7c23158b5f43d7756e2068b9d0b76c7e Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 3 Feb 2026 14:39:18 +0100 Subject: [PATCH 1/4] screenshot via callback --- .../include/botcraft/Renderer/RenderingManager.hpp | 2 ++ botcraft/src/Renderer/RenderingManager.cpp | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/botcraft/include/botcraft/Renderer/RenderingManager.hpp b/botcraft/include/botcraft/Renderer/RenderingManager.hpp index 9bbc30e0..cfacd4f6 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 &)> callback); void SetCurrentBehaviourTree(const BaseNode* root) const; void ResetBehaviourState() const; @@ -183,6 +184,7 @@ namespace Botcraft std::function(KEY_CODE::NUMBER_OF_KEYS)>, double)> KeyboardCallback; std::string screenshot_path; + std::optional &)>> screenshot_callback; bool take_screenshot; bool running; diff --git a/botcraft/src/Renderer/RenderingManager.cpp b/botcraft/src/Renderer/RenderingManager.cpp index 632317aa..38e3ef36 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_height, current_window_width, pixels); take_screenshot = false; } @@ -385,6 +388,14 @@ namespace Botcraft void RenderingManager::Screenshot(const std::string& path) { screenshot_path = path; + screenshot_callback.reset(); + take_screenshot = true; + } + + void RenderingManager::Screenshot(std::function &)> callback) + { + screenshot_path.clear(); + screenshot_callback = callback; take_screenshot = true; } From cbe6892950be4871b8a63204ef80cc1850c847f8 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 3 Feb 2026 14:50:28 +0100 Subject: [PATCH 2/4] Switched parameters --- botcraft/src/Renderer/RenderingManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botcraft/src/Renderer/RenderingManager.cpp b/botcraft/src/Renderer/RenderingManager.cpp index 38e3ef36..d76384bc 100644 --- a/botcraft/src/Renderer/RenderingManager.cpp +++ b/botcraft/src/Renderer/RenderingManager.cpp @@ -344,7 +344,7 @@ namespace Botcraft if (screenshot_path.empty() == false) WriteImage(screenshot_path, current_window_height, current_window_width, 3, pixels.data(), true); else - screenshot_callback.value()(current_window_height, current_window_width, pixels); + screenshot_callback.value()(current_window_width, current_window_height, pixels); take_screenshot = false; } From 363b6fe0fb0f64cbca47f23cd46a05ee1137c6e7 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 3 Feb 2026 18:05:13 +0100 Subject: [PATCH 3/4] give arguments to screenshot callback --- botcraft/include/botcraft/Renderer/RenderingManager.hpp | 9 +++++---- botcraft/src/Renderer/RenderingManager.cpp | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/botcraft/include/botcraft/Renderer/RenderingManager.hpp b/botcraft/include/botcraft/Renderer/RenderingManager.hpp index cfacd4f6..5485e749 100644 --- a/botcraft/include/botcraft/Renderer/RenderingManager.hpp +++ b/botcraft/include/botcraft/Renderer/RenderingManager.hpp @@ -74,7 +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 &)> callback); + void Screenshot(std::function &, void *arg)> callback); void SetCurrentBehaviourTree(const BaseNode* root) const; void ResetBehaviourState() const; @@ -183,9 +183,10 @@ namespace Botcraft std::function MouseCallback; std::function(KEY_CODE::NUMBER_OF_KEYS)>, double)> KeyboardCallback; - std::string screenshot_path; - std::optional &)>> screenshot_callback; - 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 d76384bc..fc037757 100644 --- a/botcraft/src/Renderer/RenderingManager.cpp +++ b/botcraft/src/Renderer/RenderingManager.cpp @@ -344,7 +344,7 @@ namespace Botcraft 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_callback.value()(current_window_width, current_window_height, pixels, screenshot_arg); take_screenshot = false; } @@ -392,7 +392,7 @@ namespace Botcraft take_screenshot = true; } - void RenderingManager::Screenshot(std::function &)> callback) + void RenderingManager::Screenshot(std::function &, void *args)> callback) { screenshot_path.clear(); screenshot_callback = callback; From d4c64d28b1c61be5d93e7aa6df684fc8359f3e8e Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 3 Feb 2026 18:10:22 +0100 Subject: [PATCH 4/4] give arguments to screenshot callback - set that argument in Screenshot call --- botcraft/include/botcraft/Renderer/RenderingManager.hpp | 2 +- botcraft/src/Renderer/RenderingManager.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/botcraft/include/botcraft/Renderer/RenderingManager.hpp b/botcraft/include/botcraft/Renderer/RenderingManager.hpp index 5485e749..56e0534b 100644 --- a/botcraft/include/botcraft/Renderer/RenderingManager.hpp +++ b/botcraft/include/botcraft/Renderer/RenderingManager.hpp @@ -74,7 +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 Screenshot(std::function &, void *arg)> callback, void *arg); void SetCurrentBehaviourTree(const BaseNode* root) const; void ResetBehaviourState() const; diff --git a/botcraft/src/Renderer/RenderingManager.cpp b/botcraft/src/Renderer/RenderingManager.cpp index fc037757..d3c330f9 100644 --- a/botcraft/src/Renderer/RenderingManager.cpp +++ b/botcraft/src/Renderer/RenderingManager.cpp @@ -389,13 +389,15 @@ namespace Botcraft { screenshot_path = path; screenshot_callback.reset(); + screenshot_arg = nullptr; take_screenshot = true; } - void RenderingManager::Screenshot(std::function &, void *args)> callback) + void RenderingManager::Screenshot(std::function &, void *args)> callback, void *arg) { screenshot_path.clear(); screenshot_callback = callback; + screenshot_arg = arg; take_screenshot = true; }