Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2009, 12:47:15 AM (16 years ago)
Author:
scheusso
Message:

had to revert some things in Gamestate::diff

Location:
code/branches/netp3/src/network
Files:
3 edited

Legend:

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

    r3045 r3047  
    132132    if(client){
    133133//       COUT(3) << "diffing" << std::endl;
     134//       packet::Gamestate* gs1  = gs;
    134135      gs = gs->diff(client);
     136//       packet::Gamestate* gs2 = gs->undiff(client);
    135137//       gs = new packet::Gamestate(*gs);
     138//       assert(*gs1==*gs2);
    136139    }
    137140    else{
     
    161164      for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
    162165        delete it->second;
     166
    163167        gamestateMap_[clientID].erase(it++);
    164168      }
  • code/branches/netp3/src/network/packet/Gamestate.cc

    r3045 r3047  
    226226  uint8_t *d1 = data_+GamestateHeader::getSize();
    227227  uint8_t *d2 = gs.data_+GamestateHeader::getSize();
     228  GamestateHeader* h1 = new GamestateHeader(data_);
     229  GamestateHeader* h2 = new GamestateHeader(gs.data_);
     230  assert(h1->getDataSize() == h2->getDataSize());
    228231  assert(!isCompressed());
    229232  assert(!gs.isCompressed());
    230   while(d1<data_+header_->getDataSize())
    231   {
    232     if(*d1!=*d2)
    233       return false;
    234     d1++;
    235     d2++;
    236   }
    237   return true;
     233  return memcmp(d1, d2, h1->getDataSize())==0;
    238234}
    239235
     
    339335  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    340336  uint8_t *dest = ndata + GamestateHeader::getSize();
    341  
    342  
    343   // LOOP-UNROLLED DIFFING
    344   uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
    345   // diff in 4-byte steps
    346   while( of < (uint32_t)(header_->getDataSize())/4 ){
    347     if( of < (uint32_t)(diffHeader.getDataSize())/4 )
    348     {
    349       *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
    350       ++of;
    351     } else
    352     {
    353       *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
    354       ++of;
    355     }
    356   }
    357   uint32_t base_rest = 0;
    358   // fill the base_rest first with 0 and then with the remaining bytes in base32
    359   switch( diffHeader.getDataSize()%sizeof(uint32_t) )
    360   {
    361     case 3:
    362       *((uint8_t*)(&base_rest)+2) = *((uint8_t*)(base32+of-1)+2); // save the last byte to the buffer
    363     case 2:
    364       *((uint16_t*)(&base_rest)) = *((uint16_t*)(base32+of-1)); // xor 2 bytes at once (either 2nd and 3rd last or the 2 last bytes)
    365       break;
    366     case 1:
    367       *((uint8_t*)(&base_rest)) = *((uint8_t*)(base32+of-1)); // xor the last byte
    368     case 0:
    369       break; // leave 0
    370   }
    371   // now diff the rest and save it to dest32 in 2- and 1-byte steps
    372   switch( header_->getDataSize()%sizeof(uint32_t) )
    373   {
    374     case 3:
    375       *((uint8_t*)(dest32+of)+2) = *((uint8_t*)&base_rest+2) ^ *((uint8_t*)(gs32+of-1)+2); // save the last byte to the buffer
    376     case 2:
    377       *((uint16_t*)(dest32+of)) = *((uint16_t*)&base_rest) ^ *((uint16_t*)(gs32+of-1)); // xor 2 bytes at once (either 2nd and 3rd last or the 2 last bytes)
    378       break;
    379     case 1:
    380       *((uint8_t*)(dest32+of)) = *((uint8_t*)&base_rest) ^ *((uint8_t*)(gs32+of-1)); // xor the last byte
    381     case 0:
    382       break;
     337  while(of < diffHeader.getDataSize() && of < header_->getDataSize()){
     338    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
     339    ++of;
     340  }
     341  if(diffHeader.getDataSize()!=header_->getDataSize()){
     342    uint8_t n=0;
     343    if(diffHeader.getDataSize() < header_->getDataSize()){
     344      while(of<dest_length){
     345        *(dest+of)=n^*(gs+of);
     346        of++;
     347      }
     348    }
    383349  }
    384350
     
    391357  return g;
    392358}
     359
     360// Gamestate *Gamestate::diff(Gamestate *base)
     361// {
     362//   assert(data_);
     363//   assert(!header_->isCompressed());
     364//   assert(!header_->isDiffed());
     365//   GamestateHeader diffHeader(base->data_);
     366//   uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
     367//   uint32_t of=0; // pointers offset
     368//   uint32_t dest_length=0;
     369//   dest_length=header_->getDataSize();
     370//   if(dest_length==0)
     371//     return NULL;
     372//   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     373//   uint8_t *dest = ndata + GamestateHeader::getSize();
     374//   
     375//   
     376//   // LOOP-UNROLLED DIFFING
     377//   uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
     378//   // diff in 4-byte steps
     379//   while( of < (uint32_t)(header_->getDataSize())/4 ){
     380//     if( of < (uint32_t)(diffHeader.getDataSize())/4 )
     381//     {
     382//       *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
     383//       ++of;
     384//     }
     385//     else
     386//     {
     387//       *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
     388//       ++of;
     389//     }
     390//   }
     391//   for( unsigned int of2 = 0; of2 < header_->getDataSize()%4; ++of2 )
     392//   {
     393//     if( of*4+of2 < diffHeader.getDataSize() )
     394//     {
     395//       *(dest+4*of+of2)=*(basep+4*of+of2) ^ *(gs+4*of+of2); // do the xor
     396//     }
     397//     else
     398//     {
     399//       *(dest+4*of+of2)=*(gs+4*of+of2); // same as 0 ^ *(gs32+of)
     400//     }
     401//   }
     402//
     403//   Gamestate *g = new Gamestate(ndata, getClientID());
     404//   *(g->header_) = *header_;
     405//   g->header_->setDiffed( true );
     406//   g->header_->setBaseID( base->getID() );
     407//   g->flags_=flags_;
     408//   g->packetDirection_ = packetDirection_;
     409//   return g;
     410// }
    393411
    394412Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
  • code/branches/netp3/src/network/packet/Gamestate.h

    r3045 r3047  
    120120    bool compressData();
    121121    bool decompressData();
     122    bool operator ==(packet::Gamestate gs);
    122123
    123124    // Packet functions
     
    126127    virtual inline bool process();
    127128
    128     bool operator ==(packet::Gamestate gs);
    129129  private:
    130130    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
Note: See TracChangeset for help on using the changeset viewer.