- Timestamp:
- May 24, 2018, 1:57:50 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Masterserver_FS18/src/libraries/network/packet/Gamestate.cc
r11907 r11983 46 46 #define GAMESTATE_START(data) (data + GamestateHeader::getSize()) 47 47 48 // #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable49 48 #define PACKET_FLAG_GAMESTATE 0 50 49 … … 128 127 for(it = ObjectList<Synchronisable>().begin(); it; ++it) 129 128 { 130 131 // tempsize=it->getSize(id, mode);132 129 133 130 tempsize = it->getData(mem, this->sizes_, id, mode); … … 196 193 else 197 194 { 198 // orxout(verbose, context::packets) << "not creating object of classid " << objectheader.getClassID() << endl;199 195 mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() ); 200 196 } … … 202 198 else 203 199 { 204 // orxout(verbose, context::packets) << "updating object of classid " << objectheader.getClassID() << endl;205 200 OrxVerify(s->updateData(mem, mode), "ERROR: could not update Synchronisable with Gamestate data"); 206 201 } … … 339 334 if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 ) 340 335 { 341 // orxout(verbose, context::packets) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;342 336 origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object 343 337 baseDataPtr += objectOffset + objectHeader.getDataSize(); … … 395 389 inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ) 396 390 { 397 // orxout(verbose, context::packets) << "docopy" << endl;398 391 // Just copy over the whole Object 399 392 memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() ); … … 402 395 newData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 403 396 origData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 404 // SynchronisableHeader baseHeader( baseData ); 405 // baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize(); 406 // orxout(verbose, context::packets) << "copy " << h.getObjectID() << endl; 407 // orxout(verbose, context::packets) << "copy " << h.getObjectID() << ":"; 397 408 398 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); 409 // for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i ) 410 // { 411 // // orxout(verbose, context::packets) << " " << *sizes; 412 // ++sizes; 413 // } 414 // orxout(verbose, context::packets) << endl; 399 415 400 } 416 401 … … 466 451 uint8_t *origDataEnd = origDataPtr + header_.getDataSize(); 467 452 uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize(); 468 // uint32_t origLength = header_.getDataSize(); 469 // uint32_t baseLength = base->header_.getDataSize(); 453 470 454 471 455 // Allocate new space for diffed gamestate … … 560 544 561 545 562 /*Gamestate* Gamestate::diffData(Gamestate *base)563 {564 assert(this && base); assert(data_ && base->data_);565 assert(!header_.isCompressed() && !base->header_.isCompressed());566 assert(!header_.isDiffed());567 568 uint8_t *basep = GAMESTATE_START(base->data_);569 uint8_t *gs = GAMESTATE_START(this->data_);570 uint32_t dest_length = header_.getDataSize();571 572 if(dest_length==0)573 return nullptr;574 575 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];576 uint8_t *dest = GAMESTATE_START(ndata);577 578 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );579 #ifndef NDEBUG580 uint8_t *dest2 = new uint8_t[dest_length];581 rawDiff( dest2, dest, basep, header_.getDataSize(), base->header_.getDataSize() );582 assert( memcmp( dest2, gs, dest_length) == 0 );583 delete dest2;584 #endif585 586 Gamestate *g = new Gamestate(ndata, getClientID());587 assert(g->header_);588 *(g->header_) = *header_;589 g->header_.setDiffed( true );590 g->header_.setBaseID( base->getID() );591 g->flags_=flags_;592 g->packetDirection_ = packetDirection_;593 assert(g->isDiffed());594 assert(!g->isCompressed());595 return g;596 }597 598 599 Gamestate* Gamestate::undiff(Gamestate *base)600 {601 assert(this && base); assert(data_ && base->data_);602 assert(!header_.isCompressed() && !base->header_.isCompressed());603 assert(header_.isDiffed());604 605 uint8_t *basep = GAMESTATE_START(base->data_);606 uint8_t *gs = GAMESTATE_START(this->data_);607 uint32_t dest_length = header_.getDataSize();608 609 if(dest_length==0)610 return nullptr;611 612 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];613 uint8_t *dest = ndata + GamestateHeader::getSize();614 615 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );616 617 Gamestate *g = new Gamestate(ndata, getClientID());618 assert(g->header_);619 *(g->header_) = *header_;620 g->header_.setDiffed( false );621 g->flags_=flags_;622 g->packetDirection_ = packetDirection_;623 assert(!g->isDiffed());624 assert(!g->isCompressed());625 return g;626 }627 628 629 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)630 {631 uint64_t* gd = (uint64_t*)data;632 uint64_t* bd = (uint64_t*)basedata;633 uint64_t* nd = (uint64_t*)newdata;634 635 unsigned int i;636 for( i=0; i<datalength/8; i++ )637 {638 if( i<baselength/8 )639 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data640 else641 *(nd+i) = *(gd+i); // just copy over the data642 }643 unsigned int j;644 // now process the rest (when datalength isn't a multiple of 4)645 for( j = 8*(datalength/8); j<datalength; j++ )646 {647 if( j<baselength )648 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor649 else650 *(newdata+j) = *(data+j); // just copy651 }652 assert(j==datalength);653 }*/654 655 656 /*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){657 assert(data_);658 std::list<obj>::iterator it;659 660 // allocate memory for new data661 uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()];662 // create a gamestate out of it663 Gamestate *gs = new Gamestate(gdata);664 uint8_t *newdata = gdata + GamestateHeader::getSize();665 uint8_t *origdata = GAMESTATE_START(data_);666 667 //copy the GamestateHeader668 assert(gs->header_);669 *(gs->header_) = *header_;670 671 uint32_t objectOffset;672 unsigned int objectsize, destsize=0;673 // TODO: Why is this variable not used?674 //Synchronisable *object;675 676 //call TrafficControl677 TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );678 679 //copy in the zeros680 // std::list<obj>::iterator itt;681 // orxout() << "myvector contains:";682 // for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )683 // orxout() << " " << (*itt).objID;684 // orxout() << endl;685 for(it=dataVector_.begin(); it!=dataVector_.end();){686 SynchronisableHeader oldobjectheader(origdata);687 SynchronisableHeader newobjectheader(newdata);688 if ( (*it).objSize == 0 )689 {690 ++it;691 continue;692 }693 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();694 objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader695 if ( (*it).objID == oldobjectheader.getObjectID() ){696 memcpy(newdata, origdata, objectsize);697 ++it;698 }else{699 newobjectheader = oldobjectheader;700 memset(newdata+objectOffset, 0, objectsize-objectOffset);701 }702 newdata += objectsize;703 origdata += objectsize;704 destsize += objectsize;705 }706 #ifndef NDEBUG707 uint32_t origsize = destsize;708 while ( origsize < header_.getDataSize() )709 {710 SynchronisableHeader oldobjectheader(origdata);711 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();712 origdata += objectsize;713 origsize += objectsize;714 }715 assert(origsize==header_.getDataSize());716 assert(destsize!=0);717 #endif718 gs->header_.setDataSize( destsize );719 return gs;720 }*/721 722 723 546 uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode) 724 547 {
Note: See TracChangeset
for help on using the changeset viewer.