Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 28, 2010, 10:10:56 PM (14 years ago)
Author:
scheusso
Message:

merging network3 into network4 branch

Location:
code/branches/network4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network4

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

    r7163 r7497  
    4343#define GAMESTATE_START(data) (data + GamestateHeader::getSize())
    4444
    45 #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
     45#define PACKET_FLAG_GAMESTATE  0 //PacketFlag::Reliable
    4646
    4747inline bool memzero( uint8_t* data, uint32_t datalength)
     
    364364
    365365
     366inline void /*Gamestate::*/diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
     367{
     368  //       COUT(4) << "dodiff" << endl;
     369  //       if(baseOffset==0)
     370  //       {
     371  //         assert(origOffset==0);
     372  //       }
     373  uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData
     374  // Check whether the whole object stayed the same
     375  if( memcmp( origData+objectOffset, baseData+objectOffset, objectHeader.getDataSize()) == 0 )
     376  {
     377    //         COUT(4) << "skip object" << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
     378    origData += objectOffset + objectHeader.getDataSize(); // skip the whole object
     379    baseData += objectOffset + objectHeader.getDataSize();
     380    sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
     381  }
     382  else
     383  {
     384    //         if( Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() == "Bot" )
     385    //           COUT(0) << "blub" << endl;
     386    //         COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
     387    //         COUT(4) << "diff " << h.getObjectID() << ":";
     388    // Now start to diff the Object
     389    SynchronisableHeaderLight h2(newData);
     390    h2 = objectHeader; // copy over the objectheader
     391    VariableID variableID = 0;
     392    uint32_t newObjectOffset = SynchronisableHeaderLight::getSize();
     393    // iterate through all variables
     394    while( objectOffset < objectHeader.getDataSize()+SynchronisableHeader::getSize() )
     395    {
     396      // check whether variable changed and write id and copy over variable to the new stream
     397      // otherwise skip variable
     398//       assert(sizes != this->sizes_.end());
     399      uint32_t varSize = *sizes;
     400      assert( varSize == Synchronisable::getSynchronisable(objectHeader.getObjectID())->getVarSize(variableID) );
     401      if ( varSize != 0 )
     402      {
     403        if ( memcmp(origData+objectOffset, baseData+objectOffset, varSize) != 0 )
     404        {
     405          //               COUT(4) << "copy variable" << endl;
     406          *(VariableID*)(newData+newObjectOffset) = variableID; // copy over the variableID
     407          newObjectOffset += sizeof(VariableID);
     408          memcpy( newData+newObjectOffset, origData+objectOffset, varSize );
     409          newObjectOffset += varSize;
     410          objectOffset += varSize;
     411        }
     412        else
     413        {
     414          //               COUT(4) << "skip variable" << endl;
     415          objectOffset += varSize;
     416        }
     417      }
     418//           else
     419//             COUT(4) << "varsize 0" << endl;
     420
     421      ++variableID;
     422      ++sizes;
     423    }
     424           
     425    if( Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() != variableID )
     426      sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() - variableID;
     427    //         COUT(4) << endl;
     428   
     429    h2.setDiffed(true);
     430    h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize());
     431    assert(objectOffset == objectHeader.getDataSize()+SynchronisableHeader::getSize());
     432    assert(h2.getDataSize()>0);
     433    origData += objectOffset;
     434    //         baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
     435    //baseOffset += objectOffset;
     436    //         SynchronisableHeader htemp(temp);
     437    //         baseOffset += SynchronisableHeader::getSize() + htemp.getDataSize();
     438    //         {
     439      //           SynchronisableHeader htemp2( baseData+(temp-baseData+objectOffset) );
     440    //           if( baseData+(temp-baseData+objectOffset) < baseData+baseLength )
     441    //           {
     442      //             assert(htemp2.getClassID()<500);
     443    //             assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
     444    //             assert(htemp2.isDiffed()==false);
     445    //           }
     446    //         }
     447    baseData += objectOffset;
     448    newData += newObjectOffset;
     449  }
     450}
     451
     452inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
     453{
     454  //       COUT(4) << "docopy" << endl;
     455  // Just copy over the whole Object
     456  memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() );
     457  newData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
     458  origData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
     459  SynchronisableHeader baseHeader( baseData );
     460  baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize();
     461  //       COUT(4) << "copy " << h.getObjectID() << endl;
     462  //       COUT(4) << "copy " << h.getObjectID() << ":";
     463  sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables();
     464//   for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i )
     465//   {
     466//     //         COUT(4) << " " << *sizes;
     467//     ++sizes;
     468//   }
     469    //       COUT(4) << endl;
     470}
     471
    366472Gamestate* Gamestate::diffVariables(Gamestate *base)
    367473{
     
    375481  uint8_t *baseData = GAMESTATE_START(base->data_);
    376482  uint8_t *origData = GAMESTATE_START(this->data_);
    377   uint32_t origLength = header_->getDataSize();
    378   uint32_t baseLength = base->header_->getDataSize();
    379 
    380   assert( origLength && baseLength );
    381 
    382   uint8_t *nData = new uint8_t[origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_]; // this is the maximum size needed in the worst case
    383   uint8_t *dest = GAMESTATE_START(nData);
    384 
    385   uint32_t baseOffset = 0; //offset in the diffed stream
    386   uint32_t origOffset = 0; //offset in the new stream with removed 0's
     483  uint8_t *origDataEnd = origData + header_->getDataSize();
     484  uint8_t *baseDataEnd = baseData + base->header_->getDataSize();
     485//   uint32_t origLength = header_->getDataSize();
     486//   uint32_t baseLength = base->header_->getDataSize();
     487
     488  assert( header_->getDataSize() && base->header_->getDataSize() );
     489 
     490  uint32_t newDataSize = header_->getDataSize() + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_;
     491  uint8_t *newData = new uint8_t[newDataSize]; // this is the maximum size needed in the worst case
     492  uint8_t *dest = GAMESTATE_START(newData);
     493
     494//   uint32_t baseOffset = 0; //offset in the diffed stream
     495//   uint32_t origOffset = 0; //offset in the new stream with removed 0's
    387496  std::vector<uint32_t>::iterator sizes = this->sizes_.begin();
    388497
    389   while( origOffset < origLength )
     498  while( origData < origDataEnd )
    390499  {
    391500    //iterate through all objects
    392501
    393     SynchronisableHeader h(origData+origOffset);
     502    SynchronisableHeader h(origData);
    394503
    395504    // Find (if possible) the current object in the datastream of the old gamestate
    396505    // Start at the current offset position
    397     if(baseOffset >= baseLength)
    398       baseOffset = 0;
    399     uint8_t* temp = baseData + baseOffset;
     506    if(baseData >= baseDataEnd)
     507      baseData = GAMESTATE_START(base->data_);
     508//     uint8_t* temp = baseData + baseOffset;
    400509    uint32_t objectID = h.getObjectID();
    401     assert(temp < baseData+baseLength);
    402     assert(dest < nData + origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_);
     510    assert(baseData < baseDataEnd);
     511    assert(dest < newData + newDataSize);
    403512    assert(sizes != this->sizes_.end());
    404     while ( temp < baseData+baseLength )
    405     {
    406       SynchronisableHeader htemp(temp);
     513    bool diffedObject = false;
     514    while ( baseData < baseDataEnd )
     515    {
     516      SynchronisableHeader htemp(baseData);
    407517      assert( htemp.getDataSize()!=0 );
    408518      if ( htemp.getObjectID() == objectID )
    409519      {
    410520        assert( h.getClassID() == htemp.getClassID() );
    411         goto DODIFF;
     521//         goto DODIFF;
     522        diffObject(dest, origData, baseData, h, sizes);
     523        diffedObject = true;
     524        break;
     525      }
     526      {
     527        SynchronisableHeader htemp2(baseData+htemp.getDataSize()+SynchronisableHeader::getSize());
     528        if( baseData+htemp.getDataSize()+SynchronisableHeader::getSize() < baseDataEnd )
     529        {
     530          assert(htemp2.getClassID()<500);
     531          assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
     532          assert(htemp2.isDiffed()==false);
     533        }
     534      }
     535      baseData += htemp.getDataSize()+SynchronisableHeader::getSize();
     536//       assert( baseData+htemp.getDataSize()+SynchronisableHeader::getSize() <=baseData+baseLength );
     537//       temp += htemp.getDataSize()+SynchronisableHeader::getSize();
     538     
     539    }
     540    // If not found start looking at the beginning
     541    assert( diffedObject || baseData == baseDataEnd );
     542    baseData = GAMESTATE_START(base->data_);
     543    {
     544      SynchronisableHeader htemp2(baseData);
     545      if( baseData < baseDataEnd )
     546      {
     547        assert(htemp2.getClassID()<500);
     548        assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
     549        assert(htemp2.isDiffed()==false);
     550      }
     551    }
     552    while ( !diffedObject && baseData < baseDataEnd )
     553    {
     554      SynchronisableHeader htemp(baseData);
     555      if ( htemp.getObjectID() == objectID )
     556      {
     557        assert( h.getClassID() == htemp.getClassID() );
     558//         goto DODIFF;
     559        diffObject(dest, origData, baseData, h, sizes);
     560        break;
    412561      }
    413562//       {
    414 //         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
    415 //         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
     563//         SynchronisableHeader htemp2(baseData+htemp.getDataSize()+SynchronisableHeader::getSize());
     564//         if( baseData+htemp.getDataSize()+SynchronisableHeader::getSize() < baseDataEnd )
    416565//         {
    417566//           assert(htemp2.getClassID()<500);
     
    420569//         }
    421570//       }
    422       temp += htemp.getDataSize()+SynchronisableHeader::getSize();
    423        
    424     }
    425     // If not found start looking at the beginning
    426     assert( temp==baseData+baseLength );
    427     temp = baseData;
    428 //     {
    429 //       SynchronisableHeader htemp2(temp);
    430 //       if( temp < baseData+baseLength )
    431 //       {
    432 //         assert(htemp2.getClassID()<500);
    433 //         assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
    434 //         assert(htemp2.isDiffed()==false);
    435 //       }
    436 //     }
    437     while ( temp < baseData+baseOffset )
    438     {
    439       SynchronisableHeader htemp(temp);
    440       if ( htemp.getObjectID() == objectID )
    441       {
    442         assert( h.getClassID() == htemp.getClassID() );
    443         goto DODIFF;
    444       }
    445 //       {
    446 //         SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize());
    447 //         if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength )
    448 //         {
    449 //           assert(htemp2.getClassID()<500);
    450 //           assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
    451 //           assert(htemp2.isDiffed()==false);
    452 //         }
    453 //       }
    454       temp += htemp.getDataSize()+SynchronisableHeader::getSize();
     571      baseData += htemp.getDataSize()+SynchronisableHeader::getSize();
    455572    }
    456573    // Object is new, thus never transmitted -> just copy over
    457     goto DOCOPY;
    458 
    459 
    460 DODIFF:
    461     {
    462 //       COUT(4) << "dodiff" << endl;
    463 //       if(baseOffset==0)
    464 //       {
    465 //         assert(origOffset==0);
    466 //       }
    467       uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData
    468       // Check whether the whole object stayed the same
    469       if( memcmp( origData+origOffset+objectOffset, temp+objectOffset, h.getDataSize()) == 0 )
    470       {
    471 //         COUT(4) << "skip object" << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
    472         origOffset += objectOffset+ h.getDataSize(); // skip the whole object
    473         baseOffset = temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
    474         sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
    475       }
    476       else
    477       {
    478 //         if( Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() == "Bot" )
    479 //           COUT(0) << "blub" << endl;
    480 //         COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl;
    481 //         COUT(4) << "diff " << h.getObjectID() << ":";
    482         // Now start to diff the Object
    483         SynchronisableHeaderLight h2(dest);
    484         h2 = h; // copy over the objectheader
    485         VariableID variableID = 0;
    486         uint32_t newObjectOffset = SynchronisableHeaderLight::getSize();
    487         // iterate through all variables
    488         while( objectOffset < h.getDataSize()+SynchronisableHeader::getSize() )
    489         {
    490           // check whether variable changed and write id and copy over variable to the new stream
    491           // otherwise skip variable
    492           assert(sizes != this->sizes_.end());
    493           uint32_t varSize = *sizes;
    494           assert( varSize == Synchronisable::getSynchronisable(h.getObjectID())->getVarSize(variableID) );
    495           if ( varSize != 0 )
    496           {
    497             if ( memcmp(origData+origOffset+objectOffset, temp+objectOffset, varSize) != 0 )
    498             {
    499 //               COUT(4) << "copy variable" << endl;
    500               *(VariableID*)(dest+newObjectOffset) = variableID; // copy over the variableID
    501               newObjectOffset += sizeof(VariableID);
    502               memcpy( dest+newObjectOffset, origData+origOffset+objectOffset, varSize );
    503               newObjectOffset += varSize;
    504               objectOffset += varSize;
    505             }
    506             else
    507             {
    508 //               COUT(4) << "skip variable" << endl;
    509               objectOffset += varSize;
    510             }
    511           }
    512 //           else
    513 //             COUT(4) << "varsize 0" << endl;
    514 
    515           ++variableID;
    516           ++sizes;
    517         }
    518        
    519         if( Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() != variableID )
    520           sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() - variableID;
    521 //         COUT(4) << endl;
    522         h2.setDiffed(true);
    523         h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize());
    524         assert(objectOffset == h.getDataSize()+SynchronisableHeader::getSize());
    525         origOffset += objectOffset;
    526 //         baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData;
    527         //baseOffset += objectOffset;
    528 //         SynchronisableHeader htemp(temp);
    529 //         baseOffset += SynchronisableHeader::getSize() + htemp.getDataSize();
    530 //         {
    531 //           SynchronisableHeader htemp2( baseData+(temp-baseData+objectOffset) );
    532 //           if( baseData+(temp-baseData+objectOffset) < baseData+baseLength )
    533 //           {
    534 //             assert(htemp2.getClassID()<500);
    535 //             assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000);
    536 //             assert(htemp2.isDiffed()==false);
    537 //           }
    538 //         }
    539         baseOffset = temp-baseData + objectOffset;
    540         dest += newObjectOffset;
    541       }
    542 
    543       continue;
    544     }
    545 
    546 DOCOPY:
    547     {
    548 //       COUT(4) << "docopy" << endl;
    549       // Just copy over the whole Object
    550       memcpy( dest, origData+origOffset, h.getDataSize()+SynchronisableHeader::getSize() );
    551       dest += h.getDataSize()+SynchronisableHeader::getSize();
    552       origOffset += h.getDataSize()+SynchronisableHeader::getSize();
    553       assert( Synchronisable::getSynchronisable(h.getObjectID()) );
    554 //       COUT(4) << "copy " << h.getObjectID() << endl;
    555 //       COUT(4) << "copy " << h.getObjectID() << ":";
    556       //sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables();
    557       for( unsigned int i = 0; i < Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); ++i )
    558       {
    559 //         COUT(4) << " " << *sizes;
    560         ++sizes;
    561       }
    562 //       COUT(4) << endl;
    563       assert(sizes != this->sizes_.end() || origOffset>=origLength);
    564       continue;
    565     }
    566   }
    567 
    568 
    569   Gamestate *g = new Gamestate(nData, getClientID());
     574//     goto DOCOPY;
     575    if ( baseData >= baseDataEnd )
     576    {
     577      assert(baseData == baseDataEnd);
     578      copyObject(dest, origData, baseData, h, sizes);
     579      assert(sizes != this->sizes_.end() || origData>=origDataEnd);
     580    }
     581  }
     582  assert(sizes==this->sizes_.end());
     583
     584
     585  Gamestate *g = new Gamestate(newData, getClientID());
    570586  assert(g->header_);
    571587  *(g->header_) = *header_;
    572588  g->header_->setBaseID( base->getID() );
    573   g->header_->setDataSize(dest - nData - GamestateHeader::getSize());
     589  g->header_->setDataSize(dest - newData - GamestateHeader::getSize());
    574590  g->flags_=flags_;
    575591  g->packetDirection_ = packetDirection_;
  • code/branches/network4/src/libraries/network/packet/Gamestate.h

    r7163 r7497  
    130130    virtual inline bool process();
    131131    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
     132//     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
     133//     inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
    132134   
    133135    std::list<obj>          dataVector_;
  • code/branches/network4/src/libraries/network/synchronisable/Synchronisable.cc

    r7401 r7497  
    123123  {
    124124    SynchronisableHeader header(mem);
    125     assert( !header.isDiffed() );
     125    if( header.isDiffed() )
     126    {
     127      mem += header.getDataSize() + header.getSize();
     128      return 0;
     129    }
     130//     assert( !header.isDiffed() );
    126131
    127132    COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl;
  • code/branches/network4/src/modules/weapons/MuzzleFlash.cc

    r7284 r7497  
    4242        this->setScale(0.1f);
    4343
    44         this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this)));
     44        if( GameMode::isMaster() )
     45          this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this)));
    4546    }
    4647}
Note: See TracChangeset for help on using the changeset viewer.