From: Markus R. <rol...@us...> - 2006-01-02 20:37:53
|
Update of /cvsroot/simspark/simspark/spark/oxygen/simulationserver In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28198 Modified Files: simulationserver.h simulationserver.cpp Log Message: - added method WantsToQuit() to query the quit flag - splitted the RunLoop into several methods that allow it to be driven from outside: Init, Cycle, Done Index: simulationserver.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/simulationserver/simulationserver.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** simulationserver.cpp 5 Dec 2005 21:21:18 -0000 1.1 --- simulationserver.cpp 2 Jan 2006 20:37:41 -0000 1.2 *************** *** 106,109 **** --- 106,114 ---- } + bool SimulationServer::WantsToQuit() + { + return mExit; + } + int SimulationServer::GetArgC() { *************** *** 153,160 **** bool SimulationServer::InitControlNode(const std::string& className, const std::string& name) { ! shared_ptr<SimControlNode> importer = shared_dynamic_cast<SimControlNode>(GetCore()->New(className)); ! if (importer.get() == 0) { GetLog()->Error() << "(SimulationServer) ERROR: " --- 158,165 ---- bool SimulationServer::InitControlNode(const std::string& className, const std::string& name) { ! shared_ptr<SimControlNode> control = shared_dynamic_cast<SimControlNode>(GetCore()->New(className)); ! if (control.get() == 0) { GetLog()->Error() << "(SimulationServer) ERROR: " *************** *** 163,168 **** } ! importer->SetName(name); ! AddChildReference(importer); GetLog()->Normal() --- 168,173 ---- } ! control->SetName(name); ! AddChildReference(control); GetLog()->Normal() *************** *** 191,194 **** --- 196,200 ---- void SimulationServer::AdvanceTime(float deltaTime) { + mSumDeltaTime += deltaTime; } *************** *** 275,281 **** } ! void SimulationServer::Run(int argc, char** argv) { ! GetLog()->Normal() << "(SimulationServer) entering runloop\n"; // cache argc and argv, to make it accessible for registerd --- 281,287 ---- } ! void SimulationServer::Init(int argc, char** argv) { ! GetLog()->Normal() << "(SimulationServer) init\n"; // cache argc and argv, to make it accessible for registerd *************** *** 285,306 **** ControlEvent(CE_Init); while (! mExit) { ! ++mCycle; ! ControlEvent(CE_StartCycle); ! ControlEvent(CE_SenseAgent); ! ControlEvent(CE_ActAgent); ! if (mAutoTime) ! { ! AdvanceTime(mSimStep); ! } ! Step(); ! ControlEvent(CE_EndCycle); } ControlEvent(CE_Done); --- 291,328 ---- ControlEvent(CE_Init); + } + + void SimulationServer::Run(int argc, char** argv) + { + Init(argc, argv); + GetLog()->Normal() << "(SimulationServer) entering runloop\n"; while (! mExit) { ! Cycle(); ! } ! Done(); ! } ! void SimulationServer::Cycle() ! { ! ++mCycle; ! ControlEvent(CE_StartCycle); ! ControlEvent(CE_SenseAgent); ! ControlEvent(CE_ActAgent); ! ! if (mAutoTime) ! { ! AdvanceTime(mSimStep); } + Step(); + + ControlEvent(CE_EndCycle); + } + void SimulationServer::Done() + { ControlEvent(CE_Done); Index: simulationserver.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/simulationserver/simulationserver.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** simulationserver.h 5 Dec 2005 21:21:18 -0000 1.1 --- simulationserver.h 2 Jan 2006 20:37:41 -0000 1.2 *************** *** 61,64 **** --- 61,67 ---- static void Quit(); + /** returns true if Quit() was called previously */ + static bool WantsToQuit(); + /** returns the current simulation time */ virtual float GetTime(); *************** *** 104,108 **** char** GetArgV(); ! /** the runloop of the simulation */ virtual void Run(int argc = 0, char** argv = 0); --- 107,122 ---- char** GetArgV(); ! /** 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(); ! ! /** shutdown server and all registered control nodes */ ! virtual void Done(); ! ! /** the runloop of the simulation, i.e. init(), cycle() until ! exit, done() ! */ virtual void Run(int argc = 0, char** argv = 0); |