[5523] | 1 | /*! |
---|
[7954] | 2 | * @file synchronizeable.h |
---|
[5550] | 3 | \brief interface for all classes that have to be synchronized |
---|
[5547] | 4 | */ |
---|
[5523] | 5 | |
---|
[5547] | 6 | #ifndef _SYNCHRONIZEABLE_H |
---|
| 7 | #define _SYNCHRONIZEABLE_H |
---|
[5523] | 8 | |
---|
[5997] | 9 | #include "base_object.h" |
---|
[5547] | 10 | #include "netdefs.h" |
---|
[6341] | 11 | #include "converter.h" |
---|
[7954] | 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" |
---|
[5547] | 22 | |
---|
[5997] | 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 | |
---|
[7954] | 30 | struct StateHistoryEntry |
---|
| 31 | { |
---|
| 32 | int stateId; |
---|
| 33 | byte * data; |
---|
| 34 | int dataLength; |
---|
| 35 | std::list<int> sizeList; |
---|
[6815] | 36 | }; |
---|
| 37 | |
---|
[7954] | 38 | typedef std::list<StateHistoryEntry*> StateHistory; |
---|
[6815] | 39 | |
---|
[7954] | 40 | typedef std::vector<StateHistory> UserStateHistory; |
---|
[6959] | 41 | |
---|
[7954] | 42 | typedef std::vector<SynchronizeableVar*> SyncVarList; |
---|
[6815] | 43 | |
---|
[6139] | 44 | class NetworkStream; |
---|
[5997] | 45 | |
---|
[5581] | 46 | class Synchronizeable : virtual public BaseObject |
---|
[6695] | 47 | { |
---|
| 48 | |
---|
[5804] | 49 | public: |
---|
[5996] | 50 | Synchronizeable(); |
---|
[6695] | 51 | virtual ~Synchronizeable(); |
---|
[5523] | 52 | |
---|
[6139] | 53 | void setIsServer( bool isServer ); |
---|
[5997] | 54 | bool isServer(); |
---|
[6695] | 55 | |
---|
[7954] | 56 | virtual void varChangeHandler( std::list<int> & id ); |
---|
| 57 | |
---|
| 58 | virtual int getStateDiff( int userId, byte* data, int maxLength, int stateId, int fromStateId, int priorityTH ); |
---|
| 59 | virtual int setStateDiff( int userId, byte* data, int length, int stateId, int fromStateId ); |
---|
| 60 | virtual void cleanUpUser( int userId ); |
---|
| 61 | virtual void handleSentState( int userId, int stateId, int fromStateId ); |
---|
| 62 | virtual void handleRecvState( int userId, int stateId, int fromStateId ); |
---|
[8068] | 63 | |
---|
[7954] | 64 | void registerVar( SynchronizeableVar * var ); |
---|
| 65 | int registerVarId( SynchronizeableVar * var ); |
---|
| 66 | |
---|
[6341] | 67 | inline void setUniqueID( int id ){ uniqueID = id; } |
---|
[6695] | 68 | inline int getUniqueID() const { return uniqueID; } |
---|
[5547] | 69 | |
---|
[6139] | 70 | inline int getOwner(){ return owner; } |
---|
| 71 | inline void setOwner(int owner){ this->owner = owner; } |
---|
| 72 | |
---|
[7954] | 73 | /** @returns true if this Synchronizeable wants to be synchronized over network */ |
---|
[6695] | 74 | inline bool beSynchronized() { return this->bSynchronize; } |
---|
| 75 | /** @param bSynchronize sets the Synchronizeable to be sunchronized or not */ |
---|
| 76 | inline void setSynchronized(bool bSynchronize) { this->bSynchronize = bSynchronize; } |
---|
[6139] | 77 | |
---|
[6695] | 78 | inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; } |
---|
| 79 | inline NetworkStream* getNetworkStream() { return this->networkStream; } |
---|
[6139] | 80 | |
---|
| 81 | |
---|
[6695] | 82 | protected: |
---|
[7954] | 83 | NetworkStream* networkStream; //!< reference network stream we are connected to |
---|
[6695] | 84 | int state; |
---|
[6139] | 85 | |
---|
[6695] | 86 | private: |
---|
[7954] | 87 | int uniqueID; //!< unique id assigned to synchronizeable |
---|
| 88 | int mLeafClassId; //!< store leafClassId to send via states |
---|
| 89 | int owner; //!< hostId of owner ( 0 if none / server ) |
---|
| 90 | bool bSynchronize; //!< do we need beeing synchronized? |
---|
[5547] | 91 | |
---|
[7954] | 92 | SyncVarList syncVarList; //!< list containing variables to synchronize |
---|
[6139] | 93 | |
---|
[7954] | 94 | UserStateHistory sentStates; //!< store already sent states to create diffs from, offset corresponds to the user id |
---|
| 95 | UserStateHistory recvStates; //!< store recieved states to apply diffs, offset corresponds to the user id |
---|
| 96 | |
---|
[6695] | 97 | }; |
---|
[5548] | 98 | #endif /* _SYNCHRONIZEABLE_H */ |
---|