- Timestamp:
- Jan 18, 2010, 12:05:57 AM (15 years ago)
- Location:
- code/branches/network2/src/libraries/network/synchronisable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network2/src/libraries/network/synchronisable/Synchronisable.cc
r6449 r6450 132 132 * @return pointer to the newly created synchronisable 133 133 */ 134 Synchronisable *Synchronisable::fabricate(uint8_t*& mem, bool diffed,uint8_t mode)134 Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode) 135 135 { 136 136 SynchronisableHeader header(mem); 137 assert( !header.isDiffed() ); 137 138 138 139 COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl; … … 308 309 if(syncList_.empty()){ 309 310 assert(0); 310 COUT( 4) << "Synchronisable::updateData syncList_ is empty" << std::endl;311 COUT(2) << "Synchronisable::updateData syncList_ is empty" << std::endl; 311 312 return false; 312 313 } … … 314 315 uint8_t* data=mem; 315 316 // start extract header 316 SynchronisableHeader syncHeader(mem); 317 assert(syncHeader.getObjectID()==this->objectID_); 318 assert(syncHeader.getCreatorID()==this->creatorID_); 319 assert(syncHeader.getClassID()==this->classID_); 320 321 mem += SynchronisableHeader::getSize(); 322 // stop extract header 317 SynchronisableHeaderLight syncHeaderLight(mem); 318 assert(syncHeaderLight.getObjectID()==this->getObjectID()); 323 319 324 320 //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl; 325 if( !syncHeader.isDiffed() ) 326 { 321 if( !syncHeaderLight.isDiffed() ) 322 { 323 SynchronisableHeader syncHeader2(mem); 324 assert( this->getClassID() == syncHeader2.getClassID() ); 325 assert( this->getCreatorID() == syncHeader2.getCreatorID() ); 326 mem += SynchronisableHeader::getSize(); 327 327 std::vector<SynchronisableVariableBase *>::iterator i; 328 328 for(i=syncList_.begin(); i!=syncList_.end(); i++) 329 329 { 330 assert( mem <= data+syncHeader .getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream330 assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream 331 331 (*i)->putData( mem, mode, forceCallback ); 332 332 } 333 assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeader::getSize() ); 333 334 } 334 335 else 335 336 { 336 COUT(0) << "objectID: " << this->objectID_ << endl; 337 while( mem < data+syncHeader.getDataSize()+SynchronisableHeader::getSize() ) 337 mem += SynchronisableHeaderLight::getSize(); 338 // COUT(0) << "objectID: " << this->objectID_ << endl; 339 while( mem < data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() ) 338 340 { 339 uint32_t varID = *(uint32_t*)mem; 340 COUT(0) << "varID: " << varID << endl; 341 if( varID == 22 ) 342 COUT(6) << " blub " << endl; 341 VariableID varID = *(VariableID*)mem; 342 // COUT(0) << "varID: " << varID << endl; 343 343 assert( varID < syncList_.size() ); 344 mem += sizeof( uint32_t);344 mem += sizeof(VariableID); 345 345 syncList_[varID]->putData( mem, mode, forceCallback ); 346 346 } 347 }348 assert(mem == data+syncHeader.getDataSize()+SynchronisableHeader::getSize() );347 assert(mem == data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() ); 348 } 349 349 return true; 350 350 } -
code/branches/network2/src/libraries/network/synchronisable/Synchronisable.h
r6449 r6450 64 64 }; 65 65 } 66 67 typedef uint8_t VariableID; 66 68 67 69 /** … … 77 79 */ 78 80 class _NetworkExport SynchronisableHeader{ 81 friend class SynchronisableHeaderLight; 79 82 private: 80 uint8_t *data_;83 uint8_t* data_; 81 84 public: 82 85 SynchronisableHeader(uint8_t* data) 83 86 { data_ = data; } 84 87 inline static uint32_t getSize() 85 { return 1 6; }86 inline uint 32_t getDataSize() const87 { return (*(uint 32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits88 inline void setDataSize(uint 32_t size)89 { *(uint 32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }88 { return 14; } 89 inline uint16_t getDataSize() const 90 { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits 91 inline void setDataSize(uint16_t size) 92 { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); } 90 93 inline bool isDiffed() const 91 { return ( (*(uint 32_t*)data_) & 0x80000000 ) == 0x80000000; }94 { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; } 92 95 inline void setDiffed( bool b) 93 { *(uint 32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }96 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); } 94 97 inline uint32_t getObjectID() const 95 { return *(uint32_t*)(data_+ 4); }98 { return *(uint32_t*)(data_+2); } 96 99 inline void setObjectID(uint32_t objectID_) 97 { *(uint32_t*)(data_+ 4) = objectID_; }100 { *(uint32_t*)(data_+2) = objectID_; } 98 101 inline uint32_t getClassID() const 99 { return *(uint32_t*)(data_+ 8); }102 { return *(uint32_t*)(data_+6); } 100 103 inline void setClassID(uint32_t classID_) 101 { *(uint32_t*)(data_+ 8) = classID_; }104 { *(uint32_t*)(data_+6) = classID_; } 102 105 inline uint32_t getCreatorID() const 103 { return *(uint32_t*)(data_+1 2); }106 { return *(uint32_t*)(data_+10); } 104 107 inline void setCreatorID(uint32_t creatorID_) 105 { *(uint32_t*)(data_+1 2) = creatorID_; }108 { *(uint32_t*)(data_+10) = creatorID_; } 106 109 inline void operator=(SynchronisableHeader& h) 107 110 { memcpy(data_, h.data_, getSize()); } … … 119 122 class _NetworkExport SynchronisableHeaderLight{ 120 123 private: 121 uint8_t *data_;124 uint8_t* data_; 122 125 public: 123 SynchronisableHeader (uint8_t* data)126 SynchronisableHeaderLight(uint8_t* data) 124 127 { data_ = data; } 125 128 inline static uint32_t getSize() 126 { return 16; }127 inline uint 32_t getDataSize() const128 { return (*(uint 32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits129 inline void setDataSize(uint 32_t size)130 { *(uint 32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }129 { return 6; } 130 inline uint16_t getDataSize() const 131 { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 31 bits 132 inline void setDataSize(uint16_t size) 133 { *(uint16_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint16_t*)(data_) & 0x8000 ); } 131 134 inline bool isDiffed() const 132 { return ( (*(uint 32_t*)data_) & 0x80000000 ) == 0x80000000; }135 { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; } 133 136 inline void setDiffed( bool b) 134 { *(uint 32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }137 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); } 135 138 inline uint32_t getObjectID() const 136 { return *(uint32_t*)(data_+ 4); }139 { return *(uint32_t*)(data_+2); } 137 140 inline void setObjectID(uint32_t objectID_) 138 { *(uint32_t*)(data_+ 4) = objectID_; }141 { *(uint32_t*)(data_+2) = objectID_; } 139 142 inline void operator=(SynchronisableHeader& h) 140 143 { memcpy(data_, h.data_, getSize()); } … … 153 156 static void setClient(bool b); 154 157 155 static Synchronisable *fabricate(uint8_t*& mem, bool diffed,uint8_t mode=0x0);158 static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0); 156 159 static bool deleteObject(uint32_t objectID_); 157 160 static Synchronisable *getSynchronisable(uint32_t objectID_); … … 168 171 169 172 inline uint32_t getNrOfVariables(){ return this->syncList_.size(); } 170 inline uint32_t getVarSize( uint32_tID )173 inline uint32_t getVarSize( VariableID ID ) 171 174 { return this->syncList_[ID]->getSize(state_); } 172 175
Note: See TracChangeset
for help on using the changeset viewer.