Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3120 for code/branches


Ignore:
Timestamp:
Jun 8, 2009, 4:03:44 PM (15 years ago)
Author:
scheusso
Message:

optimised diff function (unrolled to 8byte xor)

Location:
code/branches/netp4/src/network
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp4/src/network/GamestateManager.cc

    r3102 r3120  
    133133//       COUT(3) << "diffing" << std::endl;
    134134//       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;
    136139//       packet::Gamestate* gs2 = gs->undiff(client);
    137140//       gs = new packet::Gamestate(*gs);
  • code/branches/netp4/src/network/packet/Acknowledgement.cc

    r2710 r3120  
    6464
    6565bool Acknowledgement::process(){
    66 COUT(6) << "processing ACK with ID: " << getAckID() << endl;
     66  COUT(5) << "processing ACK with ID: " << getAckID() << endl;
    6767  bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
    6868  delete this;
  • code/branches/netp4/src/network/packet/Gamestate.cc

    r3084 r3120  
    138138  header_->setDataSize( currentsize );
    139139  header_->setID( id );
     140  header_->setBaseID( GAMESTATEID_INITIAL );
    140141  header_->setDiffed( false );
    141142  header_->setComplete( true );
     
    208209  }
    209210#endif
    210 
    211211  return true;
    212212}
     
    321321}
    322322
    323 Gamestate *Gamestate::diff(Gamestate *base)
     323/*Gamestate *Gamestate::diff(Gamestate *base)
    324324{
    325325  assert(data_);
     
    356356  g->packetDirection_ = packetDirection_;
    357357  return g;
    358 }
     358}*/
     359
     360Gamestate *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
     395Gamestate *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
    359424
    360425// Gamestate *Gamestate::diff(Gamestate *base)
     
    410475// }
    411476
     477
     478void 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
    412504Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    413505  assert(data_);
     
    479571
    480572
    481 Gamestate *Gamestate::undiff(Gamestate *base)
     573/*Gamestate *Gamestate::undiff(Gamestate *base)
    482574{
    483575  assert(this && base);assert(data_);
     
    515607  assert(!g->isCompressed());
    516608  return g;
    517 }
    518 
     609}*/
    519610
    520611uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
  • code/branches/netp4/src/network/packet/Gamestate.h

    r3084 r3120  
    124124    // Packet functions
    125125  private:
     126    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
    126127    virtual uint32_t getSize() const;
    127128    virtual inline bool process();
Note: See TracChangeset for help on using the changeset viewer.