Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/network_game_manager.h @ 6451

Last change on this file since 6451 was 6424, checked in by bensch, 19 years ago

orxonox/trunk: merged the branche network back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r 6351:HEAD
no conflicts

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