[6067] | 1 | /*! |
---|
| 2 | * @file entity_manager.h |
---|
| 3 | * Manages creation and destruction of entities |
---|
| 4 | */ |
---|
[6111] | 5 | |
---|
[6116] | 6 | #ifndef _NETWORK_GAME_MANGER |
---|
| 7 | #define _NETWORK_GAME_MANAGER |
---|
[6067] | 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 | |
---|
[6111] | 15 | |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * protocol definition |
---|
| 19 | * |
---|
[6190] | 20 | * CREATE_ENTITY: CLASS_ID, UNIQUE_ID, OWNER |
---|
| 21 | * REMOVE_ENTITY: UNIQUE_ID |
---|
[6111] | 22 | * |
---|
[6190] | 23 | * CREATE_ENTITY_LIST: NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER] |
---|
| 24 | * REMOVE_ENTITY_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] |
---|
[6111] | 25 | * |
---|
[6190] | 26 | * REQUEST_CREATE: CLASS_ID |
---|
| 27 | * REQUEST_REMOVE: UNIQUE_ID |
---|
[6111] | 28 | * |
---|
[6214] | 29 | * //REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER] |
---|
| 30 | * //REQUEST_CREATE_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] |
---|
[6111] | 31 | * |
---|
[6190] | 32 | * REQUEST_SYNC: UNIQUE_ID |
---|
[6214] | 33 | * //REQUEST_SYNC_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] |
---|
[6111] | 34 | * |
---|
[6214] | 35 | * YOU_ARE_ENTITY: UNIQUE_ID |
---|
[6190] | 36 | * |
---|
[6111] | 37 | */ |
---|
| 38 | |
---|
[6190] | 39 | typedef enum NetworkGameManagerProtocol{ |
---|
| 40 | CREATE_ENTITY = 0, |
---|
| 41 | REMOVE_ENTITY, |
---|
[6214] | 42 | CREATE_ENTITY_LIST, |
---|
| 43 | REMOVE_ENTITY_LIST, |
---|
[6190] | 44 | REQUEST_CREATE, |
---|
[6214] | 45 | REQUEST_REMOVE, |
---|
| 46 | REQUEST_SYNC, |
---|
| 47 | YOU_ARE_ENTITY |
---|
[6190] | 48 | }; |
---|
[6111] | 49 | |
---|
[6190] | 50 | struct clientBuffer |
---|
| 51 | { |
---|
| 52 | int length; |
---|
| 53 | int maxLength; |
---|
| 54 | byte * buffer; |
---|
| 55 | }; |
---|
[6111] | 56 | |
---|
[6067] | 57 | /*! |
---|
| 58 | * a class that can create and remove entities |
---|
| 59 | */ |
---|
[6116] | 60 | class NetworkGameManager: public Synchronizeable |
---|
[6067] | 61 | { |
---|
| 62 | public: |
---|
[6116] | 63 | NetworkGameManager(); |
---|
| 64 | ~NetworkGameManager(); |
---|
[6111] | 65 | |
---|
[6190] | 66 | virtual void writeBytes(const byte* data, int length, int sender); |
---|
[6067] | 67 | virtual int readBytes(byte* data, int maxLength, int * reciever); |
---|
| 68 | virtual void writeDebug() const; |
---|
| 69 | virtual void readDebug() const; |
---|
[6111] | 70 | |
---|
[6219] | 71 | void createEntity( ClassID classID, int owner = 0 ); |
---|
| 72 | void removeEntity( int uniqueID ); |
---|
[6214] | 73 | void sendYouAre( int uniqueID, int userID ); |
---|
[6111] | 74 | |
---|
| 75 | void sync(int uniqueID); |
---|
| 76 | |
---|
[6190] | 77 | void sendEntityList(int userID); |
---|
[6111] | 78 | |
---|
[6067] | 79 | private: |
---|
[6214] | 80 | void requestCreateEntity(ClassID classID); |
---|
| 81 | void executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0); |
---|
[6111] | 82 | |
---|
[6067] | 83 | void requestRemoveEntity(int uniqueID); |
---|
| 84 | void executeRemoveEntity(int uniqueID); |
---|
[6111] | 85 | |
---|
[6190] | 86 | void doCreateEntity(ClassID classID, int uniqueID, int owner); |
---|
| 87 | void doRemoveEntity(int uniqueID); |
---|
| 88 | void doRequestSync(int uniqueID, int userID); |
---|
[6214] | 89 | void doYouAre( int uniqueID ); |
---|
[6111] | 90 | |
---|
[6214] | 91 | bool canCreateEntity(ClassID classID); |
---|
[6111] | 92 | |
---|
[6190] | 93 | void resizeBufferVector(int n); |
---|
[6111] | 94 | |
---|
[6214] | 95 | inline bool writeToClientBuffer( clientBuffer &cb, byte*data, int length ); |
---|
| 96 | inline bool readFromClientBuffer( clientBuffer &cb, byte*data, int length ); |
---|
| 97 | |
---|
[6219] | 98 | //helper functions for writeBytes |
---|
| 99 | inline bool handleRequestCreate( int& i, const byte* data, int length, int sender ); |
---|
| 100 | inline bool handleRequestRemove( int& i, const byte* data, int length, int sender ); |
---|
| 101 | inline bool handleCreateEntity( int& i, const byte* data, int length, int sender ); |
---|
| 102 | inline bool handleRemoveEntity( int& i, const byte* data, int length, int sender ); |
---|
| 103 | inline bool handleCreateEntityList( int& i, const byte* data, int length, int sender ); |
---|
| 104 | inline bool handleRemoveEntityList( int& i, const byte* data, int length, int sender ); |
---|
| 105 | inline bool handleYouAreEntity( int& i, const byte* data, int length, int sender ); |
---|
| 106 | inline bool handleRequestSync( int& i, const byte* data, int length, int sender ); |
---|
| 107 | |
---|
[6111] | 108 | private: |
---|
[6190] | 109 | std::vector<clientBuffer> outBuffer; |
---|
[6214] | 110 | clientBuffer allOutBuffer; |
---|
| 111 | |
---|
| 112 | int newUniqueID; |
---|
[6067] | 113 | }; |
---|
| 114 | |
---|
| 115 | #endif /*_ENTITY_MANGER*/ |
---|