Changeset 6450 for code/branches/network2/src/libraries/network/packet
- Timestamp:
- Jan 18, 2010, 12:05:57 AM (15 years ago)
- Location:
- code/branches/network2/src/libraries/network/packet
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network2/src/libraries/network/packet/Gamestate.cc
r6449 r6450 181 181 assert(!header_->isCompressed()); 182 182 uint8_t *mem=data_+GamestateHeader::getSize(); 183 bool diffed = header_->isDiffed();184 183 Synchronisable *s; 185 184 … … 194 193 if (!GameMode::isMaster()) 195 194 { 196 Synchronisable::fabricate(mem, diffed,mode);195 Synchronisable::fabricate(mem, mode); 197 196 } 198 197 else 199 198 { 200 mem += objectheader.getDataSize() +SynchronisableHeader::getSize();199 mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() ); 201 200 } 202 201 } … … 365 364 366 365 367 Gamestate *Gamestate::diff(Gamestate *base)366 Gamestate* Gamestate::diffVariables(Gamestate *base) 368 367 { 369 368 assert(this && base); assert(data_ && base->data_); … … 381 380 assert( origLength && baseLength ); 382 381 383 COUT(0) << "newSize: " << origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_ << endl;384 382 uint8_t *nData = new uint8_t[origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_]; // this is the maximum size needed in the worst case 385 383 uint8_t *dest = GAMESTATE_START(nData); … … 448 446 // COUT(4) << "diff " << h.getObjectID() << ":"; 449 447 // Now start to diff the Object 450 SynchronisableHeader h2(dest);448 SynchronisableHeaderLight h2(dest); 451 449 h2 = h; // copy over the objectheader 452 uint32_tvariableID = 0;453 uint32_t newObjectOffset = SynchronisableHeader ::getSize();450 VariableID variableID = 0; 451 uint32_t newObjectOffset = SynchronisableHeaderLight::getSize(); 454 452 // iterate through all variables 455 453 while( objectOffset < h.getDataSize()+SynchronisableHeader::getSize() ) … … 465 463 { 466 464 // COUT(4) << " c" << varSize; 467 *( uint32_t*)(dest+newObjectOffset) = variableID; // copy over the variableID468 newObjectOffset += sizeof( uint32_t);465 *(VariableID*)(dest+newObjectOffset) = variableID; // copy over the variableID 466 newObjectOffset += sizeof(VariableID); 469 467 memcpy( dest+newObjectOffset, origData+origOffset+objectOffset, varSize ); 470 468 newObjectOffset += varSize; … … 485 483 // COUT(4) << endl; 486 484 h2.setDiffed(true); 487 h2.setDataSize(newObjectOffset-SynchronisableHeader ::getSize());485 h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize()); 488 486 assert(objectOffset == h.getDataSize()+SynchronisableHeader::getSize()); 489 487 origOffset += objectOffset; … … 520 518 assert(g->header_); 521 519 *(g->header_) = *header_; 520 g->header_->setBaseID( base->getID() ); 521 g->header_->setDataSize(dest - nData - GamestateHeader::getSize()); 522 g->flags_=flags_; 523 g->packetDirection_ = packetDirection_; 524 assert(!g->isCompressed()); 525 return g; 526 } 527 528 529 Gamestate* Gamestate::diffData(Gamestate *base) 530 { 531 assert(this && base); assert(data_ && base->data_); 532 assert(!header_->isCompressed() && !base->header_->isCompressed()); 533 assert(!header_->isDiffed()); 534 535 uint8_t *basep = GAMESTATE_START(base->data_); 536 uint8_t *gs = GAMESTATE_START(this->data_); 537 uint32_t dest_length = header_->getDataSize(); 538 539 if(dest_length==0) 540 return NULL; 541 542 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 543 uint8_t *dest = GAMESTATE_START(ndata); 544 545 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 546 #ifndef NDEBUG 547 uint8_t *dest2 = new uint8_t[dest_length]; 548 rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() ); 549 assert( memcmp( dest2, gs, dest_length) == 0 ); 550 delete dest2; 551 #endif 552 553 Gamestate *g = new Gamestate(ndata, getClientID()); 554 assert(g->header_); 555 *(g->header_) = *header_; 522 556 g->header_->setDiffed( true ); 523 557 g->header_->setBaseID( base->getID() ); 524 g->header_->setDataSize(dest - nData - GamestateHeader::getSize());525 558 g->flags_=flags_; 526 559 g->packetDirection_ = packetDirection_; … … 528 561 assert(!g->isCompressed()); 529 562 return g; 563 } 564 565 566 Gamestate* Gamestate::undiff(Gamestate *base) 567 { 568 assert(this && base); assert(data_ && base->data_); 569 assert(!header_->isCompressed() && !base->header_->isCompressed()); 570 assert(header_->isDiffed()); 571 572 uint8_t *basep = GAMESTATE_START(base->data_); 573 uint8_t *gs = GAMESTATE_START(this->data_); 574 uint32_t dest_length = header_->getDataSize(); 575 576 if(dest_length==0) 577 return NULL; 578 579 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 580 uint8_t *dest = ndata + GamestateHeader::getSize(); 581 582 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 583 584 Gamestate *g = new Gamestate(ndata, getClientID()); 585 assert(g->header_); 586 *(g->header_) = *header_; 587 g->header_->setDiffed( false ); 588 g->flags_=flags_; 589 g->packetDirection_ = packetDirection_; 590 assert(!g->isDiffed()); 591 assert(!g->isCompressed()); 592 return g; 593 } 594 595 596 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength) 597 { 598 uint64_t* gd = (uint64_t*)data; 599 uint64_t* bd = (uint64_t*)basedata; 600 uint64_t* nd = (uint64_t*)newdata; 601 602 unsigned int i; 603 for( i=0; i<datalength/8; i++ ) 604 { 605 if( i<baselength/8 ) 606 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data 607 else 608 *(nd+i) = *(gd+i); // just copy over the data 609 } 610 unsigned int j; 611 // now process the rest (when datalength isn't a multiple of 4) 612 for( j = 8*(datalength/8); j<datalength; j++ ) 613 { 614 if( j<baselength ) 615 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor 616 else 617 *(newdata+j) = *(data+j); // just copy 618 } 619 assert(j==datalength); 530 620 } 531 621 -
code/branches/network2/src/libraries/network/packet/Gamestate.h
r6449 r6450 115 115 inline int32_t getBaseID() const { return header_->getBaseID(); } 116 116 inline uint32_t getDataSize() const { return header_->getDataSize(); } 117 Gamestate *diff(Gamestate *base); 117 Gamestate* diffVariables(Gamestate *base); 118 Gamestate* diffData(Gamestate *base); 119 Gamestate *undiff(Gamestate *base); 118 120 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 119 121 bool compressData(); -
code/branches/network2/src/libraries/network/packet/Packet.cc
r6417 r6450 69 69 enetPacket_=0; 70 70 bDataENetAllocated_ = false; 71 }72 73 void blub(ENetPacket *packet){74 COUT(4) << "blubb" << std::endl;75 71 } 76 72
Note: See TracChangeset
for help on using the changeset viewer.