Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 8, 2008, 2:21:00 PM (16 years ago)
Author:
scheusso
Message:

compressing and diffing works now (also shipCache on client). server can't move while client connected. preparations for synchronise frequency of synchronisables

File:
1 edited

Legend:

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

    r1741 r1742  
    6262{
    6363  int tempsize=0, currentsize=0;
    64   assert(data_==0 /*&& bs_==0*/);
    65   int size = calcGamestateSize(mode);
     64  assert(data_==0);
     65  int size = calcGamestateSize(id, mode);
    6666 
    6767  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
    68     //retval->data = (unsigned char*)malloc(size);
    6968  if(size==0)
    7069    return false;
    7170  data_ = new unsigned char[size + sizeof(GamestateHeader)];
    72   //bs_ = new Bytestream(data_+sizeof(GamestateHeader), size);
    7371  if(!data_){
    7472    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
     
    8179  orxonox::Iterator<Synchronisable> it;
    8280  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
    83     tempsize=it->getSize2(mode);
     81    tempsize=it->getSize2(id, mode);
    8482   
    8583    if(currentsize+tempsize > size){
     
    8987      int addsize=tempsize;
    9088      while(++temp)
    91         addsize+=temp->getSize2(mode);
     89        addsize+=temp->getSize2(id, mode);
    9290      data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
    9391      if(!data_)
     
    9694    }// stop allocate additional memory
    9795
    98     if(!it->getData2(mem, mode))
     96    if(!it->getData(mem, id, mode))
    9997      return false; // mem pointer gets automatically increased because of call by reference
    10098    // increase size counter by size of current synchronisable
     
    199197{
    200198  assert(HEADER);
     199  assert(!HEADER->compressed);
    201200  uLongf buffer = (uLongf)(((HEADER->normsize + 12)*1.01)+1);
    202201  if(buffer==0)
     
    228227
    229228  //copy and modify header
     229#ifndef NDEBUG
     230  HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER->normsize);
     231#endif
    230232  *GAMESTATE_HEADER(ndata) = *HEADER;
    231233  //delete old data
     
    241243bool Gamestate::decompressData()
    242244{
     245  assert(HEADER);
    243246  assert(HEADER->compressed);
    244247  COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl;
     
    261264    case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false;
    262265  }
     266#ifndef NDEBUG
     267  assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER->normsize));
     268#endif
    263269 
    264270  //copy over the header
     
    276282Gamestate *Gamestate::diff(Gamestate *base)
    277283{
     284  assert(HEADER);
     285  assert(!HEADER->compressed);
     286  assert(!HEADER->diffed);
    278287  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    279288  unsigned char *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
     
    310319Gamestate *Gamestate::undiff(Gamestate *base)
    311320{
    312   assert(this && base);
     321  assert(this && base);assert(HEADER);
     322  assert(HEADER->diffed);
    313323  assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);
    314324  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
     
    346356
    347357
    348 unsigned int Gamestate::calcGamestateSize(int mode)
     358unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode)
    349359{
    350360  int size=0;
     
    353363    // get total size of gamestate
    354364  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it)
    355     size+=it->getSize2(mode); // size of the actual data of the synchronisable
     365    size+=it->getSize2(id, mode); // size of the actual data of the synchronisable
    356366//  size+=sizeof(GamestateHeader);
    357367  return size;
Note: See TracChangeset for help on using the changeset viewer.