Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network: working on helper funciton

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