From 02097b5ca1bf38a52693e926d0d750d972a2ae80 Mon Sep 17 00:00:00 2001 From: Robert Chisholm Date: Sat, 11 Mar 2023 15:02:54 +0000 Subject: [PATCH] Fix begin paused behaviour Adds an additional block, after buffers have been resized, until begin paused has had a chance to take effect. Closes #53 --- include/flamegpu/visualiser/FLAMEGPU_Visualisation.h | 4 ++++ src/flamegpu/visualiser/FLAMEGPU_Visualisation.cpp | 3 +++ src/flamegpu/visualiser/Visualiser.cpp | 8 +++++++- src/flamegpu/visualiser/Visualiser.h | 8 ++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/flamegpu/visualiser/FLAMEGPU_Visualisation.h b/include/flamegpu/visualiser/FLAMEGPU_Visualisation.h index 3b0f1da..5ef476a 100644 --- a/include/flamegpu/visualiser/FLAMEGPU_Visualisation.h +++ b/include/flamegpu/visualiser/FLAMEGPU_Visualisation.h @@ -69,6 +69,10 @@ class FLAMEGPU_Visualisation { /** * Set true when the vis has resized the first agent's buffers */ + bool buffersReady() const; + /** + * Set true when the vis has had a chance to pause if beginPaused is enabled + */ bool isReady() const; private: diff --git a/src/flamegpu/visualiser/FLAMEGPU_Visualisation.cpp b/src/flamegpu/visualiser/FLAMEGPU_Visualisation.cpp index 877c74b..3009552 100644 --- a/src/flamegpu/visualiser/FLAMEGPU_Visualisation.cpp +++ b/src/flamegpu/visualiser/FLAMEGPU_Visualisation.cpp @@ -59,6 +59,9 @@ void FLAMEGPU_Visualisation::stop() { bool FLAMEGPU_Visualisation::isRunning() const { return vis->isRunning(); } +bool FLAMEGPU_Visualisation::buffersReady() const { + return vis->buffersReady(); +} bool FLAMEGPU_Visualisation::isReady() const { return vis->isReady(); } diff --git a/src/flamegpu/visualiser/Visualiser.cpp b/src/flamegpu/visualiser/Visualiser.cpp index 4760e80..a227eda 100644 --- a/src/flamegpu/visualiser/Visualiser.cpp +++ b/src/flamegpu/visualiser/Visualiser.cpp @@ -110,6 +110,7 @@ Visualiser::Visualiser(const ModelConfig& modelcfg) , isInitialised(false) , continueRender(false) , buffersAllocated(false) + , visualisationLoaded(false) , msaaState(true) , windowTitle(modelcfg.windowTitle) , windowDims(modelcfg.windowDimensions[0], modelcfg.windowDimensions[1]) @@ -465,9 +466,12 @@ void Visualiser::render() { bool Visualiser::isRunning() const { return continueRender; } -bool Visualiser::isReady() const { +bool Visualiser::buffersReady() const { return buffersAllocated; } +bool Visualiser::isReady() const { + return visualisationLoaded; +} void Visualiser::addAgentState(const std::string &agent_name, const std::string &state_name, const AgentStateConfig &vc, const std::map& core_tex_buffers, const std::multimap& tex_buffers) { std::pair namepair = { agent_name, state_name }; @@ -580,6 +584,8 @@ void Visualiser::renderAgentStates() { this->pause_guard = guard; guard = nullptr; } + // Notify the sim that we're ready and it can continue + visualisationLoaded = true; } } diff --git a/src/flamegpu/visualiser/Visualiser.h b/src/flamegpu/visualiser/Visualiser.h index 85ad1e0..5b4602e 100644 --- a/src/flamegpu/visualiser/Visualiser.h +++ b/src/flamegpu/visualiser/Visualiser.h @@ -88,6 +88,10 @@ class Visualiser : public ViewportExt { /** * Returns true if the first agent buffer resize has been requested and applied */ + bool buffersReady() const; + /** + * Returns true if the beginPaused has had a chance to be activated + */ bool isReady() const; /** * Adds the render details for a specific agent state @@ -272,6 +276,10 @@ class Visualiser : public ViewportExt { */ std::atomic continueRender; std::atomic buffersAllocated; + /** + * Flag which notifies the simulation it can continue past step 0 + */ + std::atomic visualisationLoaded; /** * Flag representing whether MSAA is currently enabled * MSAA can be toggled at runtime with F10