Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6666 was 6666, checked in by patrick, 18 years ago

network: branche compiles again

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