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