Changeset 2355 for code/branches/network64/src/network/packet/Gamestate.cc
- Timestamp:
- Dec 8, 2008, 8:36:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network64/src/network/packet/Gamestate.cc
r2309 r2355 28 28 29 29 #include "Gamestate.h" 30 #include "network/ClientInformation.h" 31 #include "network/GamestateHandler.h" 30 #include "../GamestateHandler.h" 31 #include "../synchronisable/Synchronisable.h" 32 #include "../TrafficControl.h" 32 33 #include "core/CoreIncludes.h" 33 34 #include "core/Iterator.h" … … 48 49 49 50 #define PACKET_FLAG_GAMESTATE ENET_PACKET_FLAG_RELIABLE 51 52 TrafficControl Gamestate::trafficControl_; 50 53 51 54 Gamestate::Gamestate() … … 109 112 110 113 //if(it->doSelection(id)) 111 dataMap_[mem-data_]=(*it); // save the mem location of the synchronisable data 114 if(tempsize!=0) 115 dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) ); 116 // dataMap_[mem-data_]=(*it); // save the mem location of the synchronisable data 112 117 if(!it->getData(mem, id, mode)) 113 118 return false; // mem pointer gets automatically increased because of call by reference … … 148 153 if(!s) 149 154 { 150 Synchronisable::fabricate(mem, mode); 155 s = Synchronisable::fabricate(mem, mode); 156 if(s==0) 157 assert(0); 158 // COUT(0) << "could not fabricate synchronisable: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl; 159 // else 160 // COUT(0) << "fabricated: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl; 151 161 } 152 162 else … … 332 342 } 333 343 334 Gamestate* Gamestate::doSelection(unsigned int clientID ){344 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 335 345 assert(data_); 336 std:: map<uint32_t, Synchronisable *>::iterator it;346 std::list<obj>::iterator it; 337 347 338 348 // allocate memory for new data … … 341 351 Gamestate *gs = new Gamestate(gdata); 342 352 uint8_t *newdata = gdata + sizeof(GamestateHeader); 343 uint8_t *origdata = GAMESTATE_START(data_);353 // uint8_t *origdata = GAMESTATE_START(data_); 344 354 345 355 //copy the GamestateHeader … … 348 358 synchronisableHeader *oldobjectheader, *newobjectheader; 349 359 uint32_t objectOffset; 350 360 unsigned int objectsize, destsize=0; 361 Synchronisable *object; 362 363 //call TrafficControl 364 trafficControl_.processObjectList( clientID, HEADER->id, &dataMap_ ); 365 351 366 //copy in the zeros 352 367 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 353 oldobjectheader = (synchronisableHeader*) origdata;368 oldobjectheader = (synchronisableHeader*)(data_ + (*it).objDataOffset); 354 369 newobjectheader = (synchronisableHeader*)newdata; 355 uint32_t objectsize = oldobjectheader->size; 356 assert(it->second->objectID==oldobjectheader->objectID); 370 object = Synchronisable::getSynchronisable( (*it).objID ); 371 assert(object->objectID == oldobjectheader->objectID); 372 objectsize = oldobjectheader->size; 357 373 *newobjectheader = *oldobjectheader; 358 374 objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader 359 if (it->second->doSelection(HEADER->id)){375 if ( /*object->doSelection(HEADER->id)*/true ){ 360 376 assert(newobjectheader->dataAvailable==true); 361 memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);377 memcpy(newdata+objectOffset, data_ + (*it).objDataOffset + objectOffset, objectsize-objectOffset); 362 378 }else{ 363 379 newobjectheader->dataAvailable=false; … … 366 382 } 367 383 newdata += objectsize; 368 origdata += objectsize; 369 } 384 destsize += objectsize; 385 // origdata += objectsize; 386 } 387 ((GamestateHeader*)gdata)->datasize = destsize; 388 assert(destsize!=0); 370 389 return gs; 371 390 } … … 382 401 383 402 //preparations 384 std:: map<uint32_t, Synchronisable *>::iterator it;403 std::list<obj>::iterator it; 385 404 uint8_t *origdata, *basedata, *destdata, *ndata; 386 405 uint32_t objectOffset, streamOffset=0; //data offset … … 388 407 synchronisableHeader *origheader; 389 408 synchronisableHeader *destheader; 409 Synchronisable *object; 390 410 391 411 origdata = GAMESTATE_START(this->data_); … … 397 417 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ 398 418 assert(streamOffset<HEADER->datasize); 399 bool sendData = it->second->doSelection(HEADER->id);400 419 origheader = (synchronisableHeader *)(origdata+streamOffset); 401 420 destheader = (synchronisableHeader *)(destdata+streamOffset); 421 object = Synchronisable::getSynchronisable(origheader->objectID); 422 bool sendData = object->doSelection(HEADER->id); 402 423 403 424 //copy and partially diff the object header … … 450 471 451 472 //preparations 452 std:: map<uint32_t, Synchronisable *>::iterator it;473 std::list<obj>::iterator it; 453 474 uint8_t *origdata, *basedata, *destdata, *ndata; 454 475 uint32_t objectOffset, streamOffset=0; //data offset … … 456 477 synchronisableHeader *origheader; 457 478 synchronisableHeader *destheader; 479 Synchronisable *object; 458 480 459 481 origdata = GAMESTATE_START(this->data_); … … 467 489 origheader = (synchronisableHeader *)(origdata+streamOffset); 468 490 destheader = (synchronisableHeader *)(destdata+streamOffset); 491 object = Synchronisable::getSynchronisable( origheader->objectID ); 469 492 bool sendData; 470 493
Note: See TracChangeset
for help on using the changeset viewer.