Skip to content

Commit

Permalink
pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeyxRew committed Jan 20, 2024
1 parent 029d7be commit 18bc3d3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/xlpmg/communicator_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <limits>
#include <chrono>
#include <future>
#include <thread>

#ifndef NOFILESYSTEM
#include <filesystem>
Expand Down Expand Up @@ -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;
Expand All @@ -808,6 +815,8 @@ void tsunami_lab::Simulator::runCalculation()
m_waveProp->timeStep(m_scalingX, m_scalingY);
m_timeStep++;
m_simTime += m_dt;


}
}

Expand Down
13 changes: 13 additions & 0 deletions src/Simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class tsunami_lab::Simulator
std::atomic<bool> m_shouldExit = false;
std::atomic<bool> m_isPreparing = false;
std::atomic<bool> m_isCalculating = false;
std::atomic<bool> m_pausStatus = false;


// input parameters
std::string m_bathymetryFilePath = "";
Expand Down Expand Up @@ -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
19 changes: 16 additions & 3 deletions src/ui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/ui/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 18bc3d3

Please sign in to comment.