00001
00012 #ifndef SYSTEM_H
00013 #define SYSTEM_H
00014
00015 #include <vector>
00016 #include <boost/shared_ptr.hpp>
00017
00018 #include "TemplateTable.h"
00019 #include "EntityInstance.h"
00020 #include "util/Timer.h"
00021 #include "MessagePool.h"
00022
00023 namespace green
00024 {
00025 class System
00026 {
00027 friend class GRunApplication;
00028 protected:
00029 class _entry {
00030 public:
00031 _entry(Key type, Key target, ArgListPtr args) :
00032 mType(type), mTarget(target), mArgs(args) {}
00033
00034 _entry(Key type, ArgListPtr args) :
00035 mType(type), mTarget(0), mArgs(args) {}
00036
00037 Key mType;
00038 Key mTarget;
00039 ArgListPtr mArgs;
00040 };
00041 std::vector<_entry> mEntities;
00042 std::vector<_entry> mMessages;
00043 MessagePoolPtr mMsgPool;
00044
00045 Timer mTimer;
00046
00047 public:
00048 inline
00049 void SpawnEntity(Key type, ArgListPtr args) {
00050 CHECK_SHARED(args);
00051 mEntities.push_back(_entry(type, args));
00052 }
00053
00054 inline
00055 void SendMessage(Key type, Key target, ArgListPtr args) {
00056 CHECK_SHARED(args);
00057 mMessages.push_back(_entry(type, target, args));
00058 }
00059
00060 inline
00061 void Clear() {
00062 mMessages.clear();
00063 mEntities.clear();
00064 }
00065
00066 inline
00067 void SetTimer(Timer timer) {
00068 mTimer = timer;
00069 }
00070
00071 inline
00072 Timer GetTimer() const {
00073 return mTimer;
00074 }
00075
00076 inline
00077 void SetMessagePool(MessagePoolPtr pool) {
00078 CHECK_SHARED(pool);
00079 mMsgPool = pool;
00080 }
00081
00082 inline
00083 MessagePoolPtr GetMessagePool() const {
00084 return mMsgPool;
00085 }
00086
00087 };
00088 typedef boost::shared_ptr<System> SystemPtr;
00089 }
00090 #endif