Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_game_manager.h @ 6231

Last change on this file since 6231 was 6231, checked in by rennerc, 18 years ago

network_game_manager now works with new converter

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