Revision: 7459
http://playerstage.svn.sourceforge.net/playerstage/?rev=7459&view=rev
Author: natepak
Date: 2009-03-11 00:18:06 +0000 (Wed, 11 Mar 2009)
Log Message:
-----------
Fixed dynamic deletion of models
Modified Paths:
--------------
code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc
code/branches/federation/gazebo/server/Model.cc
code/branches/federation/gazebo/server/Simulator.cc
code/branches/federation/gazebo/server/Simulator.hh
code/branches/federation/gazebo/server/World.cc
Modified: code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc
===================================================================
--- code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc
2009-03-11 00:17:08 UTC (rev 7458)
+++ code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc
2009-03-11 00:18:06 UTC (rev 7459)
@@ -52,7 +52,10 @@
GraphicsIfaceHandler::~GraphicsIfaceHandler()
{
if (this->threeDIface)
+ {
+ this->threeDIface->Close();
delete this->threeDIface;
+ }
}
////////////////////////////////////////////////////////////////////////////////
@@ -70,7 +73,7 @@
}
catch (std::string err)
{
- gzerr(0) << "Error: Unable to make graphics3d interface";
+ gzerr(0) << "Error: Unable to make graphics3d interface[" << _name <<
"]\n";
gzthrow(err);
}
Modified: code/branches/federation/gazebo/server/Model.cc
===================================================================
--- code/branches/federation/gazebo/server/Model.cc 2009-03-11 00:17:08 UTC
(rev 7458)
+++ code/branches/federation/gazebo/server/Model.cc 2009-03-11 00:18:06 UTC
(rev 7459)
@@ -409,7 +409,8 @@
else
this->visualNode->SetPose(this->GetPose());
- this->graphicsHandler->Update();
+ if (this->graphicsHandler)
+ this->graphicsHandler->Update();
return this->UpdateChild();
}
@@ -432,7 +433,10 @@
}
if (this->graphicsHandler)
+ {
delete this->graphicsHandler;
+ this->graphicsHandler = NULL;
+ }
return this->FiniChild();
}
Modified: code/branches/federation/gazebo/server/Simulator.cc
===================================================================
--- code/branches/federation/gazebo/server/Simulator.cc 2009-03-11 00:17:08 UTC
(rev 7458)
+++ code/branches/federation/gazebo/server/Simulator.cc 2009-03-11 00:18:06 UTC
(rev 7459)
@@ -27,6 +27,7 @@
#include <iostream>
#include <fstream>
#include <sys/time.h>
+#include <boost/bind.hpp>
#include "OgreVisualManager.hh"
#include "Body.hh"
@@ -294,6 +295,8 @@
this->prevPhysicsTime = this->GetRealTime();
this->prevRenderTime = this->GetRealTime();
+ //this->guiThread = new boost::thread( boost::bind(&Simulator::GuiLoop,
this));
+
while (!this->userQuit)
{
currTime = this->GetRealTime();
@@ -303,9 +306,8 @@
{
// Update the physics engine
- /*if (!this->GetUserPause() && !this->IsPaused() ||
- (this->GetUserPause() && this->GetUserStepInc()))
- */
+ //if (!this->GetUserPause() && !this->IsPaused() ||
+ // (this->GetUserPause() && this->GetUserStepInc()))
if (!this->IsPaused())
{
this->simTime += step;
@@ -331,8 +333,6 @@
//this->prevRenderTime = this->GetRealTime();
}
- OgreVisualManager::Instance()->Update();
-
// Update the gui
if (this->gui)
{
@@ -353,6 +353,7 @@
break;
}
+ //this->guiThread->join();
}
////////////////////////////////////////////////////////////////////////////////
@@ -551,3 +552,65 @@
return model;
}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Function to run gui. Used by guiThread
+void Simulator::GuiLoop()
+{
+ World *world = World::Instance();
+
+ double step = world->GetPhysicsEngine()->GetStepTime();
+ double physicsUpdateRate = world->GetPhysicsEngine()->GetUpdateRate();
+ double renderUpdateRate = OgreAdaptor::Instance()->GetUpdateRate();
+ double physicsUpdatePeriod = 1.0 / physicsUpdateRate;
+ double renderUpdatePeriod = 1.0 / renderUpdateRate;
+
+ double currTime;
+ double elapsedTime;
+
+ this->prevPhysicsTime = this->GetRealTime();
+ this->prevRenderTime = this->GetRealTime();
+
+ while (!this->userQuit)
+ {
+ currTime = this->GetRealTime();
+
+ if (physicsUpdateRate == 0 ||
+ currTime - this->prevPhysicsTime >= physicsUpdatePeriod)
+ {
+
+ // Update the physics engine
+ //if (!this->GetUserPause() && !this->IsPaused() ||
+ // (this->GetUserPause() && this->GetUserStepInc()))
+ if (!this->IsPaused())
+ {
+ this->simTime += step;
+ this->iterations++;
+ this->SetUserStepInc(!this->GetUserStepInc());
+ }
+ else
+ {
+ this->pauseTime += step;
+ // this->pause=true;
+ }
+
+ this->prevPhysicsTime = this->GetRealTime();
+
+ world->Update();
+ }
+
+ // Update the rendering
+ if (renderUpdateRate == 0 ||
+ currTime - this->prevRenderTime >= renderUpdatePeriod)
+ {
+ //this->GetRenderEngine()->Render();
+ //this->prevRenderTime = this->GetRealTime();
+ }
+
+ world->ProcessMessages();
+
+ usleep(1000);
+ }
+}
+
+
Modified: code/branches/federation/gazebo/server/Simulator.hh
===================================================================
--- code/branches/federation/gazebo/server/Simulator.hh 2009-03-11 00:17:08 UTC
(rev 7458)
+++ code/branches/federation/gazebo/server/Simulator.hh 2009-03-11 00:18:06 UTC
(rev 7459)
@@ -27,6 +27,7 @@
#define SIMULATOR_HH
#include <string>
+#include <boost/thread.hpp>
#include "SingletonT.hh"
@@ -162,6 +163,9 @@
/// \brief Get the model that currently selected
public: Model *GetSelectedModel() const;
+ /// \brief Function to run gui. Used by guiThread
+ private: void GuiLoop();
+
///pointer to the XML Data
private: XMLConfig *xmlFile;
@@ -222,6 +226,9 @@
/// The entity currently selected by the user
private: Entity *selectedEntity;
+ /// Thread in which to run the gui
+ private: boost::thread *guiThread;
+
//Singleton implementation
private: friend class DestroyerT<Simulator>;
private: friend class SingletonT<Simulator>;
Modified: code/branches/federation/gazebo/server/World.cc
===================================================================
--- code/branches/federation/gazebo/server/World.cc 2009-03-11 00:17:08 UTC
(rev 7458)
+++ code/branches/federation/gazebo/server/World.cc 2009-03-11 00:18:06 UTC
(rev 7459)
@@ -219,8 +219,6 @@
// Tell the simiface that it's okay to trigger the go ack
this->simIface->GoAckPost();
-
-
}
else
{
@@ -350,7 +348,10 @@
for (miter=this->models.begin(); miter!=this->models.end(); miter++)
{
if ((*miter)->GetName() == name)
+ {
+ (*miter)->Fini();
this->toDeleteModels.push_back(*miter);
+ }
}
}
@@ -772,12 +773,13 @@
for (miter=this->toDeleteModels.begin();
miter!=this->toDeleteModels.end(); miter++)
{
+ std::cout << "Erasing a model[" << (*miter)->GetName() << "]\n";
+// (*miter)->Fini();
this->models.erase(
std::remove(this->models.begin(), this->models.end(), *miter) );
delete *miter;
}
this->toDeleteModels.clear();
-
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit