/*! * @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" #include "message_manager.h" class TiXmlElement; class PNode; typedef enum NetworkGameManagerProtocol { NET_CREATE_ENTITY = 0, NET_REMOVE_ENTITY, NET_CREATE_ENTITY_LIST, NET_REMOVE_ENTITY_LIST, NET_REQUEST_CREATE, NET_REQUEST_REMOVE, NET_YOU_ARE_ENTITY, NET_REQUEST_ENTITY_LIST, NET_REQUEST_PNODE_PATH, NET_SEND_PNODE_PATH, NET_NUMBER }; struct clientBuffer { int length; int maxLength; byte * buffer; }; /*! * a class that can create and remove entities */ class NetworkGameManager: public Synchronizeable { public: virtual ~NetworkGameManager(); static NetworkGameManager* NetworkGameManager::getInstance() { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; } #if 0 virtual int 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; #endif int createEntity( ClassID classID, int owner = 0 ); BaseObject* createEntity(const TiXmlElement* element); void removeEntity( int uniqueID ); void sendYouAre( int uniqueID, int userID ); #if 0 void sendEntityList(int userID); #endif bool signalNewPlayer(int userId); bool signalLeftPlayer(int userID); private: NetworkGameManager(); static bool youAreHandler(MessageId messageId, byte * data, int dataLength, void * someData, int userId ); /* some network signal handlers */ bool handleRequestCreate( int& i, const byte* data, int length, int sender ); bool handleRequestRemove( int& i, const byte* data, int length, int sender ); bool handleCreateEntity( int& i, const byte* data, int length, int sender ); bool handleRemoveEntity( int& i, const byte* data, int length, int sender ); bool handleCreateEntityList( int& i, const byte* data, int length, int sender ); bool handleRemoveEntityList( int& i, const byte* data, int length, int sender ); bool handleYouAreEntity( int& i, const byte* data, int length, int sender ); bool handleRequestPNodePath(int& i, const byte* data, int length, int sender); bool handleSendPNodePath(int& i, const byte* data, int length, int sender); /* some network handlers helper functions */ // void requestCreateEntity(ClassID classID); int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0); BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner); // void requestRemoveEntity(int uniqueID); void executeRemoveEntity(int uniqueID); void doRemoveEntity(int uniqueID); void doYouAre( int uniqueID ); // void requestPNodePath(const PNode* node1, const PNode* node2); void executeRequestPNodePath(const PNode* node2, const PNode* node2); void doRequestPNodePath(const PNode* node1, const PNode* node2); bool canCreateEntity(ClassID classID); #if 0 void resizeBufferVector(int n); bool writeToClientBuffer( clientBuffer &cb, byte*data, int length ); bool writeToClientBuffer( clientBuffer &cb, byte b ); bool writeToClientBuffer( clientBuffer &cb, int i ); bool readFromClientBuffer( clientBuffer &cb, byte*data, int length ); #endif private: #if 0 std::vector outBuffer; //clientBuffer allOutBuffer; #endif static NetworkGameManager* singletonRef; }; #endif /*_ENTITY_MANGER*/