Changeset 2655 for code/branches/presentation/src/network/synchronisable
- Timestamp:
- Feb 13, 2009, 6:41:08 PM (16 years ago)
- Location:
- code/branches/presentation/src/network/synchronisable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/network/synchronisable/Synchronisable.cc
r2575 r2655 28 28 */ 29 29 30 //31 // C++ Implementation: synchronisable32 //33 // Description:34 //35 //36 // Author: Dumeni, Oliver Scheuss, (C) 200737 //38 // Copyright: See COPYING file that comes with this distribution39 //40 30 41 31 #include "Synchronisable.h" … … 155 145 Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode) 156 146 { 157 synchronisableHeader *header = (synchronisableHeader *)mem;158 159 if(!header ->dataAvailable)160 { 161 mem += header ->size;147 SynchronisableHeader header(mem); 148 149 if(!header.isDataAvailable()) 150 { 151 mem += header.getDataSize(); 162 152 return 0; 163 153 } 164 154 165 COUT(4) << "fabricating object with id: " << header ->objectID<< std::endl;166 167 Identifier* id = ClassByID(header ->classID);155 COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl; 156 157 Identifier* id = ClassByID(header.getClassID()); 168 158 if (!id) 169 159 { … … 174 164 assert(id); 175 165 BaseObject* creator = 0; 176 if (header ->creatorID!= OBJECTID_UNKNOWN)177 { 178 Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header ->creatorID);166 if (header.getCreatorID() != OBJECTID_UNKNOWN) 167 { 168 Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header.getCreatorID()); 179 169 if (!synchronisable_creator) 180 170 { 181 mem += header ->size; //.TODO: this suckz.... remove size from header182 //assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^171 mem += header.getDataSize(); //.TODO: this suckz.... remove size from header 172 assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^ 183 173 return 0; 184 174 } … … 186 176 creator = dynamic_cast<BaseObject*>(synchronisable_creator); 187 177 } 188 assert(getSynchronisable(header ->objectID)==0); //make sure no object with this id exists178 assert(getSynchronisable(header.getObjectID())==0); //make sure no object with this id exists 189 179 BaseObject *bo = id->fabricate(creator); 190 180 assert(bo); 191 181 Synchronisable *no = dynamic_cast<Synchronisable *>(bo); 192 182 assert(no); 193 no->objectID=header ->objectID;194 no->creatorID=header ->creatorID; //TODO: remove this195 no->classID=header ->classID;183 no->objectID=header.getObjectID(); 184 no->creatorID=header.getCreatorID(); //TODO: remove this 185 no->classID=header.getClassID(); 196 186 COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 197 187 // update data and create object/entity... … … 329 319 330 320 // start copy header 331 synchronisableHeader *header = (synchronisableHeader *)mem;332 header ->size = size;333 header ->objectID = this->objectID;334 header ->creatorID = this->creatorID;335 header ->classID = this->classID;336 header ->dataAvailable = true;337 tempsize += sizeof(synchronisableHeader);338 mem += sizeof(synchronisableHeader);321 SynchronisableHeader header(mem); 322 header.setDataSize( size ); 323 header.setObjectID( this->objectID ); 324 header.setCreatorID( this->creatorID ); 325 header.setClassID( this->classID ); 326 header.setDataAvailable( true ); 327 tempsize += SynchronisableHeader::getSize(); 328 mem += SynchronisableHeader::getSize(); 339 329 // end copy header 340 330 … … 371 361 uint8_t* data=mem; 372 362 // start extract header 373 synchronisableHeader *syncHeader = (synchronisableHeader *)mem;374 assert(syncHeader ->objectID==this->objectID);375 assert(syncHeader ->creatorID==this->creatorID);376 assert( this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?377 if(syncHeader ->dataAvailable==false){378 mem += syncHeader ->size;363 SynchronisableHeader syncHeader(mem); 364 assert(syncHeader.getObjectID()==this->objectID); 365 assert(syncHeader.getCreatorID()==this->creatorID); 366 assert(syncHeader.getClassID()==this->classID); 367 if(syncHeader.isDataAvailable()==false){ 368 mem += syncHeader.getDataSize(); 379 369 return true; 380 370 } 381 371 382 mem += sizeof(synchronisableHeader);372 mem += SynchronisableHeader::getSize(); 383 373 // stop extract header 384 374 385 COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl; 386 for(i=syncList.begin(); i!=syncList.end() && mem <= data+syncHeader->size; i++) 387 { 375 //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl; 376 for(i=syncList.begin(); i!=syncList.end(); i++) 377 { 378 assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream 388 379 (*i)->putData( mem, mode, forceCallback ); 389 380 } 390 assert(mem == data+syncHeader ->size);381 assert(mem == data+syncHeader.getDataSize()); 391 382 return true; 392 383 } … … 399 390 */ 400 391 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){ 401 int tsize= sizeof(synchronisableHeader);392 int tsize=SynchronisableHeader::getSize(); 402 393 if(mode==0x0) 403 394 mode=state_; … … 428 419 bool Synchronisable::isMyData(uint8_t* mem) 429 420 { 430 synchronisableHeader *header = (synchronisableHeader *)mem;431 assert(header ->objectID==this->objectID);432 return header ->dataAvailable;421 SynchronisableHeader header(mem); 422 assert(header.getObjectID()==this->objectID); 423 return header.isDataAvailable(); 433 424 } 434 425 -
code/branches/presentation/src/network/synchronisable/Synchronisable.h
r2575 r2655 72 72 } 73 73 74 struct _NetworkExport synchronisableHeader{ 75 uint32_t size:31; 76 bool dataAvailable:1; 77 uint32_t objectID; 78 uint32_t creatorID; 79 uint32_t classID; 74 /** 75 * @brief: stores information about a Synchronisable 76 * 77 * This class stores the information about a Synchronisable (objectID, classID, creatorID, dataSize) 78 * in an emulated bitset. 79 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 80 * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0 81 * Byte 5 to 8: objectID 82 * Byte 9 to 12: classID 83 * Byte 13 to 16: creatorID 84 */ 85 class _NetworkExport SynchronisableHeader{ 86 private: 87 uint8_t *data_; 88 public: 89 SynchronisableHeader(uint8_t* data) 90 { data_ = data; } 91 inline static uint32_t getSize() 92 { return 16; } 93 inline uint32_t getDataSize() const 94 { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits 95 inline void setDataSize(uint32_t size) 96 { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); } 97 inline bool isDataAvailable() const 98 { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; } 99 inline void setDataAvailable( bool b) 100 { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); } 101 inline uint32_t getObjectID() const 102 { return *(uint32_t*)(data_+4); } 103 inline void setObjectID(uint32_t objectID) 104 { *(uint32_t*)(data_+4) = objectID; } 105 inline uint32_t getClassID() const 106 { return *(uint32_t*)(data_+8); } 107 inline void setClassID(uint32_t classID) 108 { *(uint32_t*)(data_+8) = classID; } 109 inline uint32_t getCreatorID() const 110 { return *(uint32_t*)(data_+12); } 111 inline void setCreatorID(uint32_t creatorID) 112 { *(uint32_t*)(data_+12) = creatorID; } 113 inline void operator=(SynchronisableHeader& h) 114 { memcpy(data_, h.data_, getSize()); } 80 115 }; 81 116 … … 83 118 /** 84 119 * This class is the base class of all the Objects in the universe that need to be synchronised over the network 85 120 * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. 86 121 * @author Oliver Scheuss 87 122 */
Note: See TracChangeset
for help on using the changeset viewer.