/*! * @file entity_manager.h * Manages creation and destruction of entities */ #ifndef _NETWORK_GAME_MANGER #define _NETWORK_GAME_MANAGER /* include this file, it contains some default definitions */ #include "netdefs.h" /* include base_object.h since all classes are derived from this one */ #include "synchronizeable.h" /** * protocol definition * * CREATE_ENTITY: CLASS_ID, UNIQUE_ID, OWNER * REMOVE_ENTITY: UNIQUE_ID * * CREATE_ENTITY_LIST: NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER] * REMOVE_ENTITY_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] * * REQUEST_CREATE: CLASS_ID * REQUEST_REMOVE: UNIQUE_ID * * REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER] * REQUEST_CREATE_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] * * REQUEST_SYNC: UNIQUE_ID * REQUEST_SYNC_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] * * */ typedef enum NetworkGameManagerProtocol{ CREATE_ENTITY = 0, REMOVE_ENTITY, REQUEST_CREATE, REQUEST_SYNC }; struct clientBuffer { int length; int maxLength; byte * buffer; }; /*! * a class that can create and remove entities */ class NetworkGameManager: public Synchronizeable { public: NetworkGameManager(); ~NetworkGameManager(); virtual void writeBytes(const byte* data, int length, int sender); virtual int readBytes(byte* data, int maxLength, int * reciever); virtual void writeDebug() const; virtual void readDebug() const; void createEntity(int classID); void removeEntity(int uniqueID); void sync(int uniqueID); void sendEntityList(int userID); private: void requestCreateEntity(int classID); void executeCreateEntity(int classID); void requestRemoveEntity(int uniqueID); void executeRemoveEntity(int uniqueID); void doCreateEntity(ClassID classID, int uniqueID, int owner); void doRemoveEntity(int uniqueID); void doRequestSync(int uniqueID, int userID); bool canCreateEntity(int classID); void resizeBufferVector(int n); private: std::vector inBuffer; std::vector outBuffer; }; #endif /*_ENTITY_MANGER*/