diff --git a/include/flamegpu/gpu/CUDASimulation.h b/include/flamegpu/gpu/CUDASimulation.h index 2df5cc6de..02cfb77b6 100644 --- a/include/flamegpu/gpu/CUDASimulation.h +++ b/include/flamegpu/gpu/CUDASimulation.h @@ -51,6 +51,9 @@ class CUDASimulation : public Simulation { friend class HostAgentAPI; friend class SimRunner; friend class CUDAEnsemble; +#ifdef VISUALISATION + friend class visualiser::ModelVis; +#endif /** * Map of a number of CUDA agents by name. * The CUDA agents are responsible for allocating and managing all the device memory diff --git a/include/flamegpu/visualiser/ModelVis.h b/include/flamegpu/visualiser/ModelVis.h index 1cd2c9576..9d49e8bad 100644 --- a/include/flamegpu/visualiser/ModelVis.h +++ b/include/flamegpu/visualiser/ModelVis.h @@ -210,6 +210,10 @@ class ModelVis { * Random seed has changed */ void updateRandomSeed(); + /** + * Singletons have init, so env props are ready to grab + */ + void registerEnvProperties(); private: /** @@ -242,6 +246,10 @@ class ModelVis { * Pointer to the visualisation */ std::unique_ptr visualiser; + /** + * Only need to register env properties once + */ + bool env_registered = false; }; } // namespace visualiser diff --git a/src/flamegpu/gpu/CUDASimulation.cu b/src/flamegpu/gpu/CUDASimulation.cu index f9861427b..fc296b640 100644 --- a/src/flamegpu/gpu/CUDASimulation.cu +++ b/src/flamegpu/gpu/CUDASimulation.cu @@ -1550,6 +1550,7 @@ void CUDASimulation::initialiseSingletons() { #ifdef VISUALISATION if (visualisation) { visualisation->updateRandomSeed(); // Incase user hasn't triggered applyConfig() + visualisation->registerEnvProperties(); } #endif diff --git a/src/flamegpu/visualiser/ModelVis.cpp b/src/flamegpu/visualiser/ModelVis.cpp index 5d25be1d8..54d33550a 100644 --- a/src/flamegpu/visualiser/ModelVis.cpp +++ b/src/flamegpu/visualiser/ModelVis.cpp @@ -79,9 +79,20 @@ void ModelVis::_activate() { } agent.second.initBindings(visualiser); } + env_registered = false; + registerEnvProperties(); visualiser->start(); } } +void ModelVis::registerEnvProperties() { + if (model.singletons && !env_registered) { + char * const host_env_origin = const_cast(static_cast(model.singletons->environment->getHostBuffer())); + for (const auto& prop : model.singletons->environment->getPropertiesMap()) { + visualiser->registerEnvironmentProperty(prop.first, host_env_origin + prop.second.offset, prop.second.type, prop.second.elements, prop.second.isConst); + } + env_registered = true; + } +} void ModelVis::deactivate() { if (visualiser && visualiser->isRunning()) {