Changeset 3120 for code/branches
- Timestamp:
- Jun 8, 2009, 4:03:44 PM (15 years ago)
- Location:
- code/branches/netp4/src/network
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp4/src/network/GamestateManager.cc
r3102 r3120 133 133 // COUT(3) << "diffing" << std::endl; 134 134 // packet::Gamestate* gs1 = gs; 135 gs = gs->diff(client); 135 packet::Gamestate *diffed = gs->diff(client); 136 //packet::Gamestate *gs2 = diffed->undiff(gs); 137 // assert(*gs == *gs2); 138 gs = diffed; 136 139 // packet::Gamestate* gs2 = gs->undiff(client); 137 140 // gs = new packet::Gamestate(*gs); -
code/branches/netp4/src/network/packet/Acknowledgement.cc
r2710 r3120 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/branches/netp4/src/network/packet/Gamestate.cc
r3084 r3120 138 138 header_->setDataSize( currentsize ); 139 139 header_->setID( id ); 140 header_->setBaseID( GAMESTATEID_INITIAL ); 140 141 header_->setDiffed( false ); 141 142 header_->setComplete( true ); … … 208 209 } 209 210 #endif 210 211 211 return true; 212 212 } … … 321 321 } 322 322 323 Gamestate *Gamestate::diff(Gamestate *base)323 /*Gamestate *Gamestate::diff(Gamestate *base) 324 324 { 325 325 assert(data_); … … 356 356 g->packetDirection_ = packetDirection_; 357 357 return g; 358 } 358 }*/ 359 360 Gamestate *Gamestate::diff(Gamestate *base) 361 { 362 assert(this && base); assert(data_ && base->data_); 363 assert(!header_->isCompressed() && !base->header_->isCompressed()); 364 assert(!header_->isDiffed()); 365 366 uint8_t *basep = GAMESTATE_START(base->data_); 367 uint8_t *gs = GAMESTATE_START(this->data_); 368 uint32_t dest_length = header_->getDataSize(); 369 370 if(dest_length==0) 371 return NULL; 372 373 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 374 uint8_t *dest = GAMESTATE_START(ndata); 375 376 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 377 #ifndef NDEBUG 378 uint8_t *dest2 = new uint8_t[dest_length]; 379 rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() ); 380 assert( memcmp( dest2, gs, dest_length) == 0 ); 381 #endif 382 383 Gamestate *g = new Gamestate(ndata, getClientID()); 384 assert(g->header_); 385 *(g->header_) = *header_; 386 g->header_->setDiffed( true ); 387 g->header_->setBaseID( base->getID() ); 388 g->flags_=flags_; 389 g->packetDirection_ = packetDirection_; 390 assert(g->isDiffed()); 391 assert(!g->isCompressed()); 392 return g; 393 } 394 395 Gamestate *Gamestate::undiff(Gamestate *base) 396 { 397 assert(this && base); assert(data_ && base->data_); 398 assert(!header_->isCompressed() && !base->header_->isCompressed()); 399 assert(header_->isDiffed()); 400 401 uint8_t *basep = GAMESTATE_START(base->data_); 402 uint8_t *gs = GAMESTATE_START(this->data_); 403 uint32_t dest_length = header_->getDataSize(); 404 405 if(dest_length==0) 406 return NULL; 407 408 uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()]; 409 uint8_t *dest = ndata + GamestateHeader::getSize(); 410 411 rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() ); 412 413 Gamestate *g = new Gamestate(ndata, getClientID()); 414 assert(g->header_); 415 *(g->header_) = *header_; 416 g->header_->setDiffed( false ); 417 g->flags_=flags_; 418 g->packetDirection_ = packetDirection_; 419 assert(!g->isDiffed()); 420 assert(!g->isCompressed()); 421 return g; 422 } 423 359 424 360 425 // Gamestate *Gamestate::diff(Gamestate *base) … … 410 475 // } 411 476 477 478 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength) 479 { 480 uint64_t* gd = (uint64_t*)data; 481 uint64_t* bd = (uint64_t*)basedata; 482 uint64_t* nd = (uint64_t*)newdata; 483 484 unsigned int i; 485 for( i=0; i<datalength/8; i++ ) 486 { 487 if( i<baselength/8 ) 488 *(nd+i) = *(gd+i) ^ *(bd+i); // xor the data 489 else 490 *(nd+i) = *(gd+i); // just copy over the data 491 } 492 unsigned int j; 493 // now process the rest (when datalength isn't a multiple of 4) 494 for( j = 8*(datalength/8); j<datalength; j++ ) 495 { 496 if( j<baselength ) 497 *(newdata+j) = *(data+j) ^ *(basedata+j); // xor 498 else 499 *(newdata+j) = *(data+j); // just copy 500 } 501 assert(j==datalength); 502 } 503 412 504 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 413 505 assert(data_); … … 479 571 480 572 481 Gamestate *Gamestate::undiff(Gamestate *base)573 /*Gamestate *Gamestate::undiff(Gamestate *base) 482 574 { 483 575 assert(this && base);assert(data_); … … 515 607 assert(!g->isCompressed()); 516 608 return g; 517 } 518 609 }*/ 519 610 520 611 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode) -
code/branches/netp4/src/network/packet/Gamestate.h
r3084 r3120 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.