From: <he...@us...> - 2011-03-24 16:21:43
|
Revision: 256 http://simspark.svn.sourceforge.net/simspark/?rev=256&view=rev Author: hedayat Date: 2011-03-24 16:21:36 +0000 (Thu, 24 Mar 2011) Log Message: ----------- * Prepared for a new release (updating version numbers) * Added a new timer architecture based on a TimerSystem concept. It is now handled completely separate from SimControlNodes. * Added TimerSystemBoost which is based on Boost timing facilities. Modified Paths: -------------- trunk/spark/CMakeLists.txt trunk/spark/ChangeLog trunk/spark/lib/oxygen/CMakeLists.txt trunk/spark/lib/oxygen/oxygen.cpp trunk/spark/lib/oxygen/oxygen.h trunk/spark/lib/oxygen/simulationserver/simulationserver.cpp trunk/spark/lib/oxygen/simulationserver/simulationserver.h trunk/spark/lib/oxygen/simulationserver/simulationserver_c.cpp trunk/spark/plugin/CMakeLists.txt trunk/spark/spark/spark.rb Added Paths: ----------- trunk/spark/lib/oxygen/simulationserver/timersystem.h trunk/spark/lib/oxygen/simulationserver/timersystem_c.cpp trunk/spark/plugin/timersystemboost/ trunk/spark/plugin/timersystemboost/CMakeLists.txt trunk/spark/plugin/timersystemboost/export.cpp trunk/spark/plugin/timersystemboost/timersystemboost.cpp trunk/spark/plugin/timersystemboost/timersystemboost.h trunk/spark/plugin/timersystemboost/timersystemboost_c.cpp Modified: trunk/spark/CMakeLists.txt =================================================================== --- trunk/spark/CMakeLists.txt 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/CMakeLists.txt 2011-03-24 16:21:36 UTC (rev 256) @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.6) project(simspark CXX C) -set(PACKAGE_VERSION "0.2.1") +set(PACKAGE_VERSION "0.2.2") ########## check for headerfiles/libraries ########## include(CheckIncludeFile) @@ -143,11 +143,11 @@ set(SALT_SO_VERSION 0) set(SALT_VERSION ${SALT_SO_VERSION}.3.2) set(ZEITGEIST_SO_VERSION 3) -set(ZEITGEIST_VERSION ${ZEITGEIST_SO_VERSION}.1.1) -set(OXYGEN_SO_VERSION 4) +set(ZEITGEIST_VERSION ${ZEITGEIST_SO_VERSION}.1.2) +set(OXYGEN_SO_VERSION 5) set(OXYGEN_VERSION ${OXYGEN_SO_VERSION}.0.0) -set(KEROSIN_SO_VERSION 1) -set(KEROSIN_VERSION ${KEROSIN_SO_VERSION}.1.1) +set(KEROSIN_SO_VERSION 2) +set(KEROSIN_VERSION ${KEROSIN_SO_VERSION}.0.0) set(SPARK_SO_VERSION 0) set(SPARK_VERSION ${SPARK_SO_VERSION}.0.1) set(RCSSNET_SO_VERSION 0) Modified: trunk/spark/ChangeLog =================================================================== --- trunk/spark/ChangeLog 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/ChangeLog 2011-03-24 16:21:36 UTC (rev 256) @@ -1,3 +1,42 @@ +2011-03-24 Hedayat Vatankhah <hed...@gm...> + + * plugin/timersystemboost/timersystemboost.h: + * plugin/timersystemboost/timersystemboost.cpp: + * plugin/timersystemboost/timersystemboost_c.cpp: + * plugin/timersystemboost/export.cpp: + * plugin/timersystemboost/CMakeLists.txt: + - Added TimerSystemBoost which uses Boost facilities for timing + + * plugin/CMakeLists.txt: + - Added timersystemboost to the list of plugins + - Reordering the list of plugins to make it sorted again + + * CMakeLists.txt: + - Prepare for 0.2.2 release: changed the version number and update library + versions + + * spark/spark.rb: + - Disable old style timer and add sparkSetupTimer() function for + setting up a timer system + + * lib/oxygen/simulationserver/simulationserver.h: + * lib/oxygen/simulationserver/simulationserver.cpp: + * lib/oxygen/simulationserver/simulationserver_c.cpp: + - Use TimerSystem for timing + - Added InitTimerSystem() to setup a timer system for simulation server + - Fixed a few spelling errors + - Added SyncTime() method which is responsible for updating mSumDeltaTime + using a TimerSystem or simulator's internal clock. + - Using Step() in multi-threaded mode in addition to the single threaded + mode. Looks like that there is no need to differentiate any more. + + * lib/oxygen/oxygen.cpp: + * lib/oxygen/oxygen.h: + * lib/oxygen/CMakeLists.txt: + * lib/oxygen/simulationserver/timersystem.h: + * lib/oxygen/simulationserver/timersystem_c.cpp: + - Added a new TimerSystem mechanism to control simulator timing + 2011-03-23 Hedayat Vatankhah <hed...@gm...> * RELEASE: Modified: trunk/spark/lib/oxygen/CMakeLists.txt =================================================================== --- trunk/spark/lib/oxygen/CMakeLists.txt 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/lib/oxygen/CMakeLists.txt 2011-03-24 16:21:36 UTC (rev 256) @@ -110,6 +110,7 @@ simulationserver/netmessage.h simulationserver/netbuffer.h simulationserver/traincontrol.h + simulationserver/timersystem.h geometryserver/geometryserver.h geometryserver/meshexporter.h geometryserver/meshimporter.h @@ -260,6 +261,7 @@ simulationserver/netbuffer.cpp simulationserver/traincontrol.cpp simulationserver/traincontrol_c.cpp + simulationserver/timersystem_c.cpp geometryserver/geometryserver.h geometryserver/geometryserver.cpp geometryserver/geometryserver_c.cpp Modified: trunk/spark/lib/oxygen/oxygen.cpp =================================================================== --- trunk/spark/lib/oxygen/oxygen.cpp 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/lib/oxygen/oxygen.cpp 2011-03-24 16:21:36 UTC (rev 256) @@ -44,6 +44,7 @@ zg.GetCore()->RegisterClassObject(new CLASS(MonitorControl), "oxygen/"); zg.GetCore()->RegisterClassObject(new CLASS(MonitorLogger), "oxygen/"); zg.GetCore()->RegisterClassObject(new CLASS(TrainControl), "oxygen/"); + zg.GetCore()->RegisterClassObject(new CLASS(TimerSystem), "oxygen/"); // geometry zg.GetCore()->RegisterClassObject(new CLASS(GeometryServer), "oxygen/"); Modified: trunk/spark/lib/oxygen/oxygen.h =================================================================== --- trunk/spark/lib/oxygen/oxygen.h 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/lib/oxygen/oxygen.h 2011-03-24 16:21:36 UTC (rev 256) @@ -90,6 +90,7 @@ #include <oxygen/simulationserver/monitorcontrol.h> #include <oxygen/simulationserver/monitorlogger.h> #include <oxygen/simulationserver/traincontrol.h> +#include <oxygen/simulationserver/timersystem.h> #include <oxygen/geometryserver/geometryserver.h> #include <oxygen/geometryserver/meshexporter.h> Modified: trunk/spark/lib/oxygen/simulationserver/simulationserver.cpp =================================================================== --- trunk/spark/lib/oxygen/simulationserver/simulationserver.cpp 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/lib/oxygen/simulationserver/simulationserver.cpp 2011-03-24 16:21:36 UTC (rev 256) @@ -21,6 +21,7 @@ */ #include "simulationserver.h" #include "simcontrolnode.h" +#include "timersystem.h" #include <zeitgeist/logserver/logserver.h> #include <signal.h> #include <algorithm> @@ -183,6 +184,33 @@ return true; } +/** creates and registers a new TimerSystem to the SimulationServer */ +bool SimulationServer::InitTimerSystem(const std::string& className) +{ + if (mTimerSystem) + { + GetLog()->Error() << "(SimulationServer) ERROR: " + << "Another timer system already in use!\n"; + return false; + } + + mTimerSystem = shared_dynamic_cast<TimerSystem>(GetCore()->New(className)); + SetAutoTimeMode(false); + + if (!mTimerSystem) + { + GetLog()->Error() << "(SimulationServer) ERROR: " + << "Unable to create '" << className << "'\n"; + return false; + } + + GetLog()->Normal() + << "(SimulationServer) TimerSystem '" + << className << "' registered\n"; + + return true; +} + boost::shared_ptr<SimControlNode> SimulationServer::GetControlNode(const string& controlName) { @@ -237,7 +265,6 @@ mSimTime += mSumDeltaTime; mSumDeltaTime = 0; } -// usleep(10000); } void SimulationServer::ControlEvent(EControlEvent event) @@ -305,6 +332,11 @@ mArgV = argv; ControlEvent(CE_Init); + + if (mTimerSystem) + { + mTimerSystem->Initialize(); + } } void SimulationServer::Run(int argc, char** argv) @@ -312,25 +344,26 @@ Init(argc, argv); GetLog()->Normal() << "(SimulationServer) entering runloop\n"; - boost::shared_ptr<SimControlNode> inputCtr = GetControlNode("InputControl"); - - if ( mMultiThreads ) + if ( !mAutoTime && !mTimerSystem ) { - GetLog()->Normal()<< "(SimulationServer) running in multi-threads\n"; - RunMultiThreaded(inputCtr); + GetLog()->Error()<< "(SimulationServer) ERROR: can not get" + " any TimerSystem objects.\n"; } else { - GetLog()->Normal()<< "(SimulationServer) running in single thread\n"; - if ( !mAutoTime && inputCtr.get() == 0 ) + if ( mMultiThreads ) { - GetLog()->Error()<< "(SimulationServer) ERROR: can not get InputControl\n"; + GetLog()->Normal()<< "(SimulationServer) running in " + "multi-threaded mode\n"; + RunMultiThreaded(); } else { + GetLog()->Normal()<< "(SimulationServer) running in single " + "thread mode\n"; while (! mExit) { - Cycle(inputCtr); + Cycle(); } } } @@ -338,7 +371,7 @@ Done(); } -void SimulationServer::Cycle(boost::shared_ptr<SimControlNode> &inputCtr) +void SimulationServer::Cycle() { ++mCycle; @@ -347,26 +380,18 @@ ControlEvent(CE_ActAgent); Step(); - if (mAutoTime) - { - AdvanceTime(mSimStep); - } - else - { - if (inputCtr.get() != 0) - { - while (int(mSumDeltaTime*100) < int(mSimStep*100)) - { - inputCtr->StartCycle();// advance the time - } - } - } + SyncTime(); ControlEvent(CE_EndCycle); } void SimulationServer::Done() { + if (mTimerSystem) + { + mTimerSystem->Finalize(); + } + ControlEvent(CE_Done); mArgC = 0; @@ -392,17 +417,8 @@ return mSceneServer.get(); } -void SimulationServer::RunMultiThreaded(boost::shared_ptr<SimControlNode> &inputCtr) +void SimulationServer::RunMultiThreaded() { - if (mSimStep == 0) - { - GetLog()->Error() << "(SimulationServer) ERROR: multi-threaded " - << "mode supports descreet simulations only.\n"; - return; - } - - boost::thread_group ctrThrdGroup; - // count valid SimControlNodes. int count = 1; for ( TLeafList::iterator iter=begin(); iter != end(); ++iter ) @@ -413,6 +429,7 @@ mThreadBarrier = new barrier(count); // create new threads for each SimControlNode + boost::thread_group ctrThrdGroup; for ( TLeafList::iterator iter=begin(); iter != end(); ++iter ) { boost::shared_ptr<SimControlNode> ctrNode = shared_dynamic_cast<SimControlNode>(*iter); @@ -433,51 +450,19 @@ mThreadBarrier->wait(); if (mExit) mExitThreads = true; - - // Wait for SimControlNodes' acts at the begining of a cycle + + // Wait for SimControlNodes' acts at the beginning of a cycle mThreadBarrier->wait(); - finalDelta = initDelta = mSumDeltaTime; + Step(); + SyncTime(); - mSceneServer->PrePhysicsUpdate(mSimStep); - mSceneServer->PhysicsUpdate(mSimStep); - - if (mAutoTime) - { - AdvanceTime(mSimStep); - } - - else - { - if (inputCtr.get() != 0) - { - while (int(mSumDeltaTime*100) < int(mSimStep*100)) - { - inputCtr->StartCycle();// advance the time - } - } - } - - UpdateDeltaTimeAfterStep(finalDelta); - - float finalStep = mSimStep; - while (int(finalDelta*100) >= int(mSimStep*100)) - { - mSceneServer->PhysicsUpdate(mSimStep); - UpdateDeltaTimeAfterStep(finalDelta); - finalStep += mSimStep; - } - mSceneServer->PostPhysicsUpdate(); - mGameControlServer->Update(finalStep); - mSimTime += finalStep; - if (renderControl && renderControl->GetTime() - mSimTime < 0.005f ) renderControl->EndCycle(); // End Cycle - mThreadBarrier->wait(); - mSumDeltaTime -= initDelta - finalDelta; + mThreadBarrier->wait(); } // wait for threads @@ -493,16 +478,15 @@ return; } - bool isInputControl = (controlNode->GetName() == "InputControl"); bool isRenderControl = (controlNode->GetName() == "RenderControl"); bool newCycle = false; while (!mExitThreads) { mThreadBarrier->wait(); - + newCycle = false; - if ( controlNode->GetTime() - mSimTime <= 0.005f && !isInputControl) + if ( controlNode->GetTime() - mSimTime <= 0.005f) { newCycle = true; controlNode->StartCycle(); @@ -552,3 +536,16 @@ else deltaTime -= mSimStep; } + +inline void SimulationServer::SyncTime() +{ + if (mAutoTime) + { + AdvanceTime(mSimStep); + } + else + { + mTimerSystem->WaitFromLastQueryUntil(mSimStep - mSumDeltaTime); + AdvanceTime(mTimerSystem->GetTimeSinceLastQuery()); + } +} Modified: trunk/spark/lib/oxygen/simulationserver/simulationserver.h =================================================================== --- trunk/spark/lib/oxygen/simulationserver/simulationserver.h 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/lib/oxygen/simulationserver/simulationserver.h 2011-03-24 16:21:36 UTC (rev 256) @@ -32,6 +32,7 @@ namespace oxygen { class SimControlNode; +class TimerSystem; class OXYGEN_API SimulationServer : public zeitgeist::Node { @@ -90,6 +91,10 @@ SimulationServer */ bool InitControlNode(const std::string& className, const std::string& name); + /** creates a new TimerSystem of type \param className to be used as + * the simulator's internal timer */ + bool InitTimerSystem(const std::string& className); + /** sets the auto time mode of the SimulationServer. if set to true the SimulationServer automatically advances the simulation mSimStep time every cycle, this is the default @@ -114,8 +119,9 @@ /** init the runloop and all registered control nodes */ virtual void Init(int argc = 0, char** argv = 0); - /** go through on cycle of the runloop, i.e. sense, act, step */ - virtual void Cycle(boost::shared_ptr<SimControlNode> &inputCtr); + /** go through on cycle of the runloop (single threaded mode), i.e. sense, + * act, step */ + virtual void Cycle(); /** shutdown server and all registered control nodes */ virtual void Done(); @@ -131,7 +137,7 @@ /** returns the cached GameControlServer reference */ boost::shared_ptr<GameControlServer> GetGameControlServer(); - /** returns thr cached SceneServer reference */ + /** returns the cached SceneServer reference */ boost::shared_ptr<SceneServer> GetSceneServer(); /** returns the current simulation cycle */ @@ -167,15 +173,20 @@ static void CatchSignal(int sig_num); /** the multi-threaded runloop of the simulation */ - void RunMultiThreaded(boost::shared_ptr<SimControlNode> &inputCtr); + void RunMultiThreaded(); /** the thread function which controls a single SimControlNode in * multi-threaded mode. */ void SimControlThread(boost::shared_ptr<SimControlNode> controlNode); - /** updates mSumDeltaTime after a step in descreet simulations */ + /** updates mSumDeltaTime after a step in discreet simulations */ void UpdateDeltaTimeAfterStep(float &deltaTime); + /** updates the accumulated time since last simulation step using the + * specified timing method: it might use simulator's own clock (if mAutoTime + * is true) or a TimerSystem provided using InitTimerSystem() */ + void SyncTime(); + protected: /** the argc parameter passed to Run() */ int mArgC; @@ -230,6 +241,9 @@ /** barrier object for synchronizing threads in multi-threaded mode */ boost::barrier *mThreadBarrier; + + /** the timer system to control the simulation */ + boost::shared_ptr<TimerSystem> mTimerSystem; }; DECLARE_CLASS(SimulationServer); Modified: trunk/spark/lib/oxygen/simulationserver/simulationserver_c.cpp =================================================================== --- trunk/spark/lib/oxygen/simulationserver/simulationserver_c.cpp 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/lib/oxygen/simulationserver/simulationserver_c.cpp 2011-03-24 16:21:36 UTC (rev 256) @@ -45,10 +45,24 @@ return false; } - return obj->InitControlNode(inClassName,inName); + return obj->InitControlNode(inClassName, inName); } +FUNCTION(SimulationServer,initTimerSystem) +{ + string inClassName; + if ( + (in.GetSize() != 1) || + (! in.GetValue(in[0],inClassName)) + ) + { + return false; + } + + return obj->InitTimerSystem(inClassName); +} + FUNCTION(SimulationServer, getTime) { return obj->GetTime(); @@ -156,6 +170,7 @@ DEFINE_BASECLASS(zeitgeist/Node); DEFINE_FUNCTION(quit); DEFINE_FUNCTION(initControlNode); + DEFINE_FUNCTION(initTimerSystem); DEFINE_FUNCTION(getTime); DEFINE_FUNCTION(resetTime); DEFINE_FUNCTION(setSimStep); Added: trunk/spark/lib/oxygen/simulationserver/timersystem.h =================================================================== --- trunk/spark/lib/oxygen/simulationserver/timersystem.h (rev 0) +++ trunk/spark/lib/oxygen/simulationserver/timersystem.h 2011-03-24 16:21:36 UTC (rev 256) @@ -0,0 +1,59 @@ +/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- + + This file is part of rcssserver3D + Thu Mar 24 2011 + Copyright (C) 2003-1011 RoboCup Soccer Server 3D Maintenance Group + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef OXYGEN_TIMERSYSTEM_H +#define OXYGEN_TIMERSYSTEM_H + +#include <zeitgeist/class.h> +#include <zeitgeist/leaf.h> + +namespace oxygen +{ +/** \class TimerSystem defines the interface for an external timer to control + * the simulation. + */ +class TimerSystem: public zeitgeist::Leaf +{ +public: + /** initialize the timer system. It is called once at the beginning of a + * simulation. + */ + virtual void Initialize() = 0; + + /** \return the elapsed time since the last call of this function or since + * the initialization for the first call. + */ + virtual float GetTimeSinceLastQuery() = 0; + + /** waits until \param deadline seconds is passed since the last call to + * GetTimeSinceLastQuery(). If that is already passed, it'll return + * immediately. + */ + virtual void WaitFromLastQueryUntil(float deadline) = 0; + + /** this is called at the end of the simulation */ + virtual void Finalize() {} +}; + +DECLARE_ABSTRACTCLASS(TimerSystem); + +} // namespace oxygen + +#endif // OXYGEN_TIMERSYSTEM_H Added: trunk/spark/lib/oxygen/simulationserver/timersystem_c.cpp =================================================================== --- trunk/spark/lib/oxygen/simulationserver/timersystem_c.cpp (rev 0) +++ trunk/spark/lib/oxygen/simulationserver/timersystem_c.cpp 2011-03-24 16:21:36 UTC (rev 256) @@ -0,0 +1,28 @@ +/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- + + This file is part of rcssserver3D + Thu Mar 24 2011 + Copyright (C) 2003-1011 RoboCup Soccer Server 3D Maintenance Group + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "timersystem.h" + +using namespace oxygen; + +void CLASS(TimerSystem)::DefineClass() +{ + DEFINE_BASECLASS(zeitgeist/Leaf); +} Modified: trunk/spark/plugin/CMakeLists.txt =================================================================== --- trunk/spark/plugin/CMakeLists.txt 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/plugin/CMakeLists.txt 2011-03-24 16:21:36 UTC (rev 256) @@ -11,25 +11,26 @@ add_subdirectory(accelerometer) add_subdirectory(agentsynceffector) +add_subdirectory(collisionperceptor) add_subdirectory(filesystemstd) add_subdirectory(filesystemzip) add_subdirectory(forceeffector) add_subdirectory(gyrorateperceptor) add_subdirectory(inputsdl) +add_subdirectory(inputwx) add_subdirectory(objimporter) add_subdirectory(odeimps) add_subdirectory(openglsyssdl) +add_subdirectory(openglsyswx) add_subdirectory(perfectvisionperceptor) -add_subdirectory(collisionperceptor) -add_subdirectory(sexpparser) add_subdirectory(rosimporter) add_subdirectory(rubysceneimporter) +add_subdirectory(sexpparser) add_subdirectory(sparkmonitor) add_subdirectory(sparkagent) add_subdirectory(sceneeffector) add_subdirectory(soundsystemfmod) -add_subdirectory(inputwx) -add_subdirectory(openglsyswx) +add_subdirectory(timersystemboost) if (APPLE) if (DEVEL) add_subdirectory(imageperceptor) Added: trunk/spark/plugin/timersystemboost/CMakeLists.txt =================================================================== --- trunk/spark/plugin/timersystemboost/CMakeLists.txt (rev 0) +++ trunk/spark/plugin/timersystemboost/CMakeLists.txt 2011-03-24 16:21:36 UTC (rev 256) @@ -0,0 +1,18 @@ +########### next target ############### + +set(timersystemboost_LIB_SRCS + export.cpp + timersystemboost.cpp + timersystemboost_c.cpp + timersystemboost.h +) + +add_library(timersystemboost MODULE ${timersystemboost_LIB_SRCS}) + +target_link_libraries(timersystemboost ${spark_libs}) + +if (NOT APPLE) + set_target_properties(timersystemboost PROPERTIES VERSION 0.0.0 SOVERSION 0) +endif (NOT APPLE) + +install(TARGETS timersystemboost DESTINATION ${LIBDIR}/${CMAKE_PROJECT_NAME}) Added: trunk/spark/plugin/timersystemboost/export.cpp =================================================================== --- trunk/spark/plugin/timersystemboost/export.cpp (rev 0) +++ trunk/spark/plugin/timersystemboost/export.cpp 2011-03-24 16:21:36 UTC (rev 256) @@ -0,0 +1,27 @@ +/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- + + This file is part of rcssserver3D + Thu Mar 24 2011 + Copyright (C) 2003-1011 RoboCup Soccer Server 3D Maintenance Group + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "timersystemboost.h" +#include <zeitgeist/zeitgeist.h> + + using namespace oxygen; +ZEITGEIST_EXPORT_BEGIN() + ZEITGEIST_EXPORT(TimerSystemBoost); +ZEITGEIST_EXPORT_END() Added: trunk/spark/plugin/timersystemboost/timersystemboost.cpp =================================================================== --- trunk/spark/plugin/timersystemboost/timersystemboost.cpp (rev 0) +++ trunk/spark/plugin/timersystemboost/timersystemboost.cpp 2011-03-24 16:21:36 UTC (rev 256) @@ -0,0 +1,52 @@ +/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- + + This file is part of rcssserver3D + Thu Mar 24 2011 + Copyright (C) 2003-1011 RoboCup Soccer Server 3D Maintenance Group + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "timersystemboost.h" +#include <boost/date_time/posix_time/posix_time.hpp> +#include <zeitgeist/logserver/logserver.h> + +using namespace oxygen; + +void TimerSystemBoost::Initialize() +{ + mLastQueryTime = boost::get_system_time(); +} + +float TimerSystemBoost::GetTimeSinceLastQuery() +{ + boost::system_time currentTime = boost::get_system_time(); + boost::posix_time::time_duration timeDiff = currentTime - mLastQueryTime; + mLastQueryTime = currentTime; + return timeDiff.total_milliseconds() / 1000.0f; +} + +void TimerSystemBoost::WaitFromLastQueryUntil(float deadline) +{ + int milliseconds = round(deadline * 1000); +// GetLog()->Debug() << "(TimerSystemBoost) Waiting for " << deadline +// << " seconds or " << milliseconds << " millisecs\n"; + boost::thread::sleep(mLastQueryTime + + boost::posix_time::milliseconds(milliseconds)); +// GetLog()->Debug() << "CURRENT TIME: " << boost::get_system_time() << '\n'; +} + +//void TimerSystemBoost::Finalize() +//{ +//} Added: trunk/spark/plugin/timersystemboost/timersystemboost.h =================================================================== --- trunk/spark/plugin/timersystemboost/timersystemboost.h (rev 0) +++ trunk/spark/plugin/timersystemboost/timersystemboost.h 2011-03-24 16:21:36 UTC (rev 256) @@ -0,0 +1,62 @@ +/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- + + This file is part of rcssserver3D + Thu Mar 24 2011 + Copyright (C) 2003-1011 RoboCup Soccer Server 3D Maintenance Group + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef OXYGEN_BOOSTTIMERSYSTEM_H +#define OXYGEN_BOOSTTIMERSYSTEM_H + +#include <boost/thread/thread.hpp> +#include <oxygen/simulationserver/timersystem.h> + +namespace oxygen +{ +/** \class TimerSystemBoost is a timer system based on Boost timing facilities + */ +class TimerSystemBoost: public TimerSystem +{ +public: + /** initialize the timer system. It is called once at the beginning of a + * simulation. + */ + virtual void Initialize(); + + /** \return the elapsed time since the last call of this function or since + * the initialization for the first call. + */ + virtual float GetTimeSinceLastQuery(); + + /** waits until \param deadline seconds is passed since the last call to + * GetTimeSinceLastQuery(). If that is already passed, it'll return + * immediately. + */ + virtual void WaitFromLastQueryUntil(float deadline); + + /** this is called at the end of the simulation */ + virtual void Finalize() {} + +private: + /** the last time GetTimeSinceLastQuery is called or zero on Initialize() */ + boost::system_time mLastQueryTime; +}; + +DECLARE_CLASS(TimerSystemBoost); + +} // namespace oxygen + +#endif // OXYGEN_BOOSTTIMERSYSTEM_H Added: trunk/spark/plugin/timersystemboost/timersystemboost_c.cpp =================================================================== --- trunk/spark/plugin/timersystemboost/timersystemboost_c.cpp (rev 0) +++ trunk/spark/plugin/timersystemboost/timersystemboost_c.cpp 2011-03-24 16:21:36 UTC (rev 256) @@ -0,0 +1,28 @@ +/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- + + This file is part of rcssserver3D + Thu Mar 24 2011 + Copyright (C) 2003-1011 RoboCup Soccer Server 3D Maintenance Group + $Id$ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "timersystemboost.h" + +using namespace oxygen; + +void CLASS(TimerSystemBoost)::DefineClass() +{ + DEFINE_BASECLASS(oxygen/TimerSystem); +} Modified: trunk/spark/spark/spark.rb =================================================================== --- trunk/spark/spark/spark.rb 2011-03-23 09:57:11 UTC (rev 255) +++ trunk/spark/spark/spark.rb 2011-03-24 16:21:36 UTC (rev 256) @@ -10,7 +10,7 @@ $scenePath = '/usr/scene/' $serverPath = '/sys/server/' -# (Inputsystem) +# (Input system) # # the default InputSystem used to read keyboard, mouse and timer input @@ -19,9 +19,15 @@ # the name of the default bundle that contains the default InputSystem $defaultInputSystemBundle = 'inputsdl' -# if simulator should run in real time rather than simulation time -$useRealTime = true +# (Timer system) +# +# the default TimerSystem used to control the simulation timing +$defaultTimerSystem = 'TimerSystemBoost' + +# the name of the default bundle that contains the default TimerSystem +$defaultTimerSystemBundle = 'timersystemboost' + # (OpenGL rendering) # @@ -394,7 +400,7 @@ inputServer.init(inputSystem) # add devices - inputServer.createDevice('Timer') + #inputServer.createDevice('Timer') inputServer.createDevice('Keyboard') inputServer.createDevice('Mouse') end @@ -411,10 +417,27 @@ # set timing mode (real time vs simulation time) inputControl = get($serverPath+'simulation/InputControl') if (inputControl != nil) - inputControl.setAdvanceTime($useRealTime) + inputControl.setAdvanceTime(false) end end +def sparkSetupTimer(timerSystem = $defaultTimerSystem) + print "(spark.rb) sparkSetupTimer\n" + print "(spark.rb) using TimerSystem '" + timerSystem + "'\n" + + # setup the Boost timer system + if (timerSystem == $defaultTimerSystem) + importBundle($defaultTimerSystemBundle) + end + + # + # register timer system to the simulation server + simulationServer = sparkGetSimulationServer() + if (simulationServer != nil) + simulationServer.initTimerSystem(timerSystem) + end +end + def sparkSetupTrain() #print "(spark.rb) sparkSetupTrain\n" # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |