Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 20, 2009, 4:27:38 PM (16 years ago)
Author:
scheusso
Message:

merged netp4 back to trunk

Location:
code/trunk/src/network/packet
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/packet/Acknowledgement.cc

    r2710 r3198  
    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/trunk/src/network/packet/Gamestate.cc

    r3196 r3198  
    7979Gamestate::~Gamestate()
    8080{
     81  if( header_ )
     82    delete header_;
    8183}
    8284
     
    98100 
    99101  // create the header object
     102  assert( header_ == 0 );
    100103  header_ = new GamestateHeader(data_);
    101104
     
    137140  header_->setDataSize( currentsize );
    138141  header_->setID( id );
     142  header_->setBaseID( GAMESTATEID_INITIAL );
    139143  header_->setDiffed( false );
    140144  header_->setComplete( true );
     
    207211  }
    208212#endif
    209 
    210213  return true;
    211214}
     
    320323}
    321324
    322 Gamestate *Gamestate::diff(Gamestate *base)
     325/*Gamestate *Gamestate::diff(Gamestate *base)
    323326{
    324327  assert(data_);
     
    355358  g->packetDirection_ = packetDirection_;
    356359  return g;
    357 }
     360}*/
     361
     362Gamestate *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
     397Gamestate *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
    358426
    359427// Gamestate *Gamestate::diff(Gamestate *base)
     
    409477// }
    410478
     479
     480void 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
    411506Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    412507  assert(data_);
     
    478573
    479574
    480 Gamestate *Gamestate::undiff(Gamestate *base)
     575/*Gamestate *Gamestate::undiff(Gamestate *base)
    481576{
    482577  assert(this && base);assert(data_);
     
    514609  assert(!g->isCompressed());
    515610  return g;
    516 }
    517 
     611}*/
    518612
    519613uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
  • code/trunk/src/network/packet/Gamestate.h

    r3084 r3198  
    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.