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 | |
---|
11 | #include "synchronizeable_var/synchronizeable_var.h" |
---|
12 | #include "synchronizeable_var/synchronizeable_vector.h" |
---|
13 | #include "synchronizeable_var/synchronizeable_quaternion.h" |
---|
14 | #include "synchronizeable_var/synchronizeable_string.h" |
---|
15 | #include "synchronizeable_var/synchronizeable_int.h" |
---|
16 | #include "synchronizeable_var/synchronizeable_float.h" |
---|
17 | #include "synchronizeable_var/synchronizeable_bool.h" |
---|
18 | #include "synchronizeable_var/synchronizeable_uint.h" |
---|
19 | #include "synchronizeable_var/synchronizeable_ip.h" |
---|
20 | |
---|
21 | #include <vector> |
---|
22 | #include <list> |
---|
23 | |
---|
24 | |
---|
25 | struct StateHistoryEntry |
---|
26 | { |
---|
27 | int stateId; |
---|
28 | byte * data; |
---|
29 | int dataLength; |
---|
30 | std::list<int> sizeList; |
---|
31 | }; |
---|
32 | |
---|
33 | typedef std::list<StateHistoryEntry*> StateHistory; |
---|
34 | |
---|
35 | typedef std::vector<StateHistory> UserStateHistory; |
---|
36 | |
---|
37 | typedef std::vector<SynchronizeableVar*> SyncVarList; |
---|
38 | |
---|
39 | class NetworkStream; |
---|
40 | |
---|
41 | class Synchronizeable : virtual public BaseObject |
---|
42 | { |
---|
43 | |
---|
44 | public: |
---|
45 | Synchronizeable(); |
---|
46 | virtual ~Synchronizeable(); |
---|
47 | |
---|
48 | virtual void varChangeHandler( std::list<int> & id ); |
---|
49 | |
---|
50 | virtual int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH ); |
---|
51 | virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId ); |
---|
52 | virtual void cleanUpUser( int userId ); |
---|
53 | virtual void handleSentState( int userId, int stateId, int fromStateId ); |
---|
54 | virtual void handleRecvState( int userId, int stateId, int fromStateId ); |
---|
55 | |
---|
56 | void registerVar( SynchronizeableVar * var ); |
---|
57 | int registerVarId( SynchronizeableVar * var ); |
---|
58 | |
---|
59 | inline void setUniqueID( int id ){ uniqueID = id; } |
---|
60 | inline int getUniqueID() const { return uniqueID; } |
---|
61 | |
---|
62 | inline int getOwner(){ return owner; } |
---|
63 | inline void setOwner(int owner){ this->owner = owner; } |
---|
64 | |
---|
65 | /** @returns true if this Synchronizeable wants to be synchronized over network */ |
---|
66 | inline bool beSynchronized() { return this->bSynchronize; } |
---|
67 | /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */ |
---|
68 | inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; } |
---|
69 | |
---|
70 | inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; } |
---|
71 | inline NetworkStream* getNetworkStream() { return this->networkStream; } |
---|
72 | |
---|
73 | |
---|
74 | protected: |
---|
75 | NetworkStream* networkStream; //!< reference network stream we are connected to |
---|
76 | |
---|
77 | |
---|
78 | private: |
---|
79 | int uniqueID; //!< unique id assigned to synchronizeable |
---|
80 | int mLeafClassId; //!< store leafClassId to send via states |
---|
81 | int owner; //!< hostId of owner ( 0 if none / server ) |
---|
82 | bool bSynchronize; //!< do we need beeing synchronized? |
---|
83 | |
---|
84 | SyncVarList syncVarList; //!< list containing variables to synchronize |
---|
85 | |
---|
86 | UserStateHistory sentStates; //!< store already sent states to create diffs from, offset corresponds to the user id |
---|
87 | UserStateHistory recvStates; //!< store recieved states to apply diffs, offset corresponds to the user id |
---|
88 | |
---|
89 | }; |
---|
90 | #endif /* _SYNCHRONIZEABLE_H */ |
---|