Revision: 6395
http://playerstage.svn.sourceforge.net/playerstage/?rev=6395&view=rev
Author: natepak
Date: 2008-05-02 10:11:43 -0700 (Fri, 02 May 2008)
Log Message:
-----------
Throttled the rendering and physics update
Modified Paths:
--------------
code/gazebo/trunk/server/Simulator.cc
code/gazebo/trunk/server/Simulator.hh
code/gazebo/trunk/server/gui/Gui.cc
code/gazebo/trunk/server/gui/StatusBar.cc
Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc 2008-05-02 14:32:17 UTC (rev
6394)
+++ code/gazebo/trunk/server/Simulator.cc 2008-05-02 17:11:43 UTC (rev
6395)
@@ -189,41 +189,59 @@
gazebo::World::Instance()->Fini();
}
-////////////////////////////////////////////////////////////////////////////////
-/// Update the simulation
-void Simulator::Update()
-{
- double step= World::Instance()->GetPhysicsEngine()->GetStepTime();
- this->simTime += step;
-
- // Update the physics engine
- if (!this->GetUserPause() && !this->GetUserStep() ||
- (this->GetUserStep() && this->GetUserStepInc()))
- {
- this->iterations++;
- this->pause=false;
- this->SetUserStepInc(!this->GetUserStepInc());
- }
- else
- {
- this->pauseTime += step;
- this->pause=true;
- }
-
-}
-
////////////////////////////////////////////////////////////////////////////////
/// Main simulation loop, when this loop ends the simulation finish
void Simulator::MainLoop()
{
+ double step= World::Instance()->GetPhysicsEngine()->GetStepTime();
+ double currTime;
+ double elapsedTime;
+
while (!this->userQuit)
{
- this->Update(); //global simulation
- World::Instance()->Update(); //physics
+ currTime = this->GetRealTime();
- gazebo::OgreAdaptor::Instance()->Render(); //rendering
- this->gui->Update(); //GUI
+ if ((currTime - this->prevPhysicsTime) >= step)
+ {
+ this->simTime += step;
+
+ // Update the physics engine
+ if (!this->GetUserPause() && !this->GetUserStep() ||
+ (this->GetUserStep() && this->GetUserStepInc()))
+ {
+ this->iterations++;
+ this->pause=false;
+ this->SetUserStepInc(!this->GetUserStepInc());
+ }
+ else
+ {
+ this->pauseTime += step;
+ this->pause=true;
+ }
+
+ World::Instance()->Update(); //physics
+
+ this->prevPhysicsTime = this->GetRealTime();
+ }
+
+ // Update the rendering
+ if (currTime - this->prevRenderTime > 0.02)
+ {
+ gazebo::OgreAdaptor::Instance()->Render();
+ this->prevRenderTime = this->GetRealTime();
+ }
+
+ // Update the gui
+ this->gui->Update();
+
+ elapsedTime = (this->GetRealTime()-currTime)*2.0;
+
+ // Wait if we're going too fast
+ if ( elapsedTime < 0.02 )
+ {
+ usleep( (0.02 - elapsedTime) * 1e6 );
+ }
}
}
Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh 2008-05-02 14:32:17 UTC (rev
6394)
+++ code/gazebo/trunk/server/Simulator.hh 2008-05-02 17:11:43 UTC (rev
6395)
@@ -71,9 +71,6 @@
/// \brief Finalize the simulation
public: void Fini( );
- /// \brief Update the simulation
- public: void Update();
-
/// \brief Main simulation loop, when this loop ends the simulation finish
public: void MainLoop();
@@ -157,6 +154,7 @@
/// Current simulation time
private: double simTime, pauseTime, startTime;
+ private: double prevPhysicsTime, prevRenderTime;
// UserIteractions
/// \brief Set to true to pause the simulation
Modified: code/gazebo/trunk/server/gui/Gui.cc
===================================================================
--- code/gazebo/trunk/server/gui/Gui.cc 2008-05-02 14:32:17 UTC (rev 6394)
+++ code/gazebo/trunk/server/gui/Gui.cc 2008-05-02 17:11:43 UTC (rev 6395)
@@ -106,8 +106,8 @@
this->toolbar->Update();
this->statusbar->Update();
this->glWindow->Update();
- //Fl::check();
- Fl::wait(0.03);
+ Fl::check();
+ //Fl::wait(0.03);
}
////////////////////////////////////////////////////////////////////////////////
Modified: code/gazebo/trunk/server/gui/StatusBar.cc
===================================================================
--- code/gazebo/trunk/server/gui/StatusBar.cc 2008-05-02 14:32:17 UTC (rev
6394)
+++ code/gazebo/trunk/server/gui/StatusBar.cc 2008-05-02 17:11:43 UTC (rev
6395)
@@ -81,7 +81,10 @@
this->iterations->value(Simulator::Instance()->GetIterations());
this->fps->value(avgFPS);
- this->realTime->value(Simulator::Instance()->GetRealTime());
+ if (Simulator::Instance()->GetRealTime() - this->realTime->value() > 0.1)
+ {
+ this->realTime->value(Simulator::Instance()->GetRealTime());
+ }
this->simTime->value(Simulator::Instance()->GetSimTime());
this->pauseTime->value(Simulator::Instance()->GetPauseTime());
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit