[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" |
---|
[8147] | 14 | #include "playable.h" |
---|
[7954] | 15 | #include "message_manager.h" |
---|
[6067] | 16 | |
---|
[6111] | 17 | |
---|
[6341] | 18 | class TiXmlElement; |
---|
[6695] | 19 | class PNode; |
---|
[6111] | 20 | |
---|
[6695] | 21 | typedef enum NetworkGameManagerProtocol { |
---|
| 22 | NET_CREATE_ENTITY = 0, |
---|
| 23 | NET_REMOVE_ENTITY, |
---|
| 24 | NET_CREATE_ENTITY_LIST, |
---|
| 25 | NET_REMOVE_ENTITY_LIST, |
---|
| 26 | NET_REQUEST_CREATE, |
---|
| 27 | NET_REQUEST_REMOVE, |
---|
| 28 | NET_YOU_ARE_ENTITY, |
---|
| 29 | NET_REQUEST_ENTITY_LIST, |
---|
| 30 | NET_REQUEST_PNODE_PATH, |
---|
| 31 | NET_SEND_PNODE_PATH, |
---|
| 32 | |
---|
| 33 | NET_NUMBER |
---|
[6341] | 34 | }; |
---|
[6111] | 35 | |
---|
[6341] | 36 | struct clientBuffer |
---|
| 37 | { |
---|
| 38 | int length; |
---|
| 39 | int maxLength; |
---|
| 40 | byte * buffer; |
---|
| 41 | }; |
---|
[6111] | 42 | |
---|
[6067] | 43 | /*! |
---|
| 44 | * a class that can create and remove entities |
---|
| 45 | */ |
---|
[6116] | 46 | class NetworkGameManager: public Synchronizeable |
---|
[6067] | 47 | { |
---|
| 48 | public: |
---|
[6981] | 49 | virtual ~NetworkGameManager(); |
---|
[8068] | 50 | |
---|
[6341] | 51 | static NetworkGameManager* NetworkGameManager::getInstance() |
---|
| 52 | { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; } |
---|
| 53 | |
---|
[6111] | 54 | |
---|
[8068] | 55 | bool signalNewPlayer( int userId ); |
---|
| 56 | bool signalLeftPlayer( int userID ); |
---|
| 57 | |
---|
| 58 | void removeSynchronizeable( int uniqueId ); |
---|
[8147] | 59 | |
---|
| 60 | void prefereTeam( int teamId ); |
---|
[6111] | 61 | |
---|
[8068] | 62 | inline void setGameState( int gameState ){ this->gameState = gameState; } |
---|
| 63 | inline int getGameState(){ return this->gameState; } |
---|
[8147] | 64 | |
---|
| 65 | void tick( float ds ); |
---|
[8623] | 66 | |
---|
[8708] | 67 | void sendChatMessage( const std::string & message, int messageType ); |
---|
[6111] | 68 | |
---|
[6067] | 69 | private: |
---|
[6341] | 70 | NetworkGameManager(); |
---|
[7954] | 71 | |
---|
[8068] | 72 | static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); |
---|
[8147] | 73 | static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); |
---|
[8623] | 74 | static bool chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); |
---|
[8147] | 75 | |
---|
| 76 | void setPreferedTeam( int userId, int teamId ); |
---|
[6111] | 77 | |
---|
[6341] | 78 | static NetworkGameManager* singletonRef; |
---|
[8068] | 79 | |
---|
| 80 | int gameState; |
---|
[8147] | 81 | |
---|
| 82 | std::list<Playable*> playablesToDelete; |
---|
[6067] | 83 | }; |
---|
| 84 | |
---|
| 85 | #endif /*_ENTITY_MANGER*/ |
---|