Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

converter: added functions for strings
network_protocol: length and id are now int
network_game_manager: fixed some more bugs :D
skybox: is loaded on client corectly now :)

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