Revision: 8425
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8425&view=rev
Author:   natepak
Date:     2009-11-20 04:49:22 +0000 (Fri, 20 Nov 2009)

Log Message:
-----------
Fixes to the time slider

Modified Paths:
--------------
    code/gazebo/trunk/server/Simulator.cc
    code/gazebo/trunk/server/Simulator.hh
    code/gazebo/trunk/server/World.cc
    code/gazebo/trunk/server/World.hh

Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc       2009-11-20 02:52:19 UTC (rev 
8424)
+++ code/gazebo/trunk/server/Simulator.cc       2009-11-20 04:49:22 UTC (rev 
8425)
@@ -421,6 +421,11 @@
 void Simulator::SetPaused(bool p)
 {
   boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
+  if (this->pause == p)
+    return;
+
+  this->pauseSignal(p);
   this->pause = p;
 }
 
@@ -647,7 +652,7 @@
     if (!this->IsPaused() || this->GetStepInc())
     {
       this->simTime += step;
-      this->SetPaused(false);
+      //this->SetPaused(false);
 
       if (this->GetStepInc())
           userStepped = true;

Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh       2009-11-20 02:52:19 UTC (rev 
8424)
+++ code/gazebo/trunk/server/Simulator.hh       2009-11-20 04:49:22 UTC (rev 
8425)
@@ -28,6 +28,7 @@
 
 #include <string>
 #include <boost/thread.hpp>
+#include <boost/signal.hpp>
 
 #include "SingletonT.hh"
 
@@ -175,6 +176,13 @@
     /// \brief Get the state of the simulation
     public: State GetState() const;
 
+    /// \brief Connect a boost::slot the the pause signal
+    public: template<typename T>
+            void ConnectPauseSignal( T subscriber )
+            {
+              pauseSignal.connect(subscriber);
+            }
+ 
     /// \brief Function to run gui. Used by guiThread
     private: void PhysicsLoop();
 
@@ -240,11 +248,15 @@
 
     private: State state;
 
+    private: boost::signal<void (bool)> pauseSignal;
+
     //Singleton implementation
     private: friend class DestroyerT<Simulator>;
     private: friend class SingletonT<Simulator>;
+
 };
 
+
 /// \}
 }
 

Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc   2009-11-20 02:52:19 UTC (rev 8424)
+++ code/gazebo/trunk/server/World.cc   2009-11-20 04:49:22 UTC (rev 8425)
@@ -76,7 +76,7 @@
 
   this->worldStates.resize(10000);
   this->worldStatesInsertIter = this->worldStates.begin();
-  this->worldStatesEndIter = this->worldStates.end()-1;
+  this->worldStatesEndIter = this->worldStates.begin();
   this->worldStatesCurrentIter = this->worldStatesInsertIter;
 }
 
@@ -145,6 +145,9 @@
 // Load the world
 void World::Load(XMLConfigNode *rootNode, unsigned int serverId)
 {
+  Simulator::Instance()->ConnectPauseSignal( 
+      boost::bind(&World::PauseSlot, this, _1) );
+  
   // Create the server object (needs to be done before models initialize)
   this->server = new Server();
 
@@ -286,8 +289,6 @@
   {
     if (Simulator::Instance()->GetSimTime() >= this->simPauseTime)
     {
-      //printf("SimTime[%f] PauseTime[%f]\n", 
Simulator::Instance()->GetSimTime(), this->simPauseTime);
-
       this->simPauseTime = 0;
       Simulator::Instance()->SetPaused(true);
 
@@ -1356,8 +1357,11 @@
   {
     this->worldStatesEndIter++;
     if (this->worldStatesEndIter == this->worldStates.end())
+    {
       this->worldStatesEndIter = this->worldStates.begin();
+    }
   }
+
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -1391,19 +1395,29 @@
 
   this->worldStatesCurrentIter = this->worldStatesInsertIter;
 
-  int i = (int)(this->worldStates.size() * (1.0-pos));
+  int diff = this->worldStatesInsertIter - this->worldStatesEndIter;
 
+  int i = (int)(diff * (1.0-pos));
+
   if (this->worldStatesCurrentIter == this->worldStates.begin())
     this->worldStatesCurrentIter = this->worldStates.end()--;
 
-  for (;i>=0;i--, this->worldStatesCurrentIter--)
+  for (;i>=0; i--, this->worldStatesCurrentIter--)
   {
+    if (this->worldStatesCurrentIter == this->worldStatesEndIter)
+      break;
+
     if (this->worldStatesCurrentIter == this->worldStates.begin())
       this->worldStatesCurrentIter = this->worldStates.end()-1;
-
-    if (this->worldStatesCurrentIter == this->worldStatesEndIter)
-      break;
   }
 
   this->SetState(this->worldStatesCurrentIter);
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// Pause callback
+void World::PauseSlot(bool p)
+{
+  if (!p)
+    this->worldStatesInsertIter = this->worldStatesCurrentIter;
+}

Modified: code/gazebo/trunk/server/World.hh
===================================================================
--- code/gazebo/trunk/server/World.hh   2009-11-20 02:52:19 UTC (rev 8424)
+++ code/gazebo/trunk/server/World.hh   2009-11-20 04:49:22 UTC (rev 8425)
@@ -200,6 +200,9 @@
   /// \breif Set the state of the world to the pos pointed to by the iterator
   private: void SetState(std::deque<WorldState>::iterator iter);
 
+  /// \brief Pause callback
+  private: void PauseSlot(bool p);
+
   /// Set to true to show bounding boxes
   private: bool showBoundingBoxes;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to