Changeset 3198 for code/trunk/src/network/packet
- Timestamp:
- Jun 20, 2009, 4:27:38 PM (16 years ago)
- Location:
- code/trunk/src/network/packet
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/packet/Acknowledgement.cc
r2710 r3198 64 64 65 65 bool Acknowledgement::process(){ 66 COUT(6) << "processing ACK with ID: " << getAckID() << endl;66 COUT(5) << "processing ACK with ID: " << getAckID() << endl; 67 67 bool b = GamestateHandler::ackGamestate(getAckID(), clientID_); 68 68 delete this; -
code/trunk/src/network/packet/Gamestate.cc
r3196 r3198 79 79 Gamestate::~Gamestate() 80 80 { 81 if( header_ ) 82 delete header_; 81 83 } 82 84 … … 98 100 99 101 // create the header object 102 assert( header_ == 0 ); 100 103 header_ = new GamestateHeader(data_); 101 104 … … 137 140 header_->setDataSize( currentsize ); 138 141 header_->setID( id ); 142 header_->setBaseID( GAMESTATEID_INITIAL ); 139 143 header_->setDiffed( false ); 140 144 header_->setComplete( true ); … … 207 211 } 208 212 #endif 209 210 213 return true; 211 214 } … … 320 323 } 321 324 322 Gamestate *Gamestate::diff(Gamestate *base)325 /*Gamestate *Gamestate::diff(Gamestate *base) 323 326 { 324 327 assert(data_); … … 355 358 g->packetDirection_ = packetDirection_; 356 359 return g; 357 } 360 }*/ 361 362 Gamestate *Gamestate::diff(Gamestate *base) 363 { 364 assert(this && base); assert(data_ && base->data_); 365 assert(!header_->isCompressed() && !base->header_->isCompressed()); 366 assert(!header_->isDiffed()); 367 368 uint8_t *basep = GAMESTATE_START(base->data_); 369 uint8_t *gs = GAMESTATE_START(this->data_); 370 uint32_t dest_length = header_->getDataSize(); 371 372 if(dest_length==0) 373 return NULL; 374 375 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 376 uint8_t *dest = GAMESTATE_START(ndata); 377 378 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 379 #ifndef NDEBUG 380 uint8_t *dest2 = new uint8_t[dest_length]; 381 rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() ); 382 assert( memcmp( dest2, gs, dest_length) == 0 ); 383 #endif 384 385 Gamestate *g = new Gamestate(ndata, getClientID()); 386 assert(g->header_); 387 *(g->header_) = *header_; 388 g->header_->setDiffed( true ); 389 g->header_->setBaseID( base->getID() ); 390 g->flags_=flags_; 391 g->packetDirection_ = packetDirection_; 392 assert(g->isDiffed()); 393 assert(!g->isCompressed()); 394 return g; 395 } 396 397 Gamestate *Gamestate::undiff(Gamestate *base) 398 { 399 assert(this && base); assert(data_ && base->data_); 400 assert(!header_->isCompressed() && !base->header_->isCompressed()); 401 assert(header_->isDiffed()); 402 403 uint8_t *basep = GAMESTATE_START(base->data_); 404 uint8_t *gs = GAMESTATE_START(this->data_); 405 uint32_t dest_length = header_->getDataSize(); 406 407 if(dest_length==0) 408 return NULL; 409 410 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 411 uint8_t *dest = ndata + GamestateHeader::getSize(); 412 413 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 414 415 Gamestate *g = new Gamestate(ndata, getClientID()); 416 assert(g->header_); 417 *(g->header_) = *header_; 418 g->header_->setDiffed( false ); 419 g->flags_=flags_; 420 g->packetDirection_ = packetDirection_; 421 assert(!g->isDiffed()); 422 assert(!g->isCompressed()); 423 return g; 424 } 425 358 426 359 427 // Gamestate *Gamestate::diff(Gamestate *base) … … 409 477 // } 410 478 479 480 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength) 481 { 482 uint64_t* gd = (uint64_t*)data; 483 uint64_t* bd = (uint64_t*)basedata; 484 uint64_t* nd = (uint64_t*)newdata; 485 486 unsigned int i; 487 for( i=0; i<datalength/8; i++ ) 488 { 489 if( i<baselength/8 ) 490 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data 491 else 492 *(nd+i) = *(gd+i); // just copy over the data 493 } 494 unsigned int j; 495 // now process the rest (when datalength isn't a multiple of 4) 496 for( j = 8*(datalength/8); j<datalength; j++ ) 497 { 498 if( j<baselength ) 499 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor 500 else 501 *(newdata+j) = *(data+j); // just copy 502 } 503 assert(j==datalength); 504 } 505 411 506 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 412 507 assert(data_); … … 478 573 479 574 480 Gamestate *Gamestate::undiff(Gamestate *base)575 /*Gamestate *Gamestate::undiff(Gamestate *base) 481 576 { 482 577 assert(this && base);assert(data_); … … 514 609 assert(!g->isCompressed()); 515 610 return g; 516 } 517 611 }*/ 518 612 519 613 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode) -
code/trunk/src/network/packet/Gamestate.h
r3084 r3198 124 124 // Packet functions 125 125 private: 126 void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 126 127 virtual uint32_t getSize() const; 127 128 virtual inline bool process();
Note: See TracChangeset
for help on using the changeset viewer.