- Timestamp:
- Jan 17, 2010, 11:49:48 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network2/src/libraries/network/synchronisable/Synchronisable.h
r6417 r6449 71 71 * in an emulated bitset. 72 72 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 73 * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 073 * Bit 32 is a bool and defines whether the variables are stored in diff mode 74 74 * Byte 5 to 8: objectID_ 75 75 * Byte 9 to 12: classID_ … … 88 88 inline void setDataSize(uint32_t size) 89 89 { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); } 90 inline bool isD ataAvailable() const90 inline bool isDiffed() const 91 91 { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; } 92 inline void setD ataAvailable( bool b)92 inline void setDiffed( bool b) 93 93 { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); } 94 94 inline uint32_t getObjectID() const … … 108 108 }; 109 109 110 /** 111 * @brief: stores information about a Synchronisable (light version) 112 * 113 * This class stores the information about a Synchronisable (objectID_, dataSize) 114 * in an emulated bitset. 115 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 116 * Bit 32 is a bool and defines whether the variables are stored in diff mode 117 * Byte 5 to 8: objectID_ 118 */ 119 class _NetworkExport SynchronisableHeaderLight{ 120 private: 121 uint8_t *data_; 122 public: 123 SynchronisableHeader(uint8_t* data) 124 { data_ = data; } 125 inline static uint32_t getSize() 126 { return 16; } 127 inline uint32_t getDataSize() const 128 { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits 129 inline void setDataSize(uint32_t size) 130 { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); } 131 inline bool isDiffed() const 132 { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; } 133 inline void setDiffed( bool b) 134 { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); } 135 inline uint32_t getObjectID() const 136 { return *(uint32_t*)(data_+4); } 137 inline void setObjectID(uint32_t objectID_) 138 { *(uint32_t*)(data_+4) = objectID_; } 139 inline void operator=(SynchronisableHeader& h) 140 { memcpy(data_, h.data_, getSize()); } 141 }; 110 142 111 143 /** … … 121 153 static void setClient(bool b); 122 154 123 static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);155 static Synchronisable *fabricate(uint8_t*& mem, bool diffed, uint8_t mode=0x0); 124 156 static bool deleteObject(uint32_t objectID_); 125 157 static Synchronisable *getSynchronisable(uint32_t objectID_); … … 134 166 135 167 void setSyncMode(uint8_t mode); 168 169 inline uint32_t getNrOfVariables(){ return this->syncList_.size(); } 170 inline uint32_t getVarSize( uint32_t ID ) 171 { return this->syncList_[ID]->getSize(state_); } 136 172 137 173 protected: … … 143 179 144 180 private: 145 uint32_t getData(uint8_t*& me n, int32_t id, uint8_t mode=0x0);181 uint32_t getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode); 146 182 uint32_t getSize(int32_t id, uint8_t mode=0x0); 147 183 bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false); 148 bool isMyData(uint8_t* mem);149 184 bool doSync(int32_t id, uint8_t mode=0x0); 150 185 … … 156 191 uint32_t classID_; 157 192 158 std::vector<SynchronisableVariableBase*> syncList ;159 std::vector<SynchronisableVariableBase*> stringList ;193 std::vector<SynchronisableVariableBase*> syncList_; 194 std::vector<SynchronisableVariableBase*> stringList_; 160 195 uint32_t dataSize_; //size of all variables except strings 161 196 static uint8_t state_; // detemines wheter we are server (default) or client … … 171 206 if (bidirectional) 172 207 { 173 syncList .push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));174 this->dataSize_ += syncList .back()->getSize(state_);208 syncList_.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb)); 209 this->dataSize_ += syncList_.back()->getSize(state_); 175 210 } 176 211 else 177 212 { 178 syncList .push_back(new SynchronisableVariable<T>(variable, mode, cb));213 syncList_.push_back(new SynchronisableVariable<T>(variable, mode, cb)); 179 214 if ( this->state_ == mode ) 180 this->dataSize_ += syncList .back()->getSize(state_);215 this->dataSize_ += syncList_.back()->getSize(state_); 181 216 } 182 217 }
Note: See TracChangeset
for help on using the changeset viewer.