- Timestamp:
- Oct 10, 2018, 3:06:55 PM (6 years ago)
- Location:
- code/branches/mergeFS18
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/mergeFS18
- Property svn:mergeinfo changed
/code/branches/Masterserver_FS18 (added) merged: 11816,11829,11842,11856,11858,11880,11889,11905,11907,11910,11929-11930,11937,11962-11963,11973,11983,11990
- Property svn:mergeinfo changed
-
code/branches/mergeFS18/src/libraries/network/packet/Gamestate.cc
r11083 r12027 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 … … 102 101 } 103 102 104 103 //AV: This takes all synchronisables and packs it in a GameState, to be sent over the network 105 104 bool Gamestate::collectData(int id, uint8_t mode) 106 105 { … … 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); … … 173 170 } 174 171 175 172 //AV: This takes the Gamestate received from the network and "unpacks" it back to a list of Objects/Synchronisables, thus updating the data 176 173 bool Gamestate::spreadData(uint8_t mode) 177 174 { … … 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 } 207 202 } 208 203 assert((uintptr_t)(mem-data_) == GamestateHeader::getSize()+header_.getDataSize()); 209 210 // In debug mode, check first, whether there are no duplicate objectIDs211 #ifndef NDEBUG212 if(this->getID()%1000==1)213 {214 std::list<uint32_t> v1;215 for (Synchronisable* synchronisable : ObjectList<Synchronisable>())216 {217 if (synchronisable->getObjectID() == OBJECTID_UNKNOWN)218 {219 if (synchronisable->objectMode_ != 0x0)220 {221 orxout(user_error, context::packets) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << endl;222 orxout(user_error, context::packets) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << endl;223 orxout(user_error, context::packets) << "Objects class: " << synchronisable->getIdentifier()->getName() << endl;224 assert(false);225 }226 }227 else228 {229 for (uint32_t id : v1)230 {231 if (synchronisable->getObjectID() == id)232 {233 orxout(user_error, context::packets) << "Found duplicate objectIDs on the client!" << endl234 << "Are you sure you don't create a Sychnronisable objcect with 'new' \235 that doesn't have objectMode = 0x0?" << endl;236 assert(false);237 }238 }239 v1.push_back(synchronisable->getObjectID());240 }241 }242 }243 #endif244 204 return true; 245 205 } … … 276 236 } 277 237 278 238 //AV: This function takes the Gamestate and compresses it for transmission over the network 279 239 bool Gamestate::compressData() 280 240 { … … 313 273 } 314 274 315 275 //AV: This function takes the compressed Gamestate received from the network and decompresses it for further unpacking 316 276 bool Gamestate::decompressData() 317 277 { … … 374 334 if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 ) 375 335 { 376 // orxout(verbose, context::packets) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;377 336 origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object 378 337 baseDataPtr += objectOffset + objectHeader.getDataSize(); … … 430 389 inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ) 431 390 { 432 // orxout(verbose, context::packets) << "docopy" << endl;433 391 // Just copy over the whole Object 434 392 memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() ); … … 437 395 newData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 438 396 origData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 439 // SynchronisableHeader baseHeader( baseData ); 440 // baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize(); 441 // orxout(verbose, context::packets) << "copy " << h.getObjectID() << endl; 442 // orxout(verbose, context::packets) << "copy " << h.getObjectID() << ":"; 397 443 398 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); 444 // for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i ) 445 // { 446 // // orxout(verbose, context::packets) << " " << *sizes; 447 // ++sizes; 448 // } 449 // orxout(verbose, context::packets) << endl; 399 450 400 } 451 401 … … 501 451 uint8_t *origDataEnd = origDataPtr + header_.getDataSize(); 502 452 uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize(); 503 // uint32_t origLength = header_.getDataSize(); 504 // uint32_t baseLength = base->header_.getDataSize(); 453 505 454 506 455 // Allocate new space for diffed gamestate … … 595 544 596 545 597 /*Gamestate* Gamestate::diffData(Gamestate *base)598 {599 assert(this && base); assert(data_ && base->data_);600 assert(!header_.isCompressed() && !base->header_.isCompressed());601 assert(!header_.isDiffed());602 603 uint8_t *basep = GAMESTATE_START(base->data_);604 uint8_t *gs = GAMESTATE_START(this->data_);605 uint32_t dest_length = header_.getDataSize();606 607 if(dest_length==0)608 return nullptr;609 610 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];611 uint8_t *dest = GAMESTATE_START(ndata);612 613 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );614 #ifndef NDEBUG615 uint8_t *dest2 = new uint8_t[dest_length];616 rawDiff( dest2, dest, basep, header_.getDataSize(), base->header_.getDataSize() );617 assert( memcmp( dest2, gs, dest_length) == 0 );618 delete dest2;619 #endif620 621 Gamestate *g = new Gamestate(ndata, getClientID());622 assert(g->header_);623 *(g->header_) = *header_;624 g->header_.setDiffed( true );625 g->header_.setBaseID( base->getID() );626 g->flags_=flags_;627 g->packetDirection_ = packetDirection_;628 assert(g->isDiffed());629 assert(!g->isCompressed());630 return g;631 }632 633 634 Gamestate* Gamestate::undiff(Gamestate *base)635 {636 assert(this && base); assert(data_ && base->data_);637 assert(!header_.isCompressed() && !base->header_.isCompressed());638 assert(header_.isDiffed());639 640 uint8_t *basep = GAMESTATE_START(base->data_);641 uint8_t *gs = GAMESTATE_START(this->data_);642 uint32_t dest_length = header_.getDataSize();643 644 if(dest_length==0)645 return nullptr;646 647 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];648 uint8_t *dest = ndata + GamestateHeader::getSize();649 650 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );651 652 Gamestate *g = new Gamestate(ndata, getClientID());653 assert(g->header_);654 *(g->header_) = *header_;655 g->header_.setDiffed( false );656 g->flags_=flags_;657 g->packetDirection_ = packetDirection_;658 assert(!g->isDiffed());659 assert(!g->isCompressed());660 return g;661 }662 663 664 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)665 {666 uint64_t* gd = (uint64_t*)data;667 uint64_t* bd = (uint64_t*)basedata;668 uint64_t* nd = (uint64_t*)newdata;669 670 unsigned int i;671 for( i=0; i<datalength/8; i++ )672 {673 if( i<baselength/8 )674 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data675 else676 *(nd+i) = *(gd+i); // just copy over the data677 }678 unsigned int j;679 // now process the rest (when datalength isn't a multiple of 4)680 for( j = 8*(datalength/8); j<datalength; j++ )681 {682 if( j<baselength )683 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor684 else685 *(newdata+j) = *(data+j); // just copy686 }687 assert(j==datalength);688 }*/689 690 691 /*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){692 assert(data_);693 std::list<obj>::iterator it;694 695 // allocate memory for new data696 uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()];697 // create a gamestate out of it698 Gamestate *gs = new Gamestate(gdata);699 uint8_t *newdata = gdata + GamestateHeader::getSize();700 uint8_t *origdata = GAMESTATE_START(data_);701 702 //copy the GamestateHeader703 assert(gs->header_);704 *(gs->header_) = *header_;705 706 uint32_t objectOffset;707 unsigned int objectsize, destsize=0;708 // TODO: Why is this variable not used?709 //Synchronisable *object;710 711 //call TrafficControl712 TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );713 714 //copy in the zeros715 // std::list<obj>::iterator itt;716 // orxout() << "myvector contains:";717 // for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )718 // orxout() << " " << (*itt).objID;719 // orxout() << endl;720 for(it=dataVector_.begin(); it!=dataVector_.end();){721 SynchronisableHeader oldobjectheader(origdata);722 SynchronisableHeader newobjectheader(newdata);723 if ( (*it).objSize == 0 )724 {725 ++it;726 continue;727 }728 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();729 objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader730 if ( (*it).objID == oldobjectheader.getObjectID() ){731 memcpy(newdata, origdata, objectsize);732 ++it;733 }else{734 newobjectheader = oldobjectheader;735 memset(newdata+objectOffset, 0, objectsize-objectOffset);736 }737 newdata += objectsize;738 origdata += objectsize;739 destsize += objectsize;740 }741 #ifndef NDEBUG742 uint32_t origsize = destsize;743 while ( origsize < header_.getDataSize() )744 {745 SynchronisableHeader oldobjectheader(origdata);746 objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();747 origdata += objectsize;748 origsize += objectsize;749 }750 assert(origsize==header_.getDataSize());751 assert(destsize!=0);752 #endif753 gs->header_.setDataSize( destsize );754 return gs;755 }*/756 757 758 546 uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode) 759 547 {
Note: See TracChangeset
for help on using the changeset viewer.