Skip to content

Commit

Permalink
Draft support for visualising environment properties (F2 menu)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Aug 11, 2022
1 parent 7df736d commit 6af36b1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/flamegpu/gpu/CUDASimulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions include/flamegpu/visualiser/ModelVis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/**
Expand Down Expand Up @@ -242,6 +246,10 @@ class ModelVis {
* Pointer to the visualisation
*/
std::unique_ptr<FLAMEGPU_Visualisation> visualiser;
/**
* Only need to register env properties once
*/
bool env_registered = false;
};

} // namespace visualiser
Expand Down
1 change: 1 addition & 0 deletions src/flamegpu/gpu/CUDASimulation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ void CUDASimulation::initialiseSingletons() {
#ifdef VISUALISATION
if (visualisation) {
visualisation->updateRandomSeed(); // Incase user hasn't triggered applyConfig()
visualisation->registerEnvProperties();
}
#endif

Expand Down
11 changes: 11 additions & 0 deletions src/flamegpu/visualiser/ModelVis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(static_cast<const char *>(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()) {
Expand Down

0 comments on commit 6af36b1

Please sign in to comment.