Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 10, 2018, 3:06:55 PM (6 years ago)
Author:
merholzl
Message:

Merged Masterserver, refresh button had to be removed

Location:
code/branches/mergeFS18
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/mergeFS18

  • code/branches/mergeFS18/src/libraries/network/packet/Gamestate.cc

    r11083 r12027  
    4646#define GAMESTATE_START(data) (data + GamestateHeader::getSize())
    4747
    48 // #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
    4948#define PACKET_FLAG_GAMESTATE  0
    5049
     
    102101}
    103102
    104 
     103//AV: This takes all synchronisables and packs it in a GameState, to be sent over the network
    105104bool Gamestate::collectData(int id, uint8_t mode)
    106105{
     
    128127  for(it = ObjectList<Synchronisable>().begin(); it; ++it)
    129128  {
    130 
    131 //     tempsize=it->getSize(id, mode);
    132129
    133130    tempsize = it->getData(mem, this->sizes_, id, mode);
     
    173170}
    174171
    175 
     172//AV: This takes the Gamestate received from the network and "unpacks" it back to a list of Objects/Synchronisables, thus updating the data
    176173bool Gamestate::spreadData(uint8_t mode)
    177174{
     
    196193      else
    197194      {
    198 //         orxout(verbose, context::packets) << "not creating object of classid " << objectheader.getClassID() << endl;
    199195        mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() );
    200196      }
     
    202198    else
    203199    {
    204 //       orxout(verbose, context::packets) << "updating object of classid " << objectheader.getClassID() << endl;
    205200      OrxVerify(s->updateData(mem, mode), "ERROR: could not update Synchronisable with Gamestate data");
    206201    }
    207202  }
    208203  assert((uintptr_t)(mem-data_) == GamestateHeader::getSize()+header_.getDataSize());
    209  
    210    // In debug mode, check first, whether there are no duplicate objectIDs
    211 #ifndef NDEBUG
    212   if(this->getID()%1000==1)
    213   {
    214     std::list<uint32_t> v1;
    215     for (Synchronisable* synchronisable : ObjectList<Synchronisable>())
    216     {
    217       if (synchronisable->getObjectID() == OBJECTID_UNKNOWN)
    218       {
    219         if (synchronisable->objectMode_ != 0x0)
    220         {
    221           orxout(user_error, context::packets) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << endl;
    222           orxout(user_error, context::packets) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << endl;
    223           orxout(user_error, context::packets) << "Objects class: " << synchronisable->getIdentifier()->getName() << endl;
    224           assert(false);
    225         }
    226       }
    227       else
    228       {
    229         for (uint32_t id : v1)
    230         {
    231           if (synchronisable->getObjectID() == id)
    232           {
    233             orxout(user_error, context::packets) << "Found duplicate objectIDs on the client!" << endl
    234                                                  << "Are you sure you don't create a Sychnronisable objcect with 'new' \
    235                                                      that doesn't have objectMode = 0x0?" << endl;
    236             assert(false);
    237           }
    238         }
    239         v1.push_back(synchronisable->getObjectID());
    240       }
    241     }
    242   }
    243 #endif
    244204  return true;
    245205}
     
    276236}
    277237
    278 
     238//AV: This function takes the Gamestate and compresses it for transmission over the network
    279239bool Gamestate::compressData()
    280240{
     
    313273}
    314274
    315 
     275//AV: This function takes the compressed Gamestate received from the network and decompresses it for further unpacking
    316276bool Gamestate::decompressData()
    317277{
     
    374334  if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 )
    375335  {
    376 //     orxout(verbose, context::packets) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl;
    377336    origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object
    378337    baseDataPtr += objectOffset + objectHeader.getDataSize();
     
    430389inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
    431390{
    432   //       orxout(verbose, context::packets) << "docopy" << endl;
    433391  // Just copy over the whole Object
    434392  memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() );
     
    437395  newData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
    438396  origData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
    439 //   SynchronisableHeader baseHeader( baseData );
    440 //   baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize();
    441   //       orxout(verbose, context::packets) << "copy " << h.getObjectID() << endl;
    442   //       orxout(verbose, context::packets) << "copy " << h.getObjectID() << ":";
     397
    443398  sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
    444 //   for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i )
    445 //   {
    446 //     //         orxout(verbose, context::packets) << " " << *sizes;
    447 //     ++sizes;
    448 //   }
    449     //       orxout(verbose, context::packets) << endl;
     399
    450400}
    451401
     
    501451  uint8_t *origDataEnd = origDataPtr + header_.getDataSize();
    502452  uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize();
    503 //   uint32_t origLength = header_.getDataSize();
    504 //   uint32_t baseLength = base->header_.getDataSize();
     453
    505454
    506455  // Allocate new space for diffed gamestate
     
    595544
    596545
    597 /*Gamestate* Gamestate::diffData(Gamestate *base)
    598 {
    599   assert(this && base); assert(data_ && base->data_);
    600   assert(!header_.isCompressed() && !base->header_.isCompressed());
    601   assert(!header_.isDiffed());
    602 
    603   uint8_t *basep = GAMESTATE_START(base->data_);
    604   uint8_t *gs = GAMESTATE_START(this->data_);
    605   uint32_t dest_length = header_.getDataSize();
    606 
    607   if(dest_length==0)
    608     return nullptr;
    609 
    610   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    611   uint8_t *dest = GAMESTATE_START(ndata);
    612 
    613   rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );
    614 #ifndef NDEBUG
    615   uint8_t *dest2 = new uint8_t[dest_length];
    616   rawDiff( dest2, dest, basep, header_.getDataSize(), base->header_.getDataSize() );
    617   assert( memcmp( dest2, gs, dest_length) == 0 );
    618   delete dest2;
    619 #endif
    620 
    621   Gamestate *g = new Gamestate(ndata, getClientID());
    622   assert(g->header_);
    623   *(g->header_) = *header_;
    624   g->header_.setDiffed( true );
    625   g->header_.setBaseID( base->getID() );
    626   g->flags_=flags_;
    627   g->packetDirection_ = packetDirection_;
    628   assert(g->isDiffed());
    629   assert(!g->isCompressed());
    630   return g;
    631 }
    632 
    633 
    634 Gamestate* Gamestate::undiff(Gamestate *base)
    635 {
    636   assert(this && base); assert(data_ && base->data_);
    637   assert(!header_.isCompressed() && !base->header_.isCompressed());
    638   assert(header_.isDiffed());
    639 
    640   uint8_t *basep = GAMESTATE_START(base->data_);
    641   uint8_t *gs = GAMESTATE_START(this->data_);
    642   uint32_t dest_length = header_.getDataSize();
    643 
    644   if(dest_length==0)
    645     return nullptr;
    646 
    647   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    648   uint8_t *dest = ndata + GamestateHeader::getSize();
    649 
    650   rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() );
    651 
    652   Gamestate *g = new Gamestate(ndata, getClientID());
    653   assert(g->header_);
    654   *(g->header_) = *header_;
    655   g->header_.setDiffed( false );
    656   g->flags_=flags_;
    657   g->packetDirection_ = packetDirection_;
    658   assert(!g->isDiffed());
    659   assert(!g->isCompressed());
    660   return g;
    661 }
    662 
    663 
    664 void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)
    665 {
    666   uint64_t* gd = (uint64_t*)data;
    667   uint64_t* bd = (uint64_t*)basedata;
    668   uint64_t* nd = (uint64_t*)newdata;
    669 
    670   unsigned int i;
    671   for( i=0; i<datalength/8; i++ )
    672   {
    673     if( i<baselength/8 )
    674       *(nd+i) = *(gd+i) ^ *(bd+i);  // xor the data
    675     else
    676       *(nd+i) = *(gd+i); // just copy over the data
    677   }
    678   unsigned int j;
    679   // now process the rest (when datalength isn't a multiple of 4)
    680   for( j = 8*(datalength/8); j<datalength; j++ )
    681   {
    682     if( j<baselength )
    683       *(newdata+j) = *(data+j) ^ *(basedata+j); // xor
    684     else
    685       *(newdata+j) = *(data+j); // just copy
    686   }
    687   assert(j==datalength);
    688 }*/
    689 
    690 
    691 /*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    692   assert(data_);
    693   std::list<obj>::iterator it;
    694 
    695   // allocate memory for new data
    696   uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()];
    697   // create a gamestate out of it
    698   Gamestate *gs = new Gamestate(gdata);
    699   uint8_t *newdata = gdata + GamestateHeader::getSize();
    700   uint8_t *origdata = GAMESTATE_START(data_);
    701 
    702   //copy the GamestateHeader
    703   assert(gs->header_);
    704   *(gs->header_) = *header_;
    705 
    706   uint32_t objectOffset;
    707   unsigned int objectsize, destsize=0;
    708   // TODO: Why is this variable not used?
    709   //Synchronisable *object;
    710 
    711   //call TrafficControl
    712   TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ );
    713 
    714   //copy in the zeros
    715 //   std::list<obj>::iterator itt;
    716 //   orxout() << "myvector contains:";
    717 //   for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )
    718 //     orxout() << " " << (*itt).objID;
    719 //   orxout() << endl;
    720   for(it=dataVector_.begin(); it!=dataVector_.end();){
    721     SynchronisableHeader oldobjectheader(origdata);
    722     SynchronisableHeader newobjectheader(newdata);
    723     if ( (*it).objSize == 0 )
    724     {
    725       ++it;
    726       continue;
    727     }
    728     objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();
    729     objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader
    730     if ( (*it).objID == oldobjectheader.getObjectID() ){
    731       memcpy(newdata, origdata, objectsize);
    732       ++it;
    733     }else{
    734       newobjectheader = oldobjectheader;
    735       memset(newdata+objectOffset, 0, objectsize-objectOffset);
    736     }
    737     newdata += objectsize;
    738     origdata += objectsize;
    739     destsize += objectsize;
    740   }
    741 #ifndef NDEBUG
    742   uint32_t origsize = destsize;
    743   while ( origsize < header_.getDataSize() )
    744   {
    745     SynchronisableHeader oldobjectheader(origdata);
    746     objectsize = oldobjectheader.getDataSize()+SynchronisableHeader::getSize();
    747     origdata += objectsize;
    748     origsize += objectsize;
    749   }
    750   assert(origsize==header_.getDataSize());
    751   assert(destsize!=0);
    752 #endif
    753   gs->header_.setDataSize( destsize );
    754   return gs;
    755 }*/
    756 
    757 
    758546uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode)
    759547{
Note: See TracChangeset for help on using the changeset viewer.