diff --git a/Source/SimulationManager/imstkSimulationManager.cpp b/Source/SimulationManager/imstkSimulationManager.cpp index 53bba9287c0dacdb090da4807e84ae3061d7a418..c4c169a1437e13e70999477ced02c2aea8b6693b 100644 --- a/Source/SimulationManager/imstkSimulationManager.cpp +++ b/Source/SimulationManager/imstkSimulationManager.cpp @@ -84,7 +84,7 @@ SimulationManager::start() for (auto module : m_asyncModules) { FuncTask* moduleTask = new(tbb::task::allocate_root())FuncTask(module, - std::bind(&SimulationManager::runModuleParallel, this, std::placeholders::_1)); + std::bind(&SimulationManager::runModuleParallel, this, std::placeholders::_1)); taskList.push_back(*moduleTask); } tbb::task::spawn_root_and_wait(taskList); @@ -101,6 +101,8 @@ SimulationManager::start() waitForInit(); + postEvent(Event(EventType::Start)); + // Start the game loop { const double desiredDt_ms = m_desiredDt * 1000.0; // ms @@ -193,6 +195,8 @@ SimulationManager::start() } } + postEvent(Event(EventType::End)); + if (m_threadType == ThreadingType::TBB) { } @@ -243,6 +247,8 @@ SimulationManager::runModuleParallel(std::shared_ptr<Module> module) waitForInit(); + postEvent(Event(EventType::Start)); + m_running[module.get()] = true; while (m_running[module.get()]) { @@ -263,6 +269,8 @@ SimulationManager::runModuleParallel(std::shared_ptr<Module> module) module->update(); } } + + postEvent(Event(EventType::End)); } void diff --git a/Source/SimulationManager/imstkSimulationManager.h b/Source/SimulationManager/imstkSimulationManager.h index 1fb9db5de5ced5d3da70092f105c5f73c134dbbf..2cac2166c53340f202d71d9b43f49c59e63e4011 100644 --- a/Source/SimulationManager/imstkSimulationManager.h +++ b/Source/SimulationManager/imstkSimulationManager.h @@ -17,7 +17,7 @@ See the License for the specific language governing permissions and limitations under the License. -=========================================================================*/ + =========================================================================*/ #pragma once @@ -40,6 +40,8 @@ class Viewer; /// This is the preferred driver. /// todo: Timestep smoothening /// +/// Events: Posts `EventType::Start` just before the beginning of the loop, +/// posts `EventType::Stop` just after the processing loops is being exited class SimulationManager : public ModuleDriver { public: @@ -67,18 +69,31 @@ public: /// This ultimately effects the number of iterations done /// default 0.003 /// - void setDesiredDt(const double dt) { m_desiredDt = dt; } - double getDesiredDt() const { return m_desiredDt; } + void setDesiredDt(const double dt) + { + m_desiredDt = dt; + } + + double getDesiredDt() const + { + return m_desiredDt; + } /// /// \brief Get the current actual timestep /// - double getDt() const { return m_dt; } + double getDt() const + { + return m_dt; + } /// /// \brief Set the thread type to run the parallel modules with /// - void setThreadType(ThreadingType threadType) { m_threadType = threadType; } + void setThreadType(ThreadingType threadType) + { + m_threadType = threadType; + } protected: void requestStop(Event* e); @@ -88,9 +103,9 @@ protected: protected: std::vector<std::shared_ptr<Viewer>> m_viewers; - std::vector<std::shared_ptr<Module>> m_syncModules; ///> Modules called once per update - std::vector<std::shared_ptr<Module>> m_asyncModules; ///> Modules that run on completely other threads without restraint - std::vector<std::shared_ptr<Module>> m_adaptiveModules; ///> Modules that update adpatively to keep up with real time + std::vector<std::shared_ptr<Module>> m_syncModules; ///> Modules called once per update + std::vector<std::shared_ptr<Module>> m_asyncModules; ///> Modules that run on completely other threads without restraint + std::vector<std::shared_ptr<Module>> m_adaptiveModules; ///> Modules that update adpatively to keep up with real time std::unordered_map<Module*, bool> m_running;