Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/synchronizeable.h @ 7559

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

network: added some comments and found some small bugs

File size: 3.2 KB
Line 
1/*!
2 * @file synchronizeable.h
3    \brief interface for all classes that have to be synchronized
4 */
5
6#ifndef _SYNCHRONIZEABLE_H
7#define _SYNCHRONIZEABLE_H
8
9#include "base_object.h"
10#include "netdefs.h"
11#include "converter.h"
12#include "vector.h"
13#include "quaternion.h"
14#include "synchronizeable_var/synchronizeable_var.h"
15#include "synchronizeable_var/synchronizeable_vector.h"
16#include "synchronizeable_var/synchronizeable_quaternion.h"
17#include "synchronizeable_var/synchronizeable_string.h"
18#include "synchronizeable_var/synchronizeable_int.h"
19#include "synchronizeable_var/synchronizeable_float.h"
20#include "synchronizeable_var/synchronizeable_bool.h"
21#include "synchronizeable_var/synchronizeable_uint.h"
22
23
24#include <vector>
25#include <list>
26
27//State constants: They have to be of the form 2^n
28#define STATE_SERVER 1
29
30struct StateHistoryEntry
31{
32  int             stateId;
33  byte *          data;
34  int             dataLength;
35  std::list<int>  sizeList;
36};
37
38typedef std::list<StateHistoryEntry*> StateHistory;
39
40typedef std::vector<StateHistory> UserStateHistory;
41
42enum {
43  PERMISSION_OWNER = 1,
44  PERMISSION_ALL   = 2
45};
46
47typedef std::vector<SynchronizeableVar*> SyncVarList;
48
49class NetworkStream;
50
51class Synchronizeable : virtual public BaseObject
52{
53
54  public:
55    Synchronizeable();
56    virtual ~Synchronizeable();
57
58    void setIsServer( bool isServer );
59    bool isServer();
60
61    virtual void varChangeHandler( std::list<int> & id );
62
63    int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH );
64    bool setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
65
66    void registerVar( SynchronizeableVar * var );
67    int registerVarId( SynchronizeableVar * var );
68
69    inline void setUniqueID( int id ){ uniqueID = id; }
70    inline int  getUniqueID() const { return uniqueID; }
71    inline int getHostID() { return this->hostID; }
72
73    inline int getOwner(){ return owner; }
74    inline void setOwner(int owner){ this->owner = owner; }
75
76    /** @returns true if this Synchronizeable wants to be synchronized over network */
77    inline bool beSynchronized() { return this->bSynchronize; }
78    /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */
79    inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; }
80
81    inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; }
82    inline NetworkStream* getNetworkStream() { return this->networkStream; }
83
84
85  protected:
86    NetworkStream*    networkStream;  //!< reference network stream we are connected to
87    int               state;
88
89  private:
90    int               uniqueID;       //!< unique id assigned to synchronizeable
91    int               owner;          //!< hostId of owner ( 0 if none / server )
92    int               hostID;         //!< my own host id
93    bool              bSynchronize;   //!< do we need beeing synchronized?
94
95    SyncVarList       syncVarList;    //!< list containing variables to synchronize
96
97    UserStateHistory  sentStates;     //!< store already sent states to create diffs from, offset corresponds to the user id
98    UserStateHistory  recvStates;     //!< store recieved states to apply diffs, offset corresponds to the user id
99
100};
101#endif /* _SYNCHRONIZEABLE_H */
Note: See TracBrowser for help on using the repository browser.