| 1 | /*! |
|---|
| 2 | * @file entity_manager.h |
|---|
| 3 | * Manages creation and destruction of entities |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | #ifndef _NETWORK_GAME_MANGER |
|---|
| 7 | #define _NETWORK_GAME_MANAGER |
|---|
| 8 | |
|---|
| 9 | /* include this file, it contains some default definitions */ |
|---|
| 10 | #include "netdefs.h" |
|---|
| 11 | |
|---|
| 12 | /* include base_object.h since all classes are derived from this one */ |
|---|
| 13 | #include "synchronizeable.h" |
|---|
| 14 | #include "message_manager.h" |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | class TiXmlElement; |
|---|
| 18 | class PNode; |
|---|
| 19 | |
|---|
| 20 | typedef enum NetworkGameManagerProtocol { |
|---|
| 21 | NET_CREATE_ENTITY = 0, |
|---|
| 22 | NET_REMOVE_ENTITY, |
|---|
| 23 | NET_CREATE_ENTITY_LIST, |
|---|
| 24 | NET_REMOVE_ENTITY_LIST, |
|---|
| 25 | NET_REQUEST_CREATE, |
|---|
| 26 | NET_REQUEST_REMOVE, |
|---|
| 27 | NET_YOU_ARE_ENTITY, |
|---|
| 28 | NET_REQUEST_ENTITY_LIST, |
|---|
| 29 | NET_REQUEST_PNODE_PATH, |
|---|
| 30 | NET_SEND_PNODE_PATH, |
|---|
| 31 | |
|---|
| 32 | NET_NUMBER |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | struct clientBuffer |
|---|
| 36 | { |
|---|
| 37 | int length; |
|---|
| 38 | int maxLength; |
|---|
| 39 | byte * buffer; |
|---|
| 40 | }; |
|---|
| 41 | |
|---|
| 42 | /*! |
|---|
| 43 | * a class that can create and remove entities |
|---|
| 44 | */ |
|---|
| 45 | class NetworkGameManager: public Synchronizeable |
|---|
| 46 | { |
|---|
| 47 | public: |
|---|
| 48 | virtual ~NetworkGameManager(); |
|---|
| 49 | |
|---|
| 50 | static NetworkGameManager* NetworkGameManager::getInstance() |
|---|
| 51 | { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; } |
|---|
| 52 | |
|---|
| 53 | #if 0 |
|---|
| 54 | virtual int writeBytes(const byte* data, int length, int sender); |
|---|
| 55 | virtual int readBytes(byte* data, int maxLength, int * reciever); |
|---|
| 56 | virtual void writeDebug() const; |
|---|
| 57 | virtual void readDebug() const; |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | int createEntity( ClassID classID, int owner = 0 ); |
|---|
| 61 | BaseObject* createEntity(const TiXmlElement* element); |
|---|
| 62 | void removeEntity( int uniqueID ); |
|---|
| 63 | void sendYouAre( int uniqueID, int userID ); |
|---|
| 64 | |
|---|
| 65 | #if 0 |
|---|
| 66 | void sendEntityList(int userID); |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | bool signalNewPlayer(int userId); |
|---|
| 70 | bool signalLeftPlayer(int userID); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | private: |
|---|
| 74 | NetworkGameManager(); |
|---|
| 75 | |
|---|
| 76 | static bool youAreHandler(MessageId messageId, byte * data, int dataLength, void * someData, int userId ); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | /* some network signal handlers */ |
|---|
| 80 | bool handleRequestCreate( int& i, const byte* data, int length, int sender ); |
|---|
| 81 | bool handleRequestRemove( int& i, const byte* data, int length, int sender ); |
|---|
| 82 | bool handleCreateEntity( int& i, const byte* data, int length, int sender ); |
|---|
| 83 | bool handleRemoveEntity( int& i, const byte* data, int length, int sender ); |
|---|
| 84 | bool handleCreateEntityList( int& i, const byte* data, int length, int sender ); |
|---|
| 85 | bool handleRemoveEntityList( int& i, const byte* data, int length, int sender ); |
|---|
| 86 | bool handleYouAreEntity( int& i, const byte* data, int length, int sender ); |
|---|
| 87 | bool handleRequestPNodePath(int& i, const byte* data, int length, int sender); |
|---|
| 88 | bool handleSendPNodePath(int& i, const byte* data, int length, int sender); |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | /* some network handlers helper functions */ |
|---|
| 92 | // void requestCreateEntity(ClassID classID); |
|---|
| 93 | int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0); |
|---|
| 94 | BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner); |
|---|
| 95 | |
|---|
| 96 | // void requestRemoveEntity(int uniqueID); |
|---|
| 97 | void executeRemoveEntity(int uniqueID); |
|---|
| 98 | void doRemoveEntity(int uniqueID); |
|---|
| 99 | |
|---|
| 100 | void doYouAre( int uniqueID ); |
|---|
| 101 | |
|---|
| 102 | // void requestPNodePath(const PNode* node1, const PNode* node2); |
|---|
| 103 | void executeRequestPNodePath(const PNode* node2, const PNode* node2); |
|---|
| 104 | void doRequestPNodePath(const PNode* node1, const PNode* node2); |
|---|
| 105 | |
|---|
| 106 | bool canCreateEntity(ClassID classID); |
|---|
| 107 | #if 0 |
|---|
| 108 | void resizeBufferVector(int n); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | bool writeToClientBuffer( clientBuffer &cb, byte*data, int length ); |
|---|
| 112 | bool writeToClientBuffer( clientBuffer &cb, byte b ); |
|---|
| 113 | bool writeToClientBuffer( clientBuffer &cb, int i ); |
|---|
| 114 | bool readFromClientBuffer( clientBuffer &cb, byte*data, int length ); |
|---|
| 115 | #endif |
|---|
| 116 | |
|---|
| 117 | private: |
|---|
| 118 | #if 0 |
|---|
| 119 | std::vector<clientBuffer> outBuffer; |
|---|
| 120 | //clientBuffer allOutBuffer; |
|---|
| 121 | #endif |
|---|
| 122 | static NetworkGameManager* singletonRef; |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | #endif /*_ENTITY_MANGER*/ |
|---|