Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

reimplemented NetworkStream

File size: 3.3 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_SERVER = 1,
44  PERMISSION_OWNER  = 2,
45  PERMISSION_ALL    = 4
46};
47
48typedef std::vector<SynchronizeableVar*> SyncVarList;
49
50class NetworkStream;
51
52class Synchronizeable : virtual public BaseObject
53{
54
55  public:
56    Synchronizeable();
57    virtual ~Synchronizeable();
58
59    void setIsServer( bool isServer );
60    bool isServer();
61
62    virtual void varChangeHandler( std::list<int> & id );
63
64    int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH );
65    bool setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId );
66
67    void registerVar( SynchronizeableVar * var );
68    int registerVarId( SynchronizeableVar * var );
69
70    inline void setUniqueID( int id ){ uniqueID = id; }
71    inline int  getUniqueID() const { return uniqueID; }
72    inline int getHostID() { return this->hostID; }
73
74    inline int getOwner(){ return owner; }
75    inline void setOwner(int owner){ this->owner = owner; }
76
77    /** @returns true if this Synchronizeable wants to be synchronized over network */
78    inline bool beSynchronized() { return this->bSynchronize; }
79    /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */
80    inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; }
81
82    inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; }
83    inline NetworkStream* getNetworkStream() { return this->networkStream; }
84
85
86  protected:
87    NetworkStream*    networkStream;  //!< reference network stream we are connected to
88    int               state;
89
90  private:
91    int               uniqueID;       //!< unique id assigned to synchronizeable
92    int               mLeafClassId;   //!< store leafClassId to send via states
93    int               owner;          //!< hostId of owner ( 0 if none / server )
94    int               hostID;         //!< my own host id
95    bool              bSynchronize;   //!< do we need beeing synchronized?
96
97    SyncVarList       syncVarList;    //!< list containing variables to synchronize
98
99    UserStateHistory  sentStates;     //!< store already sent states to create diffs from, offset corresponds to the user id
100    UserStateHistory  recvStates;     //!< store recieved states to apply diffs, offset corresponds to the user id
101
102};
103#endif /* _SYNCHRONIZEABLE_H */
Note: See TracBrowser for help on using the repository browser.