Commit 365c3814 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

REFAC: Move the infinite loop in no-rendering mode to simulation manager class

parent 692fa47c
......@@ -26,7 +26,7 @@
using namespace imstk;
const bool runSimWithoutRendering = false;
const bool runSimWithoutRendering = true;
///
/// \brief This example demonstrates the cloth simulation
......@@ -128,15 +128,7 @@ int main()
// Start
sdk->setActiveScene(scene);
sdk->startSimulation(SimulationStatus::RUNNING);
// Perform an infinite loop if there is no rendering enabled
if (runSimWithoutRendering)
{
LOG(INFO) << "simulation is starting. PRESS any key to exit";
while (sdk->getStatus() == SimulationStatus::RUNNING && !getchar()) {}
sdk->endSimulation();
}
sdk->startSimulation(SimulationStatus::RUNNING);
return 0;
}
......@@ -34,7 +34,7 @@ using namespace imstk;
///
int main()
{
auto sdk = std::make_shared<SimulationManager>();
auto sdk = std::make_shared<SimulationManager>(1);
auto scene = sdk->createNewScene("PBDFluid");
scene->getCamera()->setPosition(0, 10.0, 15.0);
......
......@@ -399,6 +399,47 @@ SimulationManager::startSimulation(const SimulationStatus simStatus /*= Simulati
// start the viewer
this->startViewer(renderMode);
}
else
{
this->printUserControlsInfo(false);
this->infiniteLoopNoRenderingMode();
this->endSimulation();
}
}
void
SimulationManager::infiniteLoopNoRenderingMode()
{
while (this->getStatus() == SimulationStatus::RUNNING || this->getStatus() == SimulationStatus::PAUSED)
{
auto c = getchar();
if (c == 'e' || c == 'E')
{
break;
}
if (c == 'r' || c == 'R')
{
this->resetSimulation();
continue;
}
if (c == ' ')
{
if (this->getStatus() == SimulationStatus::RUNNING)
{
this->pauseSimulation();
continue;
}
if (this->getStatus() == SimulationStatus::PAUSED)
{
this->runSimulation();
continue;
}
}
}
}
void
......@@ -426,17 +467,31 @@ SimulationManager::startViewer(const Renderer::Mode renderMode /*= Renderer::Mod
}
void
SimulationManager::printUserControlsInfo()
SimulationManager::printUserControlsInfo(bool isRendering)
{
LOG(INFO) <<
"\n------------------------\n" <<
" User controls\n" <<
"------------------------\n" <<
"<space> - pause or unpause simulation\n" <<
" R/r - reset simulation\n" <<
" D/d - toggle between debug and simulation rendering modes\n" <<
" P/p - Display render frame rate on the screen\n" <<
"------------------------\n\n";
if (isRendering)
{
LOG(INFO) <<
"\n------------------------\n" <<
" User controls\n" <<
"------------------------\n" <<
"<space> - pause or unpause simulation\n" <<
" R/r - reset simulation\n" <<
" D/d - toggle between debug and simulation rendering modes\n" <<
" P/p - Display render frame rate on the screen\n" <<
"------------------------\n\n";
}
else
{
LOG(INFO) <<
"\n------------------------\n" <<
" User controls\n" <<
"------------------------\n" <<
"<space> - pause or unpause simulation\n" <<
" R/r - reset simulation\n" <<
" E/e - end simulatino\n" <<
"------------------------\n\n";
}
}
void
......
......@@ -152,7 +152,7 @@ public:
///
void startSimulation(const SimulationStatus simStatus = SimulationStatus::PAUSED,
const Renderer::Mode renderMode = Renderer::Mode::SIMULATION);
///
/// \brief Run the simulation from a paused state
///
......@@ -190,10 +190,16 @@ private:
///
/// \brief Print user keyboard controls
///
void printUserControlsInfo();
void printUserControlsInfo(bool isRendering = true);
void startModuleInNewThread(std::shared_ptr<Module> module);
///
/// \brief Keeps things in an infinite loop if rendering is disabled
/// The same keys can be used to trigger PAUSE, RUNNING, RESET of the simulation
///
void infiniteLoopNoRenderingMode();
SimulationStatus m_status = SimulationStatus::INACTIVE;
std::string m_activeSceneName = "";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment