Changeset 2655 for code/branches/presentation/src
- Timestamp:
- Feb 13, 2009, 6:41:08 PM (16 years ago)
- Location:
- code/branches/presentation/src/network
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/network/GamestateClient.cc
r2485 r2655 77 77 int id = GAMESTATEID_INITIAL; 78 78 packet::Gamestate *processed = processGamestate(tempGamestate_); 79 //assert(processed);79 assert(processed); 80 80 81 81 //now call the queued callbacks … … 83 83 84 84 if (!processed){ 85 sendAck(0);85 // sendAck(0); 86 86 return false; 87 87 } … … 91 91 last_diff_ = processed->getID(); 92 92 id = processed->getID(); 93 sendAck(id);93 // sendAck(id); 94 94 return true; 95 95 } … … 160 160 packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; 161 161 if(!base){ 162 COUT(0) << "could not find base gamestate id: " << gs->getBaseID() << endl; 162 163 delete gs; 163 164 return 0; … … 172 173 return gs; 173 174 else 175 COUT(0) << "could not spread gamestate" << endl; 174 176 return NULL; 175 177 } -
code/branches/presentation/src/network/GamestateManager.cc
r2561 r2655 134 134 // COUT(3) << "diffing" << std::endl; 135 135 gs = gs->diff(client); 136 // gs = new packet::Gamestate(*gs); 136 137 } 137 138 else{ -
code/branches/presentation/src/network/packet/Gamestate.cc
r2575 r2655 44 44 namespace packet { 45 45 46 #define GAMESTATE_START(data) (data + GamestateHeader::getSize()) 46 47 47 48 #define PACKET_FLAG_GAMESTATE ENET_PACKET_FLAG_RELIABLE 48 49 50 // Gamestate::Gamestate() 51 // { 52 // flags_ = flags_ | PACKET_FLAG_GAMESTATE; 53 // } 54 49 55 Gamestate::Gamestate() 50 56 { 51 57 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 58 header_ = 0; 52 59 } 53 60 … … 56 63 { 57 64 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 65 header_ = new GamestateHeader(data_); 58 66 } 59 67 … … 62 70 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 63 71 data_=data; 72 header_ = new GamestateHeader(data_); 64 73 } 65 74 … … 71 80 bool Gamestate::collectData(int id, uint8_t mode) 72 81 { 82 assert(this->header_==0); // make sure the header didn't exist before 73 83 uint32_t tempsize=0, currentsize=0; 74 84 assert(data_==0); … … 78 88 if(size==0) 79 89 return false; 80 data_ = new u nsigned char[size + sizeof(GamestateHeader)];90 data_ = new uint8_t[size + GamestateHeader::getSize()]; 81 91 if(!data_){ 82 92 COUT(2) << "GameStateManager: could not allocate memory" << std::endl; 83 93 return false; 84 94 } 95 96 // create the header object 97 header_ = new GamestateHeader(data_); 85 98 86 99 //start collect data synchronisable by synchronisable 87 100 uint8_t *mem=data_; 88 mem +=sizeof(GamestateHeader);101 mem += GamestateHeader::getSize(); 89 102 ObjectList<Synchronisable>::iterator it; 90 103 for(it = ObjectList<Synchronisable>::begin(); it; ++it){ … … 100 113 while(++temp) 101 114 addsize+=temp->getSize(id, mode); 102 data_ = (uint8_t *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);115 data_ = (uint8_t *)realloc(data_, GamestateHeader::getSize() + currentsize + addsize); 103 116 if(!data_) 104 117 return false; … … 119 132 120 133 //start write gamestate header 121 HEADER->packetType = ENUM::Gamestate; 122 HEADER->datasize = currentsize; 123 HEADER->id = id; 124 HEADER->diffed = false; 125 HEADER->complete = true; 126 HEADER->compressed = false; 134 header_->setDataSize( currentsize ); 135 header_->setID( id ); 136 header_->setDiffed( false ); 137 header_->setComplete( true ); 138 header_->setCompressed( false ); 127 139 //stop write gamestate header 128 140 … … 135 147 { 136 148 assert(data_); 137 assert(! HEADER->compressed);138 assert(! HEADER->diffed);139 uint8_t *mem=data_+ sizeof(GamestateHeader);149 assert(!header_->isCompressed()); 150 assert(!header_->isDiffed()); 151 uint8_t *mem=data_+GamestateHeader::getSize(); 140 152 // get the start of the Synchronisable list 141 153 //ObjectList<Synchronisable>::iterator it=ObjectList<Synchronisable>::begin(); … … 143 155 144 156 // update the data of the objects we received 145 while(mem < data_+ sizeof(GamestateHeader)+HEADER->datasize){146 synchronisableHeader *objectheader = (synchronisableHeader*)mem;147 148 s = Synchronisable::getSynchronisable( objectheader ->objectID);157 while(mem < data_+GamestateHeader::getSize()+header_->getDataSize()){ 158 SynchronisableHeader objectheader(mem); 159 160 s = Synchronisable::getSynchronisable( objectheader.getObjectID() ); 149 161 if(!s) 150 162 { 151 163 if (!Core::isMaster()) 164 { 152 165 Synchronisable::fabricate(mem, mode); 166 } 153 167 else 154 mem += objectheader->size; 168 { 169 mem += objectheader.getDataSize(); 170 } 155 171 // COUT(0) << "could not fabricate synchronisable: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl; 156 172 // else … … 196 212 { 197 213 assert(data_); 198 if( HEADER->compressed)199 return HEADER->compsize+sizeof(GamestateHeader);214 if(header_->isCompressed()) 215 return header_->getCompSize()+GamestateHeader::getSize(); 200 216 else 201 217 { 202 return HEADER->datasize+sizeof(GamestateHeader);218 return header_->getDataSize()+GamestateHeader::getSize(); 203 219 } 204 220 } 205 221 206 222 bool Gamestate::operator==(packet::Gamestate gs){ 207 uint8_t *d1 = data_+ sizeof(GamestateHeader);208 uint8_t *d2 = gs.data_+ sizeof(GamestateHeader);223 uint8_t *d1 = data_+GamestateHeader::getSize(); 224 uint8_t *d2 = gs.data_+GamestateHeader::getSize(); 209 225 assert(!isCompressed()); 210 226 assert(!gs.isCompressed()); 211 while(d1<data_+ HEADER->datasize)227 while(d1<data_+header_->getDataSize()) 212 228 { 213 229 if(*d1!=*d2) … … 228 244 bool Gamestate::compressData() 229 245 { 230 assert( HEADER);231 assert(! HEADER->compressed);232 uLongf buffer = (uLongf)((( HEADER->datasize+ 12)*1.01)+1);246 assert(data_); 247 assert(!header_->isCompressed()); 248 uLongf buffer = (uLongf)(((header_->getDataSize() + 12)*1.01)+1); 233 249 if(buffer==0) 234 250 return false; 235 251 236 uint8_t *ndata = new uint8_t[buffer+ sizeof(GamestateHeader)];237 uint8_t *dest = GAMESTATE_START(ndata);252 uint8_t *ndata = new uint8_t[buffer+GamestateHeader::getSize()]; 253 uint8_t *dest = ndata + GamestateHeader::getSize(); 238 254 //unsigned char *dest = new unsigned char[buffer]; 239 uint8_t *source = GAMESTATE_START(data_);255 uint8_t *source = data_ + GamestateHeader::getSize(); 240 256 int retval; 241 retval = compress( dest, &buffer, source, (uLong)( HEADER->datasize) );257 retval = compress( dest, &buffer, source, (uLong)(header_->getDataSize()) ); 242 258 switch ( retval ) { 243 259 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; … … 248 264 249 265 //copy and modify header 250 *GAMESTATE_HEADER(ndata) = *HEADER; 266 GamestateHeader *temp = header_; 267 header_ = new GamestateHeader(ndata, temp); 268 delete temp; 251 269 //delete old data 252 270 delete[] data_; 253 271 //save new data 254 272 data_ = ndata; 255 HEADER->compsize = buffer; 256 HEADER->compressed = true; 257 assert(HEADER->compressed); 258 COUT(4) << "gamestate compress datasize: " << HEADER->datasize << " compsize: " << HEADER->compsize << std::endl; 273 header_->setCompSize( buffer ); 274 header_->setCompressed( true ); 275 COUT(5) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl; 259 276 return true; 260 277 } 261 278 bool Gamestate::decompressData() 262 279 { 263 assert( HEADER);264 assert( HEADER->compressed);265 COUT(4) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize<< std::endl;266 uint32_t datasize = HEADER->datasize;267 uint32_t compsize = HEADER->compsize;280 assert(data_); 281 assert(header_->isCompressed()); 282 COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_->getID() << ", baseid: " << header_->getBaseID() << ", datasize: " << header_->getDataSize() << ", compsize: " << header_->getCompSize() << std::endl; 283 uint32_t datasize = header_->getDataSize(); 284 uint32_t compsize = header_->getCompSize(); 268 285 uint32_t bufsize; 269 286 // assert(compsize<=datasize); 270 287 bufsize = datasize; 271 288 assert(bufsize!=0); 272 uint8_t *ndata = new uint8_t[bufsize + sizeof(GamestateHeader)];273 uint8_t *dest = ndata + sizeof(GamestateHeader);274 uint8_t *source = data_ + sizeof(GamestateHeader);289 uint8_t *ndata = new uint8_t[bufsize + GamestateHeader::getSize()]; 290 uint8_t *dest = ndata + GamestateHeader::getSize(); 291 uint8_t *source = data_ + GamestateHeader::getSize(); 275 292 int retval; 276 293 uLongf length=bufsize; … … 284 301 285 302 //copy over the header 286 *GAMESTATE_HEADER(ndata) = *HEADER; 303 GamestateHeader *temp = header_; 304 header_ = new GamestateHeader( data_, header_ ); 305 delete temp; 287 306 288 307 if (this->bDataENetAllocated_){ … … 299 318 //set new pointers 300 319 data_ = ndata; 301 HEADER->compressed = false;302 assert( HEADER->datasize==datasize);303 assert( HEADER->compsize==compsize);320 header_->setCompressed( false ); 321 assert(header_->getDataSize()==datasize); 322 assert(header_->getCompSize()==compsize); 304 323 return true; 305 324 } … … 307 326 Gamestate *Gamestate::diff(Gamestate *base) 308 327 { 309 assert(HEADER); 310 assert(!HEADER->compressed); 311 assert(!HEADER->diffed); 328 assert(data_); 329 assert(!header_->isCompressed()); 330 assert(!header_->isDiffed()); 331 GamestateHeader diffHeader(base->data_); 312 332 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 313 333 uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_); 314 334 uint32_t of=0; // pointers offset 315 335 uint32_t dest_length=0; 316 dest_length= HEADER->datasize;336 dest_length=header_->getDataSize(); 317 337 if(dest_length==0) 318 338 return NULL; 319 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+ sizeof(GamestateHeader)];320 uint8_t *dest = ndata + sizeof(GamestateHeader);321 while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){339 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 340 uint8_t *dest = ndata + GamestateHeader::getSize(); 341 while(of < diffHeader.getDataSize() && of < header_->getDataSize()){ 322 342 *(dest+of)=*(basep+of)^*(gs+of); // do the xor 323 343 ++of; 324 344 } 325 if( GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){345 if(diffHeader.getDataSize()!=header_->getDataSize()){ 326 346 uint8_t n=0; 327 if( GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){347 if(diffHeader.getDataSize() < header_->getDataSize()){ 328 348 while(of<dest_length){ 329 349 *(dest+of)=n^*(gs+of); … … 333 353 } 334 354 335 *GAMESTATE_HEADER(ndata) = *HEADER;336 GAMESTATE_HEADER(ndata)->diffed = true;337 GAMESTATE_HEADER(ndata)->base_id = base->getID();338 355 Gamestate *g = new Gamestate(ndata, getClientID()); 356 *(g->header_) = *header_; 357 g->header_->setDiffed( true ); 358 g->header_->setBaseID( base->getID() ); 339 359 g->flags_=flags_; 340 360 g->packetDirection_ = packetDirection_; … … 347 367 348 368 // allocate memory for new data 349 uint8_t *gdata = new uint8_t[ HEADER->datasize+sizeof(GamestateHeader)];369 uint8_t *gdata = new uint8_t[header_->getDataSize()+GamestateHeader::getSize()]; 350 370 // create a gamestate out of it 351 371 Gamestate *gs = new Gamestate(gdata); 352 uint8_t *newdata = gdata + sizeof(GamestateHeader);372 uint8_t *newdata = gdata + GamestateHeader::getSize(); 353 373 uint8_t *origdata = GAMESTATE_START(data_); 354 374 355 375 //copy the GamestateHeader 356 *(GamestateHeader*)gdata = *HEADER;357 358 synchronisableHeader *oldobjectheader, *newobjectheader; 376 assert(gs->header_); 377 *(gs->header_) = *header_; 378 359 379 uint32_t objectOffset; 360 380 unsigned int objectsize, destsize=0; … … 363 383 364 384 //call TrafficControl 365 TrafficControl::getInstance()->processObjectList( clientID, HEADER->id, &dataMap_ );385 TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), &dataMap_ ); 366 386 367 387 //copy in the zeros … … 371 391 // if(it->second->getSize(HEADER->id)==0) // merged from objecthierarchy2, doesn't work anymore; TODO: change this 372 392 // continue; // merged from objecthierarchy2, doesn't work anymore; TODO: change this 373 oldobjectheader = (synchronisableHeader*)origdata;374 newobjectheader = (synchronisableHeader*)newdata;393 SynchronisableHeader oldobjectheader(origdata); 394 SynchronisableHeader newobjectheader(newdata); 375 395 if ( (*it).objSize == 0 ) 376 396 { … … 380 400 // object = Synchronisable::getSynchronisable( (*it).objID ); 381 401 // assert(object->objectID == oldobjectheader->objectID); 382 objectsize = oldobjectheader ->size;383 objectOffset= sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader384 if ( (*it).objID == oldobjectheader ->objectID){402 objectsize = oldobjectheader.getDataSize(); 403 objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader 404 if ( (*it).objID == oldobjectheader.getObjectID() ){ 385 405 memcpy(newdata, origdata, objectsize); 386 assert(newobjectheader ->dataAvailable==true);406 assert(newobjectheader.isDataAvailable()==true); 387 407 ++it; 388 408 }else{ 389 *newobjectheader = *oldobjectheader;390 newobjectheader ->dataAvailable=false;409 newobjectheader = oldobjectheader; 410 newobjectheader.setDataAvailable(false); 391 411 memset(newdata+objectOffset, 0, objectsize-objectOffset); 392 412 } … … 397 417 #ifndef NDEBUG 398 418 uint32_t origsize = destsize; 399 while ( origsize < HEADER->datasize)419 while ( origsize < header_->getDataSize() ) 400 420 { 401 oldobjectheader = (synchronisableHeader*)origdata;402 objectsize = oldobjectheader ->size;421 SynchronisableHeader oldobjectheader(origdata); 422 objectsize = oldobjectheader.getDataSize(); 403 423 origdata += objectsize; 404 424 origsize += objectsize; 405 425 } 406 assert(origsize== HEADER->datasize);426 assert(origsize==header_->getDataSize()); 407 427 assert(destsize!=0); 408 428 #endif 409 ((GamestateHeader*)gdata)->datasize = destsize;429 gs->header_->setDataSize( destsize ); 410 430 return gs; 411 431 } … … 414 434 Gamestate *Gamestate::undiff(Gamestate *base) 415 435 { 416 assert(this && base);assert( HEADER);417 assert( HEADER->diffed);418 assert(! HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);436 assert(this && base);assert(data_); 437 assert(header_->isDiffed()); 438 assert(!header_->isCompressed() && !base->header_->isCompressed()); 419 439 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 420 440 uint8_t *basep = GAMESTATE_START(base->data_); … … 422 442 uint32_t of=0; // pointers offset 423 443 uint32_t dest_length=0; 424 dest_length= HEADER->datasize;444 dest_length=header_->getDataSize(); 425 445 if(dest_length==0) 426 446 return NULL; 427 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+ sizeof(GamestateHeader)];428 uint8_t *dest = ndata + sizeof(GamestateHeader);429 while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){447 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 448 uint8_t *dest = ndata + GamestateHeader::getSize(); 449 while(of < base->header_->getDataSize() && of < header_->getDataSize()){ 430 450 *(dest+of)=*(basep+of)^*(gs+of); // do the xor 431 451 ++of; 432 452 } 433 if( GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){453 if(base->header_->getDataSize()!=header_->getDataSize()){ 434 454 uint8_t n=0; 435 if( GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){455 if(base->header_->getDataSize() < header_->getDataSize()){ 436 456 while(of < dest_length){ 437 457 *(dest+of)=n^*(gs+of); … … 440 460 } 441 461 } 442 *GAMESTATE_HEADER(ndata) = *HEADER;443 GAMESTATE_HEADER(ndata)->diffed = false;444 462 Gamestate *g = new Gamestate(ndata, getClientID()); 463 assert(g->header_); 464 *(g->header_) = *header_; 465 g->header_->setDiffed( false ); 445 466 g->flags_=flags_; 446 467 g->packetDirection_ = packetDirection_; … … 463 484 464 485 } //namespace packet 465 466 486 } //namespace orxonox -
code/branches/presentation/src/network/packet/Gamestate.h
r2575 r2655 46 46 namespace packet { 47 47 48 #define GAMESTATE_START(data) (data + sizeof(GamestateHeader)) 49 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data) 50 #define HEADER GAMESTATE_HEADER(data_) 48 class _NetworkExport GamestateHeader{ 49 public: 50 GamestateHeader(uint8_t *data){ data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; } 51 GamestateHeader(uint8_t *data, GamestateHeader* h) 52 { data_=data; memcpy(data_, h->data_, getSize()); } 53 static inline uint32_t getSize() 54 { return 21; } 51 55 52 struct _NetworkExport GamestateHeader{ 53 ENUM::Type packetType; 54 int32_t id; // id of the gamestate 55 uint32_t compsize; 56 uint32_t datasize; 57 int32_t base_id; // id of the base-gamestate diffed from 58 bool diffed:1; // wheter diffed or not 59 bool complete:1; // wheter it is a complete gamestate or only partial 60 bool compressed:1; 56 inline int32_t getID() const 57 { return *(int32_t*)(data_+4); } 58 inline void setID(int32_t id) 59 { *(int32_t*)(data_+4) = id; } 60 61 inline int32_t getBaseID() const 62 { return *(int32_t*)(data_+8); } 63 inline void setBaseID(int32_t id) 64 { *(int32_t*)(data_+8) = id; } 65 66 inline uint32_t getDataSize() const 67 { return *(uint32_t*)(data_+12); } 68 inline void setDataSize(uint32_t size) 69 { *(uint32_t*)(data_+12) = size; } 70 71 inline uint32_t getCompSize() const 72 { return *(uint32_t*)(data_+16); } 73 inline void setCompSize(uint32_t size) 74 { *(uint32_t*)(data_+16) = size; } 75 76 inline bool isDiffed() const 77 { return *(int8_t*)(data_+20) & 0x1; } 78 inline void setDiffed(bool b) 79 { *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); } 80 81 inline bool isComplete() const 82 { return *(int8_t*)(data_+20) & 0x2; } 83 inline void setComplete(bool b) 84 { *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); } 85 86 inline bool isCompressed() const 87 { return *(int8_t*)(data_+20) & 0x4; } 88 inline void setCompressed(bool b) 89 { *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); } 90 91 inline void operator=(GamestateHeader& h) 92 { memcpy( data_, h.data_, getSize()); } 93 private: 94 uint8_t *data_; 95 //#define GAMESTATE_START(data) (data + sizeof(GamestateHeader)) 96 //#define GAMESTATE_HEADER(data) ((GamestateHeader *)data) 97 //#define HEADER GAMESTATE_HEADER(data_) 98 61 99 }; 62 100 … … 74 112 bool collectData(int id, uint8_t mode=0x0); 75 113 bool spreadData( uint8_t mode=0x0); 76 inline int32_t getID() const { return HEADER->id; }77 inline bool isDiffed() const { return HEADER->diffed; }78 inline bool isCompressed() const { return HEADER->compressed; }79 inline int32_t getBaseID() const { return HEADER->base_id; }114 inline int32_t getID() const { return header_->getID(); } 115 inline bool isDiffed() const { return header_->isDiffed(); } 116 inline bool isCompressed() const { return header_->isCompressed(); } 117 inline int32_t getBaseID() const { return header_->getBaseID(); } 80 118 Gamestate *diff(Gamestate *base); 81 119 Gamestate *undiff(Gamestate *base); … … 93 131 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 94 132 std::list<obj> dataMap_; 133 GamestateHeader* header_; 95 134 }; 96 135 -
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.