From 18bc3d3f5a62dc48101a587ed175ed2041d1bdf7 Mon Sep 17 00:00:00 2001 From: ZeyxRew <117768526+ZeyxRew@users.noreply.github.com> Date: Sat, 20 Jan 2024 16:01:15 +0100 Subject: [PATCH] pausing --- lib/xlpmg/communicator_api.h | 7 +++++++ src/Server.cpp | 10 ++++++++++ src/Simulator.cpp | 9 +++++++++ src/Simulator.h | 13 +++++++++++++ src/ui/GUI.cpp | 19 ++++++++++++++++--- src/ui/GUI.h | 4 ++++ 6 files changed, 59 insertions(+), 3 deletions(-) diff --git a/lib/xlpmg/communicator_api.h b/lib/xlpmg/communicator_api.h index 35319416..eae9ef66 100644 --- a/lib/xlpmg/communicator_api.h +++ b/lib/xlpmg/communicator_api.h @@ -165,6 +165,13 @@ namespace xlpmg //! Deletes stations. inline const Message DELETE_STATIONS = {MessageType::SERVER_RESPONSE, "delete_stations"}; + + //! pause simulation + inline const Message PAUSE_SIMULATION = {MessageType::SERVER_CALL, "pause_simulation"}; + + //!continue simulation + inline const Message CONTINUE_SIMULATION = {MessageType::SERVER_CALL, "continue_simulation"}; + } #endif \ No newline at end of file diff --git a/src/Server.cpp b/src/Server.cpp index 251d8239..9ed97c78 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -193,6 +193,16 @@ int main(int i_argc, char *i_argv[]) } } } + else if(l_key == xlpmg::PAUSE_SIMULATION.key) + { + std::cout << "Pause simulation" << std::endl; + simulator->setPausingStatus(true); + } + else if(l_key == xlpmg::CONTINUE_SIMULATION.key) + { + std::cout << "Continue simulation" << std::endl; + simulator->setPausingStatus(false); + } } else if (l_type == xlpmg::FUNCTION_CALL) diff --git a/src/Simulator.cpp b/src/Simulator.cpp index 3f183587..4a88033d 100644 --- a/src/Simulator.cpp +++ b/src/Simulator.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #ifndef NOFILESYSTEM #include @@ -796,6 +797,12 @@ void tsunami_lab::Simulator::runCalculation() l_lastWrite = std::chrono::system_clock::now(); } } + + //pausing the simulation + // while(m_pausStatus){ + // std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + // } + // BREAKPOINT if (m_shouldExit) return; @@ -808,6 +815,8 @@ void tsunami_lab::Simulator::runCalculation() m_waveProp->timeStep(m_scalingX, m_scalingY); m_timeStep++; m_simTime += m_dt; + + } } diff --git a/src/Simulator.h b/src/Simulator.h index 1087adb2..f9a8a55a 100644 --- a/src/Simulator.h +++ b/src/Simulator.h @@ -65,6 +65,8 @@ class tsunami_lab::Simulator std::atomic m_shouldExit = false; std::atomic m_isPreparing = false; std::atomic m_isCalculating = false; + std::atomic m_pausStatus = false; + // input parameters std::string m_bathymetryFilePath = ""; @@ -440,6 +442,17 @@ class tsunami_lab::Simulator { m_shouldExit = i_shouldExit; }; + + /** + * Sets the exit flag to provided a safe-exit mechanism. + * + * @param i_shouldExit whether to exit or not. + * @return void + */ + void setPausingStatus(bool i_PausStatus) + { + m_pausStatus = i_PausStatus; + }; }; #endif diff --git a/src/ui/GUI.cpp b/src/ui/GUI.cpp index 2490c5a7..561f5f2f 100644 --- a/src/ui/GUI.cpp +++ b/src/ui/GUI.cpp @@ -386,9 +386,6 @@ int tsunami_lab::ui::GUI::launch() { if (ImGui::Button("Run simulation")) { - // if(m_bathymetryFilePath != ""){ - // m_communicator.sendToServer(messageToJsonString(xlpmg::PREPARE_BATHYMETRY_DATA)); - // } xlpmg::Message startSimMsg = xlpmg::START_SIMULATION; m_communicator.sendToServer(messageToJsonString(startSimMsg)); } @@ -409,6 +406,22 @@ int tsunami_lab::ui::GUI::launch() m_communicator.sendToServer(messageToJsonString(xlpmg::KILL_SIMULATION)); } + if(ImGui::Button("Pause Simulation")) + { + if(!m_isPausing) + { + m_communicator.sendToServer(messageToJsonString(xlpmg::PAUSE_SIMULATION)); + } + } + ImGui::SameLine(); + if(ImGui::Button("Continue Simulation")) + { + if(m_isPausing) + { + m_communicator.sendToServer(messageToJsonString(xlpmg::CONTINUE_SIMULATION)); + } + } + if (ImGui::Button("Get height data")) { if (m_communicator.sendToServer(messageToJsonString(xlpmg::GET_HEIGHT_DATA)) == 0) diff --git a/src/ui/GUI.h b/src/ui/GUI.h index 9820bb0e..1669c720 100644 --- a/src/ui/GUI.h +++ b/src/ui/GUI.h @@ -108,6 +108,10 @@ class tsunami_lab::ui::GUI // client log bool m_clientLogAutoScroll = true; + //simulation status + bool m_isPausing = false; + + /** * Executes a shell command. *