Changeset 7753
- Timestamp:
- Dec 10, 2010, 5:07:02 PM (14 years ago)
- Location:
- code/branches/network4/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network4/src/libraries/network/packet/Gamestate.cc
r7497 r7753 364 364 365 365 366 inline void /*Gamestate::*/diffObject( uint8_t*& newData , uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )366 inline void /*Gamestate::*/diffObject( uint8_t*& newDataPtr, uint8_t*& origDataPtr, uint8_t*& baseDataPtr, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ) 367 367 { 368 368 // COUT(4) << "dodiff" << endl; … … 371 371 // assert(origOffset==0); 372 372 // } 373 assert( objectHeader.getDataSize() == SynchronisableHeader(baseDataPtr).getDataSize() ); 374 373 375 uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData 374 376 // Check whether the whole object stayed the same 375 if( memcmp( origData +objectOffset, baseData+objectOffset, objectHeader.getDataSize()) == 0 )376 { 377 // COUT(4) << "skip object" << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;378 origData += objectOffset + objectHeader.getDataSize(); // skip the whole object379 baseData += objectOffset + objectHeader.getDataSize();377 if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 ) 378 { 379 // COUT(4) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl; 380 origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object 381 baseDataPtr += objectOffset + objectHeader.getDataSize(); 380 382 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); 381 383 } 382 384 else 383 385 { 384 // if( Synchronisable::getSynchronisable( h.getObjectID())->getIdentifier()->getName() == "Bot" )386 // if( Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() == "Bot" ) 385 387 // COUT(0) << "blub" << endl; 386 388 // COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl; 387 389 // COUT(4) << "diff " << h.getObjectID() << ":"; 388 390 // Now start to diff the Object 389 SynchronisableHeaderLight h2(newData);390 h2= objectHeader; // copy over the objectheader391 SynchronisableHeaderLight newObjectHeader(newDataPtr); 392 newObjectHeader = objectHeader; // copy over the objectheader 391 393 VariableID variableID = 0; 392 uint32_t newObjectOffset = SynchronisableHeaderLight::getSize();394 uint32_t diffedObjectOffset = SynchronisableHeaderLight::getSize(); 393 395 // iterate through all variables 394 396 while( objectOffset < objectHeader.getDataSize()+SynchronisableHeader::getSize() ) … … 401 403 if ( varSize != 0 ) 402 404 { 403 if ( memcmp(origData +objectOffset, baseData+objectOffset, varSize) != 0 )405 if ( memcmp(origDataPtr+objectOffset, baseDataPtr+objectOffset, varSize) != 0 ) 404 406 { 405 407 // COUT(4) << "copy variable" << endl; 406 *(VariableID*)(newData +newObjectOffset) = variableID; // copy over the variableID407 newObjectOffset += sizeof(VariableID);408 memcpy( newData +newObjectOffset, origData+objectOffset, varSize );409 newObjectOffset += varSize;408 *(VariableID*)(newDataPtr+diffedObjectOffset) = variableID; // copy over the variableID 409 diffedObjectOffset += sizeof(VariableID); 410 memcpy( newDataPtr+diffedObjectOffset, origDataPtr+objectOffset, varSize ); 411 diffedObjectOffset += varSize; 410 412 objectOffset += varSize; 411 413 } … … 427 429 // COUT(4) << endl; 428 430 429 h2.setDiffed(true);430 h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize());431 newObjectHeader.setDiffed(true); 432 newObjectHeader.setDataSize(diffedObjectOffset-SynchronisableHeaderLight::getSize()); 431 433 assert(objectOffset == objectHeader.getDataSize()+SynchronisableHeader::getSize()); 432 assert( h2.getDataSize()>0);433 origData += objectOffset;434 assert(newObjectHeader.getDataSize()>0); 435 origDataPtr += objectOffset; 434 436 // baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData; 435 437 //baseOffset += objectOffset; … … 445 447 // } 446 448 // } 447 baseData += objectOffset;448 newData += newObjectOffset;449 baseDataPtr += objectOffset; 450 newDataPtr += diffedObjectOffset; 449 451 } 450 452 } … … 457 459 newData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 458 460 origData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 459 SynchronisableHeader baseHeader( baseData );460 baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize();461 // SynchronisableHeader baseHeader( baseData ); 462 // baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize(); 461 463 // COUT(4) << "copy " << h.getObjectID() << endl; 462 464 // COUT(4) << "copy " << h.getObjectID() << ":"; … … 470 472 } 471 473 474 inline bool findObject(uint8_t*& dataPtr, uint8_t* endPtr, SynchronisableHeader& objectHeader) 475 { 476 // Some assertions to make sure the dataPtr is valid (pointing to a SynchronisableHeader) 477 { 478 SynchronisableHeader htemp2(dataPtr); 479 assert(htemp2.getClassID()<500); 480 assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 481 assert(htemp2.isDiffed()==false); 482 } 483 uint32_t objectID = objectHeader.getObjectID(); 484 while ( dataPtr < endPtr ) 485 { 486 SynchronisableHeader htemp(dataPtr); 487 assert( htemp.getDataSize()!=0 ); 488 if ( htemp.getObjectID() == objectID ) 489 { 490 assert( objectHeader.getClassID() == htemp.getClassID() ); 491 assert( objectHeader.getCreatorID() == htemp.getCreatorID() ); 492 return true; 493 } 494 { 495 if( dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize() < endPtr ) 496 { 497 SynchronisableHeader htemp2(dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize()); 498 assert(htemp2.getClassID()<500); 499 assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 500 assert(htemp2.isDiffed()==false); 501 } 502 } 503 dataPtr += htemp.getDataSize()+SynchronisableHeader::getSize(); 504 505 } 506 assert(dataPtr == endPtr); 507 508 return false; 509 } 510 472 511 Gamestate* Gamestate::diffVariables(Gamestate *base) 473 512 { … … 475 514 assert(!header_->isCompressed() && !base->header_->isCompressed()); 476 515 assert(!header_->isDiffed()); 516 assert( header_->getDataSize() && base->header_->getDataSize() ); 477 517 478 518 479 519 // *** first do a raw diff of the two gamestates 480 520 481 uint8_t *baseData = GAMESTATE_START(base->data_);482 uint8_t *origData = GAMESTATE_START(this->data_);483 uint8_t *origDataEnd = origData + header_->getDataSize();484 uint8_t *baseDataEnd = baseData + base->header_->getDataSize();521 uint8_t *baseDataPtr = GAMESTATE_START(base->data_); 522 uint8_t *origDataPtr = GAMESTATE_START(this->data_); 523 uint8_t *origDataEnd = origDataPtr + header_->getDataSize(); 524 uint8_t *baseDataEnd = baseDataPtr + base->header_->getDataSize(); 485 525 // uint32_t origLength = header_->getDataSize(); 486 526 // uint32_t baseLength = base->header_->getDataSize(); 487 527 488 assert( header_->getDataSize() && base->header_->getDataSize() ); 489 528 // Allocate new space for diffed gamestate 490 529 uint32_t newDataSize = header_->getDataSize() + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_; 491 530 uint8_t *newData = new uint8_t[newDataSize]; // this is the maximum size needed in the worst case 492 uint8_t *dest = GAMESTATE_START(newData); 493 494 // uint32_t baseOffset = 0; //offset in the diffed stream 495 // uint32_t origOffset = 0; //offset in the new stream with removed 0's 496 std::vector<uint32_t>::iterator sizes = this->sizes_.begin(); 497 498 while( origData < origDataEnd ) 531 uint8_t *destDataPtr = GAMESTATE_START(newData); 532 533 std::vector<uint32_t>::iterator sizesIt = this->sizes_.begin(); 534 535 while( origDataPtr < origDataEnd ) 499 536 { 500 537 //iterate through all objects 501 538 502 SynchronisableHeader h(origData);539 SynchronisableHeader origHeader(origDataPtr); 503 540 504 541 // Find (if possible) the current object in the datastream of the old gamestate 505 542 // Start at the current offset position 506 if(baseData >= baseDataEnd) 507 baseData = GAMESTATE_START(base->data_); 508 // uint8_t* temp = baseData + baseOffset; 509 uint32_t objectID = h.getObjectID(); 510 assert(baseData < baseDataEnd); 511 assert(dest < newData + newDataSize); 512 assert(sizes != this->sizes_.end()); 543 if(baseDataPtr == baseDataEnd) 544 baseDataPtr = GAMESTATE_START(base->data_); 545 uint8_t* oldBaseDataPtr = baseDataPtr; 546 547 assert(baseDataPtr < baseDataEnd); 548 assert(destDataPtr < newData + newDataSize); 549 assert(sizesIt != this->sizes_.end()); 550 513 551 bool diffedObject = false; 514 while ( baseData < baseDataEnd ) 515 { 516 SynchronisableHeader htemp(baseData); 517 assert( htemp.getDataSize()!=0 ); 518 if ( htemp.getObjectID() == objectID ) 519 { 520 assert( h.getClassID() == htemp.getClassID() ); 521 // goto DODIFF; 522 diffObject(dest, origData, baseData, h, sizes); 552 if( findObject(baseDataPtr, baseDataEnd, origHeader) ) 553 { 554 if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() ) 555 { 556 // COUT(4) << "diffing object in order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 557 diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 523 558 diffedObject = true; 524 break; 525 } 526 { 527 SynchronisableHeader htemp2(baseData+htemp.getDataSize()+SynchronisableHeader::getSize()); 528 if( baseData+htemp.getDataSize()+SynchronisableHeader::getSize() < baseDataEnd ) 559 } 560 else 561 { 562 // COUT(4) << "copy object because of different data sizes (1): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 563 copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 564 assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd); 565 } 566 567 } 568 else 569 { 570 assert( baseDataPtr == baseDataEnd ); 571 baseDataPtr = GAMESTATE_START(base->data_); 572 if( findObject(baseDataPtr, oldBaseDataPtr, origHeader) ) 573 { 574 if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() ) 529 575 { 530 assert(htemp2.getClassID()<500);531 assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);532 assert(htemp2.isDiffed()==false);576 // COUT(4) << "diffing object out of order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 577 diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 578 diffedObject = true; 533 579 } 534 } 535 baseData += htemp.getDataSize()+SynchronisableHeader::getSize(); 536 // assert( baseData+htemp.getDataSize()+SynchronisableHeader::getSize() <=baseData+baseLength ); 537 // temp += htemp.getDataSize()+SynchronisableHeader::getSize(); 538 539 } 540 // If not found start looking at the beginning 541 assert( diffedObject || baseData == baseDataEnd ); 542 baseData = GAMESTATE_START(base->data_); 543 { 544 SynchronisableHeader htemp2(baseData); 545 if( baseData < baseDataEnd ) 546 { 547 assert(htemp2.getClassID()<500); 548 assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 549 assert(htemp2.isDiffed()==false); 550 } 551 } 552 while ( !diffedObject && baseData < baseDataEnd ) 553 { 554 SynchronisableHeader htemp(baseData); 555 if ( htemp.getObjectID() == objectID ) 556 { 557 assert( h.getClassID() == htemp.getClassID() ); 558 // goto DODIFF; 559 diffObject(dest, origData, baseData, h, sizes); 560 break; 561 } 562 // { 563 // SynchronisableHeader htemp2(baseData+htemp.getDataSize()+SynchronisableHeader::getSize()); 564 // if( baseData+htemp.getDataSize()+SynchronisableHeader::getSize() < baseDataEnd ) 565 // { 566 // assert(htemp2.getClassID()<500); 567 // assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 568 // assert(htemp2.isDiffed()==false); 569 // } 570 // } 571 baseData += htemp.getDataSize()+SynchronisableHeader::getSize(); 572 } 573 // Object is new, thus never transmitted -> just copy over 574 // goto DOCOPY; 575 if ( baseData >= baseDataEnd ) 576 { 577 assert(baseData == baseDataEnd); 578 copyObject(dest, origData, baseData, h, sizes); 579 assert(sizes != this->sizes_.end() || origData>=origDataEnd); 580 } 581 } 582 assert(sizes==this->sizes_.end()); 580 else 581 { 582 // COUT(4) << "copy object because of different data sizes (2): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 583 copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 584 assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd); 585 } 586 } 587 else 588 { 589 // COUT(4) << "copy object: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 590 assert(baseDataPtr == oldBaseDataPtr); 591 copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 592 assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd); 593 } 594 } 595 } 596 assert(sizesIt==this->sizes_.end()); 583 597 584 598 … … 587 601 *(g->header_) = *header_; 588 602 g->header_->setBaseID( base->getID() ); 589 g->header_->setDataSize(dest - newData - GamestateHeader::getSize());603 g->header_->setDataSize(destDataPtr - newData - GamestateHeader::getSize()); 590 604 g->flags_=flags_; 591 605 g->packetDirection_ = packetDirection_; … … 595 609 596 610 597 Gamestate* Gamestate::diffData(Gamestate *base)611 /*Gamestate* Gamestate::diffData(Gamestate *base) 598 612 { 599 613 assert(this && base); assert(data_ && base->data_); … … 686 700 } 687 701 assert(j==datalength); 688 } 689 690 691 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){702 }*/ 703 704 705 /*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 692 706 assert(data_); 693 707 std::list<obj>::iterator it; … … 753 767 gs->header_->setDataSize( destsize ); 754 768 return gs; 755 } 769 }*/ 756 770 757 771 -
code/branches/network4/src/libraries/network/packet/Gamestate.h
r7497 r7753 116 116 inline uint32_t getDataSize() const { return header_->getDataSize(); } 117 117 Gamestate* diffVariables(Gamestate *base); 118 Gamestate* diffData(Gamestate *base);119 Gamestate *undiff(Gamestate *base);120 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);118 // Gamestate* diffData(Gamestate *base); 119 // Gamestate *undiff(Gamestate *base); 120 // Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 121 121 bool compressData(); 122 122 bool decompressData(); … … 125 125 // Packet functions 126 126 private: 127 void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);128 inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );127 // void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 128 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 129 129 virtual uint32_t getSize() const; 130 130 virtual inline bool process(); -
code/branches/network4/src/orxonox/gametypes/Gametype.cc
r7284 r7753 79 79 else 80 80 this->scoreboard_ = 0; 81 82 /* HACK HACK HACK */ 83 this->dedicatedAddBots_ = createConsoleCommand( "dedicatedAddBots", createExecutor( createFunctor(&Gametype::addBots, this) ) ); 84 this->dedicatedKillBots_ = createConsoleCommand( "dedicatedKillBots", createExecutor( createFunctor(&Gametype::killBots, this) ) ); 85 /* HACK HACK HACK */ 81 86 } 82 87 … … 86 91 { 87 92 this->gtinfo_->destroy(); 93 if( this->dedicatedAddBots_ ) 94 delete this->dedicatedAddBots_; 95 if( this->dedicatedKillBots_ ) 96 delete this->dedicatedKillBots_; 88 97 } 89 98 } -
code/branches/network4/src/orxonox/gametypes/Gametype.h
r7284 r7753 184 184 // Config Values 185 185 std::string scoreboardTemplate_; 186 187 /* HACK HACK HACK */ 188 ConsoleCommand* dedicatedAddBots_; 189 ConsoleCommand* dedicatedKillBots_; 190 /* HACK HACK HACK */ 186 191 }; 187 192 } -
code/branches/network4/src/orxonox/worldentities/ControllableEntity.cc
r7495 r7753 87 87 this->setPriority( Priority::VeryHigh ); 88 88 this->registerVariables(); 89 COUT(0) << "CE creator" << endl;90 if( GameMode::isMaster() )91 callMemberNetworkFunction(ControllableEntity, fire, this->getObjectID(), 1, 0);92 89 } 93 90 … … 244 241 void ControllableEntity::fire(unsigned int firemode) 245 242 { 246 COUT(0) << "fire........." << endl;247 243 if(GameMode::isMaster()) 248 244 {
Note: See TracChangeset
for help on using the changeset viewer.