00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef OXYGEN_SPADESSERVER_H
00023 #define OXYGEN_SPADESSERVER_H
00024
00025 #include <spades/enginemain.hpp>
00026 #include <spades/SimEngine.hpp>
00027 #include <zeitgeist/class.h>
00028 #include <zeitgeist/node.h>
00029 #include "paramreader.h"
00030 #include <queue>
00031
00032 namespace oxygen
00033 {
00034 class GameControlServer;
00035 class MonitorServer;
00036 class SceneServer;
00037
00040 class SpadesServer :
00041 public zeitgeist::Node,
00042 public spades::WorldModel
00043 {
00044 public:
00045 SpadesServer();
00046 ~SpadesServer();
00047
00048
00049
00050
00051
00054 virtual bool ConstructInternal();
00055
00057 virtual void OnLink();
00058
00060 virtual void OnUnlink();
00061
00063 boost::shared_ptr<GameControlServer> GetGameControlServer() const;
00064
00068 float GetTimePerStep() const;
00069
00073 bool GetRunIntegratedCommserver() const;
00074
00080 int GetCommServersWanted() const;
00081
00085 int GetMonitorInterval() const;
00086
00088 bool GetSendAgentThinkTimes() const;
00089
00094 void QueueAgents(const std::string& agentType="default", int num=1);
00095
00097 void Unpause();
00098
00100 virtual void UpdateCached();
00101
00102
00103
00104
00108 spades::EngineParam* parseParameters(int argc, const char* const *argv);
00109
00117 bool initialize(spades::SimEngine* pSE);
00118
00120 spades::SimEngine* GetSimEngine();
00121
00123 bool finalize();
00124
00136 spades::SimTime
00137 simToTime(spades::SimTime time_curr, spades::SimTime time_desired);
00138
00147 spades::DataArray getMonitorHeaderInfo();
00148
00154 spades::DataArray getMonitorInfo(spades::SimTime time);
00155
00163 void parseMonitorMessage(const char* data, unsigned datalen);
00164
00170 spades::SimTime getMinActionLatency() const;
00171
00176 spades::SimTime getMinSenseLatency() const;
00177
00185 spades::ActEvent*
00186 parseAct(spades::SimTime t, spades::AgentID a, const char* data, unsigned datalen) const;
00187
00192 void pauseModeCallback();
00193
00198 bool agentConnect(spades::AgentID agent, spades::AgentTypeDB::AgentTypeConstIterator at);
00199
00204 bool agentDisappear(spades::AgentID agent, spades::AgentLostReason reason);
00205
00211 void notifyCommserverConnect(spades::ServerID s);
00212
00218 void notifyCommserverDisconnect(spades::ServerID s);
00219
00220 protected:
00221 struct AgentItem
00222 {
00223 AgentItem(const std::string& agentType = "", int num = 0) :
00224 mAgentType(agentType), mNumber(num) {}
00225 std::string mAgentType;
00226 int mNumber;
00227 };
00228 typedef std::list<AgentItem> TAgentQueue;
00229
00234 void StartAgents(const AgentItem& ai);
00235
00236 private:
00238 spades::SimEngine* mSimEngine;
00239
00241 boost::shared_ptr<ParamReader> mParamReader;
00242
00244 bool mSimulationModeChanged;
00245
00247 spades::SimulationMode mNewSimulationMode;
00248
00250 TAgentQueue mAgentQueue;
00251
00255 float mOffsetCreateSense;
00256
00260 float mNextInitialCreateSense;
00261
00263 boost::shared_ptr<MonitorServer> mMonitorServer;
00264
00266 boost::shared_ptr<GameControlServer> mGameControlServer;
00267
00269 boost::shared_ptr<SceneServer> mSceneServer;
00270
00272 float mTimePerStep;
00273 };
00274
00275 DECLARE_CLASS(SpadesServer);
00276
00277 }
00278
00279 #endif // OXYGEN_SPADESSERVER_H