Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

new network system implemented. yet with a lot of empty function bodys

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