Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 28, 2008, 9:11:02 PM (16 years ago)
Author:
landauf
Message:

some small adjustments in the network

File:
1 edited

Legend:

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

    r1990 r2031  
    4646#define HEADER GAMESTATE_HEADER(data_)
    4747
    48  
     48
    4949#define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
    50  
     50
    5151Gamestate::Gamestate()
    5252{
     
    8585    return false;
    8686  }
    87  
     87
    8888#ifndef NDEBUG
    8989  std::list<Synchronisable*> slist;
     
    115115    slist.push_back(*it);
    116116#endif
    117    
     117
    118118    //if(it->doSelection(id))
    119119    dataMap_[mem-data_]=(*it);  // save the mem location of the synchronisable data
     
    165165    {
    166166      bool b = s->updateData(mem, mode);
    167       assert(b);
     167//      assert(b);
    168168      //if(!s->updateData(mem, mode))
    169169        //return false;
     
    339339  assert(data_);
    340340  std::map<unsigned int, Synchronisable *>::iterator it;
    341  
     341
    342342  // allocate memory for new data
    343343  uint8_t *gdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)];
     
    346346  uint8_t *newdata = gdata + sizeof(GamestateHeader);
    347347  uint8_t *origdata = GAMESTATE_START(data_);
    348  
     348
    349349  //copy the GamestateHeader
    350350  *(GamestateHeader*)gdata = *HEADER;
    351  
     351
    352352  synchronisableHeader *oldobjectheader, *newobjectheader;
    353353  unsigned int objectOffset;
    354  
     354
    355355  //copy in the zeros
    356356  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
     
    390390  assert(!HEADER->compressed);
    391391  assert(!HEADER->diffed);
    392  
     392
    393393  //preparations
    394394  std::map<unsigned int, Synchronisable *>::iterator it;
    395395  uint8_t *origdata, *basedata, *destdata, *ndata;
    396396  unsigned int objectOffset, streamOffset=0;    //data offset
    397   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 
     397  unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    398398  synchronisableHeader *origheader;
    399399  synchronisableHeader *destheader;
    400  
     400
    401401  origdata = GAMESTATE_START(this->data_);
    402402  basedata = GAMESTATE_START(base->data_);
    403403  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
    404404  destdata = ndata + sizeof(GamestateHeader);
    405  
     405
    406406  // do the diff
    407407  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
     
    410410    origheader = (synchronisableHeader *)(origdata+streamOffset);
    411411    destheader = (synchronisableHeader *)(destdata+streamOffset);
    412    
     412
    413413    //copy and partially diff the object header
    414414    assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
     
    420420    }else{
    421421      *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0;
    422       *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 
     422      *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0;
    423423    }
    424424    objectOffset=sizeof(synchronisableHeader);
    425425    streamOffset+=sizeof(synchronisableHeader);
    426    
     426
    427427    //now handle the object data or fill with zeros
    428428    while(objectOffset<origheader->size ){
    429      
     429
    430430      if(sendData && streamOffset<minsize)
    431431        *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor
     
    434434      else
    435435        *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered
    436      
     436
    437437      objectOffset++;
    438438      streamOffset++;
     
    442442    basedata+=objectOffset;
    443443  }
    444  
     444
    445445  //copy over the gamestate header and set the diffed flag
    446446  *(GamestateHeader *)ndata = *HEADER; //copy over the header
     
    458458  assert(!HEADER->compressed);
    459459  assert(HEADER->diffed);
    460  
     460
    461461  //preparations
    462462  std::map<unsigned int, Synchronisable *>::iterator it;
    463463  uint8_t *origdata, *basedata, *destdata, *ndata;
    464464  unsigned int objectOffset, streamOffset=0;    //data offset
    465   unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 
     465  unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize;
    466466  synchronisableHeader *origheader;
    467467  synchronisableHeader *destheader;
    468  
     468
    469469  origdata = GAMESTATE_START(this->data_);
    470470  basedata = GAMESTATE_START(base->data_);
    471471  ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)];
    472472  destdata = ndata + sizeof(GamestateHeader);
    473  
     473
    474474  // do the undiff
    475475  for(it=dataMap_.begin(); it!=dataMap_.end(); it++){
     
    478478    destheader = (synchronisableHeader *)(destdata+streamOffset);
    479479    bool sendData;
    480    
     480
    481481    //copy and partially diff the object header
    482482    assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool));
     
    489489    }else{
    490490      *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0;
    491       *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0; 
     491      *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0;
    492492    }
    493493    objectOffset=sizeof(synchronisableHeader);
    494494    streamOffset+=sizeof(synchronisableHeader);
    495    
     495
    496496    //now handle the object data or fill with zeros
    497497    while(objectOffset<origheader->size ){
    498      
     498
    499499      if(sendData && streamOffset<minsize)
    500500        *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor
     
    503503      else
    504504        *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered
    505      
     505
    506506      objectOffset++;
    507507      streamOffset++;
     
    511511    basedata+=objectOffset;
    512512  }
    513  
     513
    514514  //copy over the gamestate header and set the diffed flag
    515515  *(GamestateHeader *)ndata = *HEADER; //copy over the header
Note: See TracChangeset for help on using the changeset viewer.