Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2009, 10:38:06 PM (15 years ago)
Author:
scheusso
Message:

first approach of having client-side pong physics
some optimisations in TrafficControl

File:
1 edited

Legend:

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

    r3015 r3043  
    110110
    111111    tempsize = it->getData(mem, id, mode);
    112     if ( it->doSync( id, mode ) )
     112    if ( tempsize != 0 )
    113113      dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
    114114   
     
    339339  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    340340  uint8_t *dest = ndata + GamestateHeader::getSize();
    341   while(of < diffHeader.getDataSize() && of < header_->getDataSize()){
    342     *(dest+of)=*(basep+of)^*(gs+of); // do the xor
    343     ++of;
    344   }
    345   if(diffHeader.getDataSize()!=header_->getDataSize()){
    346     uint8_t n=0;
    347     if(diffHeader.getDataSize() < header_->getDataSize()){
    348       while(of<dest_length){
    349         *(dest+of)=n^*(gs+of);
    350         of++;
    351       }
    352     }
     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;
    353383  }
    354384
Note: See TracChangeset for help on using the changeset viewer.