From 4f6e747753fba081fab7bf533f94495ace8e378e Mon Sep 17 00:00:00 2001 From: Robert Chisholm Date: Sat, 25 Mar 2023 19:45:46 +0000 Subject: [PATCH] wip --- include/flamegpu/visualiser/ModelVis.h | 4 ++++ src/flamegpu/visualiser/ModelVis.cpp | 13 +++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/flamegpu/visualiser/ModelVis.h b/include/flamegpu/visualiser/ModelVis.h index ed92c07cc..4b85fa8db 100644 --- a/include/flamegpu/visualiser/ModelVis.h +++ b/include/flamegpu/visualiser/ModelVis.h @@ -62,6 +62,10 @@ struct ModelVisData { * Only need to register env properties once */ bool env_registered = false; + /** + * Marked true when first agent data has been passed to vis + */ + bool has_first_agents = true; /** * Updates all agent renders from corresponding * @param sc Step count, the step count value shown in visualisation HUD diff --git a/src/flamegpu/visualiser/ModelVis.cpp b/src/flamegpu/visualiser/ModelVis.cpp index 59cff4c6a..5e9fd3d1c 100644 --- a/src/flamegpu/visualiser/ModelVis.cpp +++ b/src/flamegpu/visualiser/ModelVis.cpp @@ -34,12 +34,16 @@ void ModelVisData::registerEnvProperties() { } void ModelVisData::updateBuffers(const unsigned int& sc) { if (visualiser) { - bool has_agents = false; + bool _has_first_agents = false; for (auto& a : agents) { - has_agents = a.second->requestBufferResizes(visualiser, sc == 0 || sc == UINT_MAX) || has_agents; + _has_first_agents = a.second->requestBufferResizes(visualiser, sc == 0 || sc == UINT_MAX) || _has_first_agents; + } + if (_has_first_agents) { + _has_first_agents = !this->has_first_agents; + this->has_first_agents = true; } // Block the sim when we first get agents, until vis has resized buffers, incase vis is being slow to init - if (has_agents && (sc == 0 || sc == UINT_MAX)) { + if (_has_first_agents) { while (!visualiser->buffersReady()) { // Do nothing, just spin until ready std::this_thread::yield(); @@ -56,7 +60,7 @@ void ModelVisData::updateBuffers(const unsigned int& sc) { } visualiser->releaseMutex(); // Block the sim again, until vis is fully ready - if (has_agents && (sc == 0 || sc == UINT_MAX)) { + if (_has_first_agents) { while (!visualiser->isReady()) { // Do nothing, just spin until ready std::this_thread::yield(); @@ -135,6 +139,7 @@ void ModelVis::_activate() { agent.second->initBindings(data->visualiser); } data->env_registered = false; + data->has_first_agents = false; data->registerEnvProperties(); data->visualiser->start(); }