Changeset 11983 for code/branches/Masterserver_FS18
- Timestamp:
- May 24, 2018, 1:57:50 PM (6 years ago)
- Location:
- code/branches/Masterserver_FS18/src/libraries/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Masterserver_FS18/src/libraries/network/Client.cc
r11071 r11983 166 166 } 167 167 } 168 //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now 169 // if(gs){ 170 // orxout(verbose, context::network) << "client tick: sending gs " << gs << endl; 171 // if( !gs->send() ) 172 // orxout(internal_warning, context::network) << "Problem adding partial gamestate to queue" << endl; 173 // // gs gets automatically deleted by enet callback 174 // } 168 175 169 FunctionCallManager::sendCalls(static_cast<Host*>(this)); 176 170 } 177 171 } 178 // sendPackets(); // flush the enet queue179 172 180 173 Connection::processQueue(); … … 185 178 isSynched_=true; 186 179 } 187 // GamestateManager::cleanup();; 188 // Connection::sendPackets(); 180 189 181 190 182 return; -
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 { -
code/branches/Masterserver_FS18/src/libraries/network/packet/Gamestate.h
r11071 r11983 57 57 GamestateHeader(uint8_t* data) 58 58 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } 59 /*GamestateHeader(uint8_t* data, GamestateHeader* h)60 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/61 59 void setData(uint8_t* data) 62 60 { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; } … … 127 125 inline uint32_t getDataSize() const { return header_.getDataSize(); } 128 126 Gamestate* diffVariables(Gamestate *base); 129 // Gamestate* diffData(Gamestate *base); 130 // Gamestate *undiff(Gamestate *base); 131 // Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 127 132 128 bool compressData(); 133 129 bool decompressData(); … … 136 132 // Packet functions 137 133 private: 138 // void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 139 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 134 140 135 virtual uint32_t getSize() const override; 141 136 virtual bool process(orxonox::Host* host) override; 142 137 uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0); 143 // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 144 // inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 145 138 146 139 std::list<obj> dataVector_; 147 140 GamestateHeader header_; -
code/branches/Masterserver_FS18/src/libraries/network/synchronisable/Synchronisable.cc
r11907 r11983 43 43 std::queue<uint32_t> Synchronisable::deletedObjects_; 44 44 45 uint8_t Synchronisable::state_=0x1; // dete mines wheter we are server (default) or client45 uint8_t Synchronisable::state_=0x1; // determines wheter we are server (default) or client 46 46 47 47 RegisterAbstractClass(Synchronisable).inheritsFrom<OrxonoxInterface>(); … … 179 179 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() ); 180 180 no->setObjectID(header.getObjectID()); 181 //no->contextID=header.getContextID(); //TODO: remove this182 181 no->setClassID(header.getClassID()); 183 182 assert(no->contextID_ == header.getContextID()); 184 //assert(no->classID_ == header.getClassID());185 183 orxout(verbose, context::network) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << endl; 186 184 // update data and create object/entity... … … 189 187 if (b) 190 188 { 191 // b = no->create();192 189 assert(b); 193 190 } … … 273 270 274 271 orxout(verbose_more, context::network) << "getting data from objectID_: " << objectID_ << ", classID_: " << classID_ << endl; 275 // orxout(verbose, context::network) << "objectid: " << this->objectID_ << ":";276 272 // copy to location 277 273 for(SynchronisableVariableBase* variable : syncList_) 278 274 { 279 275 uint32_t varsize = variable->getData( mem, mode ); 280 // orxout(verbose, context::network) << " " << varsize;281 276 tempsize += varsize; 282 277 sizes.push_back(varsize); 283 278 ++test; 284 //tempsize += (*i)->getSize( mode );285 279 } 286 280 assert(tempsize!=0); // if this happens an empty object (with no variables) would be transmitted 287 // orxout(verbose, context::network) << endl;288 281 289 282 header.setObjectID( this->objectID_ ); … … 340 333 } 341 334 342 //orxout(verbose_more, context::network) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << endl;343 335 if( !syncHeaderLight.isDiffed() ) 344 336 { … … 357 349 { 358 350 mem += SynchronisableHeaderLight::getSize(); 359 // orxout(debug_output, context::network) << "objectID: " << this->objectID_ << endl;360 351 while( mem < data+syncHeaderLight.getDataSize()+SynchronisableHeaderLight::getSize() ) 361 352 { 362 353 VariableID varID = *(VariableID*)mem; 363 // orxout(debug_output, context::network) << "varID: " << varID << endl;364 354 assert( varID < syncList_.size() ); 365 355 mem += sizeof(VariableID); … … 400 390 bool Synchronisable::doSync(/*int32_t id,*/ uint8_t mode) 401 391 { 402 // if(mode==0x0)403 // mode=state_;404 392 assert(mode!=0x0); 405 393 return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) ); -
code/branches/Masterserver_FS18/src/libraries/network/synchronisable/Synchronisable.h
r11071 r11983 134 134 { memcpy(data_, h.data_, getSize()); } 135 135 }; 136 137 // inline void operator=(SynchronisableHeaderLight& h1, SynchronisableHeader& h2)138 // {139 // memcpy(h1.data_, h2.data_, h1.getSize());140 // }141 136 142 137 /**
Note: See TracChangeset
for help on using the changeset viewer.