Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2655


Ignore:
Timestamp:
Feb 13, 2009, 6:41:08 PM (16 years ago)
Author:
scheusso
Message:

finally got rid of these structs in our network datastream
this means we should now be able to play with gcc and msvc compiled versions together

Location:
code/branches/presentation/src/network
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/network/GamestateClient.cc

    r2485 r2655  
    7777    int id = GAMESTATEID_INITIAL;
    7878    packet::Gamestate *processed = processGamestate(tempGamestate_);
    79 //    assert(processed);
     79    assert(processed);
    8080   
    8181    //now call the queued callbacks
     
    8383   
    8484    if (!processed){
    85       sendAck(0);
     85//      sendAck(0);
    8686      return false;
    8787    }
     
    9191    last_diff_ = processed->getID();
    9292    id = processed->getID();
    93     sendAck(id);
     93//     sendAck(id);
    9494    return true;
    9595  }
     
    160160      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
    161161      if(!base){
     162COUT(0) << "could not find base gamestate id: " << gs->getBaseID() << endl;
    162163        delete gs;
    163164        return 0;
     
    172173      return gs;
    173174    else
     175COUT(0) << "could not spread gamestate" << endl;
    174176      return NULL;
    175177  }
  • code/branches/presentation/src/network/GamestateManager.cc

    r2561 r2655  
    134134//       COUT(3) << "diffing" << std::endl;
    135135      gs = gs->diff(client);
     136//       gs = new packet::Gamestate(*gs);
    136137    }
    137138    else{
  • code/branches/presentation/src/network/packet/Gamestate.cc

    r2575 r2655  
    4444namespace packet {
    4545
     46#define GAMESTATE_START(data) (data + GamestateHeader::getSize())
    4647
    4748#define PACKET_FLAG_GAMESTATE  ENET_PACKET_FLAG_RELIABLE
    4849
     50// Gamestate::Gamestate()
     51// {
     52//   flags_ = flags_ | PACKET_FLAG_GAMESTATE;
     53// }
     54
    4955Gamestate::Gamestate()
    5056{
    5157  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
     58  header_ = 0;
    5259}
    5360
     
    5663{
    5764  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
     65  header_ = new GamestateHeader(data_);
    5866}
    5967
     
    6270  flags_ = flags_ | PACKET_FLAG_GAMESTATE;
    6371  data_=data;
     72  header_ = new GamestateHeader(data_);
    6473}
    6574
     
    7180bool Gamestate::collectData(int id, uint8_t mode)
    7281{
     82  assert(this->header_==0); // make sure the header didn't exist before
    7383  uint32_t tempsize=0, currentsize=0;
    7484  assert(data_==0);
     
    7888  if(size==0)
    7989    return false;
    80   data_ = new unsigned char[size + sizeof(GamestateHeader)];
     90  data_ = new uint8_t[size + GamestateHeader::getSize()];
    8191  if(!data_){
    8292    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
    8393    return false;
    8494  }
     95 
     96  // create the header object
     97  header_ = new GamestateHeader(data_);
    8598
    8699  //start collect data synchronisable by synchronisable
    87100  uint8_t *mem=data_;
    88   mem+=sizeof(GamestateHeader);
     101  mem += GamestateHeader::getSize();
    89102  ObjectList<Synchronisable>::iterator it;
    90103  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
     
    100113      while(++temp)
    101114        addsize+=temp->getSize(id, mode);
    102       data_ = (uint8_t *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
     115      data_ = (uint8_t *)realloc(data_, GamestateHeader::getSize() + currentsize + addsize);
    103116      if(!data_)
    104117        return false;
     
    119132
    120133  //start write gamestate header
    121   HEADER->packetType = ENUM::Gamestate;
    122   HEADER->datasize = currentsize;
    123   HEADER->id = id;
    124   HEADER->diffed = false;
    125   HEADER->complete = true;
    126   HEADER->compressed = false;
     134  header_->setDataSize( currentsize );
     135  header_->setID( id );
     136  header_->setDiffed( false );
     137  header_->setComplete( true );
     138  header_->setCompressed( false );
    127139  //stop write gamestate header
    128140
     
    135147{
    136148  assert(data_);
    137   assert(!HEADER->compressed);
    138   assert(!HEADER->diffed);
    139   uint8_t *mem=data_+sizeof(GamestateHeader);
     149  assert(!header_->isCompressed());
     150  assert(!header_->isDiffed());
     151  uint8_t *mem=data_+GamestateHeader::getSize();
    140152    // get the start of the Synchronisable list
    141153  //ObjectList<Synchronisable>::iterator it=ObjectList<Synchronisable>::begin();
     
    143155
    144156  // update the data of the objects we received
    145   while(mem < data_+sizeof(GamestateHeader)+HEADER->datasize){
    146     synchronisableHeader *objectheader = (synchronisableHeader*)mem;
    147 
    148     s = Synchronisable::getSynchronisable( objectheader->objectID );
     157  while(mem < data_+GamestateHeader::getSize()+header_->getDataSize()){
     158    SynchronisableHeader objectheader(mem);
     159
     160    s = Synchronisable::getSynchronisable( objectheader.getObjectID() );
    149161    if(!s)
    150162    {
    151163      if (!Core::isMaster())
     164      {
    152165        Synchronisable::fabricate(mem, mode);
     166      }
    153167      else
    154         mem += objectheader->size;
     168      {
     169        mem += objectheader.getDataSize();
     170      }
    155171//         COUT(0) << "could not fabricate synchronisable: " << objectheader->objectID << " classid: " << objectheader->classID << " creator: " << objectheader->creatorID << endl;
    156172//       else
     
    196212{
    197213  assert(data_);
    198   if(HEADER->compressed)
    199     return HEADER->compsize+sizeof(GamestateHeader);
     214  if(header_->isCompressed())
     215    return header_->getCompSize()+GamestateHeader::getSize();
    200216  else
    201217  {
    202     return HEADER->datasize+sizeof(GamestateHeader);
     218    return header_->getDataSize()+GamestateHeader::getSize();
    203219  }
    204220}
    205221
    206222bool Gamestate::operator==(packet::Gamestate gs){
    207   uint8_t *d1 = data_+sizeof(GamestateHeader);
    208   uint8_t *d2 = gs.data_+sizeof(GamestateHeader);
     223  uint8_t *d1 = data_+GamestateHeader::getSize();
     224  uint8_t *d2 = gs.data_+GamestateHeader::getSize();
    209225  assert(!isCompressed());
    210226  assert(!gs.isCompressed());
    211   while(d1<data_+HEADER->datasize)
     227  while(d1<data_+header_->getDataSize())
    212228  {
    213229    if(*d1!=*d2)
     
    228244bool Gamestate::compressData()
    229245{
    230   assert(HEADER);
    231   assert(!HEADER->compressed);
    232   uLongf buffer = (uLongf)(((HEADER->datasize + 12)*1.01)+1);
     246  assert(data_);
     247  assert(!header_->isCompressed());
     248  uLongf buffer = (uLongf)(((header_->getDataSize() + 12)*1.01)+1);
    233249  if(buffer==0)
    234250    return false;
    235251
    236   uint8_t *ndata = new uint8_t[buffer+sizeof(GamestateHeader)];
    237   uint8_t *dest = GAMESTATE_START(ndata);
     252  uint8_t *ndata = new uint8_t[buffer+GamestateHeader::getSize()];
     253  uint8_t *dest = ndata + GamestateHeader::getSize();
    238254  //unsigned char *dest = new unsigned char[buffer];
    239   uint8_t *source = GAMESTATE_START(data_);
     255  uint8_t *source = data_ + GamestateHeader::getSize();
    240256  int retval;
    241   retval = compress( dest, &buffer, source, (uLong)(HEADER->datasize) );
     257  retval = compress( dest, &buffer, source, (uLong)(header_->getDataSize()) );
    242258  switch ( retval ) {
    243259    case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
     
    248264
    249265  //copy and modify header
    250   *GAMESTATE_HEADER(ndata) = *HEADER;
     266  GamestateHeader *temp = header_;
     267  header_ = new GamestateHeader(ndata, temp);
     268  delete temp;
    251269  //delete old data
    252270  delete[] data_;
    253271  //save new data
    254272  data_ = ndata;
    255   HEADER->compsize = buffer;
    256   HEADER->compressed = true;
    257   assert(HEADER->compressed);
    258   COUT(4) << "gamestate compress datasize: " << HEADER->datasize << " compsize: " << HEADER->compsize << std::endl;
     273  header_->setCompSize( buffer );
     274  header_->setCompressed( true );
     275  COUT(5) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;
    259276  return true;
    260277}
    261278bool Gamestate::decompressData()
    262279{
    263   assert(HEADER);
    264   assert(HEADER->compressed);
    265   COUT(4) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl;
    266   uint32_t datasize = HEADER->datasize;
    267   uint32_t compsize = HEADER->compsize;
     280  assert(data_);
     281  assert(header_->isCompressed());
     282  COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_->getID() << ", baseid: " << header_->getBaseID() << ", datasize: " << header_->getDataSize() << ", compsize: " << header_->getCompSize() << std::endl;
     283  uint32_t datasize = header_->getDataSize();
     284  uint32_t compsize = header_->getCompSize();
    268285  uint32_t bufsize;
    269286//  assert(compsize<=datasize);
    270287  bufsize = datasize;
    271288  assert(bufsize!=0);
    272   uint8_t *ndata = new uint8_t[bufsize + sizeof(GamestateHeader)];
    273   uint8_t *dest = ndata + sizeof(GamestateHeader);
    274   uint8_t *source = data_ + sizeof(GamestateHeader);
     289  uint8_t *ndata = new uint8_t[bufsize + GamestateHeader::getSize()];
     290  uint8_t *dest = ndata + GamestateHeader::getSize();
     291  uint8_t *source = data_ + GamestateHeader::getSize();
    275292  int retval;
    276293  uLongf length=bufsize;
     
    284301
    285302  //copy over the header
    286   *GAMESTATE_HEADER(ndata) = *HEADER;
     303  GamestateHeader *temp = header_;
     304  header_ = new GamestateHeader( data_, header_ );
     305  delete temp;
    287306
    288307  if (this->bDataENetAllocated_){
     
    299318  //set new pointers
    300319  data_ = ndata;
    301   HEADER->compressed = false;
    302   assert(HEADER->datasize==datasize);
    303   assert(HEADER->compsize==compsize);
     320  header_->setCompressed( false );
     321  assert(header_->getDataSize()==datasize);
     322  assert(header_->getCompSize()==compsize);
    304323  return true;
    305324}
     
    307326Gamestate *Gamestate::diff(Gamestate *base)
    308327{
    309   assert(HEADER);
    310   assert(!HEADER->compressed);
    311   assert(!HEADER->diffed);
     328  assert(data_);
     329  assert(!header_->isCompressed());
     330  assert(!header_->isDiffed());
     331  GamestateHeader diffHeader(base->data_);
    312332  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    313333  uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
    314334  uint32_t of=0; // pointers offset
    315335  uint32_t dest_length=0;
    316   dest_length=HEADER->datasize;
     336  dest_length=header_->getDataSize();
    317337  if(dest_length==0)
    318338    return NULL;
    319   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)];
    320   uint8_t *dest = ndata + sizeof(GamestateHeader);
    321   while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){
     339  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     340  uint8_t *dest = ndata + GamestateHeader::getSize();
     341  while(of < diffHeader.getDataSize() && of < header_->getDataSize()){
    322342    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
    323343    ++of;
    324344  }
    325   if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
     345  if(diffHeader.getDataSize()!=header_->getDataSize()){
    326346    uint8_t n=0;
    327     if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
     347    if(diffHeader.getDataSize() < header_->getDataSize()){
    328348      while(of<dest_length){
    329349        *(dest+of)=n^*(gs+of);
     
    333353  }
    334354
    335   *GAMESTATE_HEADER(ndata) = *HEADER;
    336   GAMESTATE_HEADER(ndata)->diffed = true;
    337   GAMESTATE_HEADER(ndata)->base_id = base->getID();
    338355  Gamestate *g = new Gamestate(ndata, getClientID());
     356  *(g->header_) = *header_;
     357  g->header_->setDiffed( true );
     358  g->header_->setBaseID( base->getID() );
    339359  g->flags_=flags_;
    340360  g->packetDirection_ = packetDirection_;
     
    347367
    348368  // allocate memory for new data
    349   uint8_t *gdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)];
     369  uint8_t *gdata = new uint8_t[header_->getDataSize()+GamestateHeader::getSize()];
    350370  // create a gamestate out of it
    351371  Gamestate *gs = new Gamestate(gdata);
    352   uint8_t *newdata = gdata + sizeof(GamestateHeader);
     372  uint8_t *newdata = gdata + GamestateHeader::getSize();
    353373  uint8_t *origdata = GAMESTATE_START(data_);
    354374
    355375  //copy the GamestateHeader
    356   *(GamestateHeader*)gdata = *HEADER;
    357 
    358   synchronisableHeader *oldobjectheader, *newobjectheader;
     376  assert(gs->header_);
     377  *(gs->header_) = *header_;
     378
    359379  uint32_t objectOffset;
    360380  unsigned int objectsize, destsize=0;
     
    363383
    364384  //call TrafficControl
    365   TrafficControl::getInstance()->processObjectList( clientID, HEADER->id, &dataMap_ );
     385  TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), &dataMap_ );
    366386
    367387  //copy in the zeros
     
    371391//    if(it->second->getSize(HEADER->id)==0) // merged from objecthierarchy2, doesn't work anymore; TODO: change this
    372392//      continue;                            // merged from objecthierarchy2, doesn't work anymore; TODO: change this
    373     oldobjectheader = (synchronisableHeader*)origdata;
    374     newobjectheader = (synchronisableHeader*)newdata;
     393    SynchronisableHeader oldobjectheader(origdata);
     394    SynchronisableHeader newobjectheader(newdata);
    375395    if ( (*it).objSize == 0 )
    376396    {
     
    380400//     object = Synchronisable::getSynchronisable( (*it).objID );
    381401//     assert(object->objectID == oldobjectheader->objectID);
    382     objectsize = oldobjectheader->size;
    383     objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
    384     if ( (*it).objID == oldobjectheader->objectID ){
     402    objectsize = oldobjectheader.getDataSize();
     403    objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader
     404    if ( (*it).objID == oldobjectheader.getObjectID() ){
    385405      memcpy(newdata, origdata, objectsize);
    386       assert(newobjectheader->dataAvailable==true);
     406      assert(newobjectheader.isDataAvailable()==true);
    387407      ++it;
    388408    }else{
    389       *newobjectheader = *oldobjectheader;
    390       newobjectheader->dataAvailable=false;
     409      newobjectheader = oldobjectheader;
     410      newobjectheader.setDataAvailable(false);
    391411      memset(newdata+objectOffset, 0, objectsize-objectOffset);
    392412    }
     
    397417#ifndef NDEBUG
    398418  uint32_t origsize = destsize;
    399   while ( origsize < HEADER->datasize )
     419  while ( origsize < header_->getDataSize() )
    400420  {
    401     oldobjectheader = (synchronisableHeader*)origdata;
    402     objectsize = oldobjectheader->size;
     421    SynchronisableHeader oldobjectheader(origdata);
     422    objectsize = oldobjectheader.getDataSize();
    403423    origdata += objectsize;
    404424    origsize += objectsize;
    405425  }
    406   assert(origsize==HEADER->datasize);
     426  assert(origsize==header_->getDataSize());
    407427  assert(destsize!=0);
    408428#endif
    409   ((GamestateHeader*)gdata)->datasize = destsize;
     429  gs->header_->setDataSize( destsize );
    410430  return gs;
    411431}
     
    414434Gamestate *Gamestate::undiff(Gamestate *base)
    415435{
    416   assert(this && base);assert(HEADER);
    417   assert(HEADER->diffed);
    418   assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);
     436  assert(this && base);assert(data_);
     437  assert(header_->isDiffed());
     438  assert(!header_->isCompressed() && !base->header_->isCompressed());
    419439  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    420440  uint8_t *basep = GAMESTATE_START(base->data_);
     
    422442  uint32_t of=0; // pointers offset
    423443  uint32_t dest_length=0;
    424   dest_length=HEADER->datasize;
     444  dest_length=header_->getDataSize();
    425445  if(dest_length==0)
    426446    return NULL;
    427   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+sizeof(GamestateHeader)];
    428   uint8_t *dest = ndata + sizeof(GamestateHeader);
    429   while(of < GAMESTATE_HEADER(base->data_)->datasize && of < HEADER->datasize){
     447  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     448  uint8_t *dest = ndata + GamestateHeader::getSize();
     449  while(of < base->header_->getDataSize() && of < header_->getDataSize()){
    430450    *(dest+of)=*(basep+of)^*(gs+of); // do the xor
    431451    ++of;
    432452  }
    433   if(GAMESTATE_HEADER(base->data_)->datasize!=HEADER->datasize){
     453  if(base->header_->getDataSize()!=header_->getDataSize()){
    434454    uint8_t n=0;
    435     if(GAMESTATE_HEADER(base->data_)->datasize < HEADER->datasize){
     455    if(base->header_->getDataSize() < header_->getDataSize()){
    436456      while(of < dest_length){
    437457        *(dest+of)=n^*(gs+of);
     
    440460    }
    441461  }
    442   *GAMESTATE_HEADER(ndata) = *HEADER;
    443   GAMESTATE_HEADER(ndata)->diffed = false;
    444462  Gamestate *g = new Gamestate(ndata, getClientID());
     463  assert(g->header_);
     464  *(g->header_) = *header_;
     465  g->header_->setDiffed( false );
    445466  g->flags_=flags_;
    446467  g->packetDirection_ = packetDirection_;
     
    463484
    464485} //namespace packet
    465 
    466486} //namespace orxonox
  • code/branches/presentation/src/network/packet/Gamestate.h

    r2575 r2655  
    4646namespace packet {
    4747
    48 #define GAMESTATE_START(data) (data + sizeof(GamestateHeader))
    49 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
    50 #define HEADER GAMESTATE_HEADER(data_)
     48class _NetworkExport GamestateHeader{
     49  public:
     50    GamestateHeader(uint8_t *data){ data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; }
     51    GamestateHeader(uint8_t *data, GamestateHeader* h)
     52      { data_=data; memcpy(data_, h->data_, getSize()); }
     53    static inline uint32_t getSize()
     54      { return 21; }
    5155
    52 struct _NetworkExport GamestateHeader{
    53   ENUM::Type packetType;
    54   int32_t id; // id of the gamestate
    55   uint32_t compsize;
    56   uint32_t datasize;
    57   int32_t base_id; // id of the base-gamestate diffed from
    58   bool diffed:1; // wheter diffed or not
    59   bool complete:1; // wheter it is a complete gamestate or only partial
    60   bool compressed:1;
     56    inline int32_t getID() const
     57      { return *(int32_t*)(data_+4); }
     58    inline void setID(int32_t id)
     59      { *(int32_t*)(data_+4) = id; }
     60
     61    inline int32_t getBaseID() const
     62      { return *(int32_t*)(data_+8); }
     63    inline void setBaseID(int32_t id)
     64      { *(int32_t*)(data_+8) = id; }
     65
     66    inline uint32_t getDataSize() const
     67      { return *(uint32_t*)(data_+12); }
     68    inline void setDataSize(uint32_t size)
     69      { *(uint32_t*)(data_+12) = size; }
     70
     71    inline uint32_t getCompSize() const
     72      { return *(uint32_t*)(data_+16); }
     73    inline void setCompSize(uint32_t size)
     74      { *(uint32_t*)(data_+16) = size; }
     75
     76    inline bool isDiffed() const
     77      { return *(int8_t*)(data_+20) & 0x1; }
     78    inline void setDiffed(bool b)
     79      { *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }
     80
     81    inline bool isComplete() const
     82      { return *(int8_t*)(data_+20) & 0x2; }
     83    inline void setComplete(bool b)
     84      { *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }
     85
     86    inline bool isCompressed() const
     87      { return *(int8_t*)(data_+20) & 0x4; }
     88    inline void setCompressed(bool b)
     89      { *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }
     90
     91    inline void operator=(GamestateHeader& h)
     92      { memcpy( data_, h.data_, getSize()); }
     93  private:
     94    uint8_t *data_;
     95//#define GAMESTATE_START(data) (data + sizeof(GamestateHeader))
     96//#define GAMESTATE_HEADER(data) ((GamestateHeader *)data)
     97//#define HEADER GAMESTATE_HEADER(data_)
     98
    6199};
    62100
     
    74112    bool collectData(int id, uint8_t mode=0x0);
    75113    bool spreadData( uint8_t mode=0x0);
    76     inline int32_t getID() const { return HEADER->id; }
    77     inline bool isDiffed() const { return HEADER->diffed; }
    78     inline bool isCompressed() const { return HEADER->compressed; }
    79     inline int32_t getBaseID() const { return HEADER->base_id; }
     114    inline int32_t getID() const { return header_->getID(); }
     115    inline bool isDiffed() const { return header_->isDiffed(); }
     116    inline bool isCompressed() const { return header_->isCompressed(); }
     117    inline int32_t getBaseID() const { return header_->getBaseID(); }
    80118    Gamestate *diff(Gamestate *base);
    81119    Gamestate *undiff(Gamestate *base);
     
    93131    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    94132    std::list<obj> dataMap_;
     133    GamestateHeader* header_;
    95134};
    96135
  • code/branches/presentation/src/network/synchronisable/Synchronisable.cc

    r2575 r2655  
    2828 */
    2929
    30 //
    31 // C++ Implementation: synchronisable
    32 //
    33 // Description:
    34 //
    35 //
    36 // Author:  Dumeni, Oliver Scheuss, (C) 2007
    37 //
    38 // Copyright: See COPYING file that comes with this distribution
    39 //
    4030
    4131#include "Synchronisable.h"
     
    155145  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
    156146  {
    157     synchronisableHeader *header = (synchronisableHeader *)mem;
    158 
    159     if(!header->dataAvailable)
    160     {
    161       mem += header->size;
     147    SynchronisableHeader header(mem);
     148
     149    if(!header.isDataAvailable())
     150    {
     151      mem += header.getDataSize();
    162152      return 0;
    163153    }
    164154
    165     COUT(4) << "fabricating object with id: " << header->objectID << std::endl;
    166 
    167     Identifier* id = ClassByID(header->classID);
     155    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
     156
     157    Identifier* id = ClassByID(header.getClassID());
    168158    if (!id)
    169159    {
     
    174164    assert(id);
    175165    BaseObject* creator = 0;
    176     if (header->creatorID != OBJECTID_UNKNOWN)
    177     {
    178       Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header->creatorID);
     166    if (header.getCreatorID() != OBJECTID_UNKNOWN)
     167    {
     168      Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header.getCreatorID());
    179169      if (!synchronisable_creator)
    180170      {
    181         mem += header->size; //.TODO: this suckz.... remove size from header
    182 //         assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^
     171        mem += header.getDataSize(); //.TODO: this suckz.... remove size from header
     172        assert(0); // TODO: uncomment this if we have a clean objecthierarchy (with destruction of children of objects) ^^
    183173        return 0;
    184174      }
     
    186176        creator = dynamic_cast<BaseObject*>(synchronisable_creator);
    187177    }
    188     assert(getSynchronisable(header->objectID)==0);   //make sure no object with this id exists
     178    assert(getSynchronisable(header.getObjectID())==0);   //make sure no object with this id exists
    189179    BaseObject *bo = id->fabricate(creator);
    190180    assert(bo);
    191181    Synchronisable *no = dynamic_cast<Synchronisable *>(bo);
    192182    assert(no);
    193     no->objectID=header->objectID;
    194     no->creatorID=header->creatorID; //TODO: remove this
    195     no->classID=header->classID;
     183    no->objectID=header.getObjectID();
     184    no->creatorID=header.getCreatorID(); //TODO: remove this
     185    no->classID=header.getClassID();
    196186    COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
    197187          // update data and create object/entity...
     
    329319
    330320    // start copy header
    331     synchronisableHeader *header = (synchronisableHeader *)mem;
    332     header->size = size;
    333     header->objectID = this->objectID;
    334     header->creatorID = this->creatorID;
    335     header->classID = this->classID;
    336     header->dataAvailable = true;
    337     tempsize += sizeof(synchronisableHeader);
    338     mem += sizeof(synchronisableHeader);
     321    SynchronisableHeader header(mem);
     322    header.setDataSize( size );
     323    header.setObjectID( this->objectID );
     324    header.setCreatorID( this->creatorID );
     325    header.setClassID( this->classID );
     326    header.setDataAvailable( true );
     327    tempsize += SynchronisableHeader::getSize();
     328    mem += SynchronisableHeader::getSize();
    339329    // end copy header
    340330
     
    371361    uint8_t* data=mem;
    372362    // start extract header
    373     synchronisableHeader *syncHeader = (synchronisableHeader *)mem;
    374     assert(syncHeader->objectID==this->objectID);
    375     assert(syncHeader->creatorID==this->creatorID);
    376     assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
    377     if(syncHeader->dataAvailable==false){
    378       mem += syncHeader->size;
     363    SynchronisableHeader syncHeader(mem);
     364    assert(syncHeader.getObjectID()==this->objectID);
     365    assert(syncHeader.getCreatorID()==this->creatorID);
     366    assert(syncHeader.getClassID()==this->classID);
     367    if(syncHeader.isDataAvailable()==false){
     368      mem += syncHeader.getDataSize();
    379369      return true;
    380370    }
    381371
    382     mem += sizeof(synchronisableHeader);
     372    mem += SynchronisableHeader::getSize();
    383373    // stop extract header
    384374
    385     COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl;
    386     for(i=syncList.begin(); i!=syncList.end() && mem <= data+syncHeader->size; i++)
    387     {
     375    //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
     376    for(i=syncList.begin(); i!=syncList.end(); i++)
     377    {
     378      assert( mem <= data+syncHeader.getDataSize() ); // always make sure we don't exceed the datasize in our stream
    388379      (*i)->putData( mem, mode, forceCallback );
    389380    }
    390     assert(mem == data+syncHeader->size);
     381    assert(mem == data+syncHeader.getDataSize());
    391382    return true;
    392383  }
     
    399390  */
    400391  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    401     int tsize=sizeof(synchronisableHeader);
     392    int tsize=SynchronisableHeader::getSize();
    402393    if(mode==0x0)
    403394      mode=state_;
     
    428419  bool Synchronisable::isMyData(uint8_t* mem)
    429420  {
    430     synchronisableHeader *header = (synchronisableHeader *)mem;
    431     assert(header->objectID==this->objectID);
    432     return header->dataAvailable;
     421    SynchronisableHeader header(mem);
     422    assert(header.getObjectID()==this->objectID);
     423    return header.isDataAvailable();
    433424  }
    434425
  • code/branches/presentation/src/network/synchronisable/Synchronisable.h

    r2575 r2655  
    7272  }
    7373
    74   struct _NetworkExport synchronisableHeader{
    75     uint32_t size:31;
    76     bool dataAvailable:1;
    77     uint32_t objectID;
    78     uint32_t creatorID;
    79     uint32_t classID;
     74  /**
     75   * @brief: stores information about a Synchronisable
     76   *
     77   * This class stores the information about a Synchronisable (objectID, classID, creatorID, dataSize)
     78   * in an emulated bitset.
     79   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
     80   * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
     81   * Byte 5 to 8: objectID
     82   * Byte 9 to 12: classID
     83   * Byte 13 to 16: creatorID
     84   */
     85  class _NetworkExport SynchronisableHeader{
     86    private:
     87      uint8_t *data_;
     88    public:
     89      SynchronisableHeader(uint8_t* data)
     90        { data_ = data; }
     91      inline static uint32_t getSize()
     92        { return 16; }
     93      inline uint32_t getDataSize() const
     94        { return (*(uint32_t*)data_) & 0x7FFFFFFF; } //only use the first 31 bits
     95      inline void setDataSize(uint32_t size)
     96        { *(uint32_t*)(data_) = (size & 0x7FFFFFFF) | (*(uint32_t*)(data_) & 0x80000000 ); }
     97      inline bool isDataAvailable() const
     98        { return ( (*(uint32_t*)data_) & 0x80000000 ) == 0x80000000; }
     99      inline void setDataAvailable( bool b)
     100        { *(uint32_t*)(data_) = (b << 31) | (*(uint32_t*)(data_) & 0x7FFFFFFF ); }
     101      inline uint32_t getObjectID() const
     102        { return *(uint32_t*)(data_+4); }
     103      inline void setObjectID(uint32_t objectID)
     104        { *(uint32_t*)(data_+4) = objectID; }
     105      inline uint32_t getClassID() const
     106        { return *(uint32_t*)(data_+8); }
     107      inline void setClassID(uint32_t classID)
     108        { *(uint32_t*)(data_+8) = classID; }
     109      inline uint32_t getCreatorID() const
     110        { return *(uint32_t*)(data_+12); }
     111      inline void setCreatorID(uint32_t creatorID)
     112        { *(uint32_t*)(data_+12) = creatorID; }
     113      inline void operator=(SynchronisableHeader& h)
     114        { memcpy(data_, h.data_, getSize()); }
    80115  };
    81116
     
    83118  /**
    84119  * This class is the base class of all the Objects in the universe that need to be synchronised over the network
    85    * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
     120  * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
    86121  * @author Oliver Scheuss
    87122  */
Note: See TracChangeset for help on using the changeset viewer.