Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 14, 2010, 8:54:00 PM (14 years ago)
Author:
scheusso
Message:

a lot of changes:

  • some fixes (mostly gamestate:diff)
  • FunctionCall buffering (if Gamestate is not recent enough)
Location:
code/branches/network5/src/libraries/network/packet
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network5/src/libraries/network/packet/FunctionCalls.cc

    r7495 r7759  
    3232#include "network/FunctionCall.h"
    3333#include "network/FunctionCallManager.h"
     34#include "network/GamestateHandler.h"
    3435
    3536namespace orxonox {
     
    4041const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
    4142
    42 FunctionCalls::FunctionCalls()
    43  : Packet()
     43FunctionCalls::FunctionCalls():
     44  Packet(), minGamestateID_(GAMESTATEID_INITIAL)
    4445{
    4546  flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS;
    46   currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls
     47  currentSize_ = 3*sizeof(uint32_t); // for packetid, nrOfCalls and minGamestateID_
    4748}
    4849
    49 FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID )
    50   : Packet(data, clientID)
     50FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID ):
     51  Packet(data, clientID), minGamestateID_(GAMESTATEID_INITIAL)
    5152{
    5253}
     
    6364  uint32_t nrOfCalls = *(uint32_t*)temp;
    6465  temp += sizeof(uint32_t);
     66  this->minGamestateID_ = *(uint32_t*)temp;
     67  temp += sizeof(uint32_t);
    6568  for( unsigned int i = 0; i<nrOfCalls; i++ )
    6669  {
    6770    FunctionCall fctCall;
    6871    fctCall.loadData(temp);
    69     if( !fctCall.execute() )
    70       FunctionCallManager::bufferIncomingFunctionCall( fctCall );
     72    if( this->minGamestateID_ > GamestateHandler::getInstance()->getLastProcessedGamestateID(this->getClientID()) || !fctCall.execute() )
     73    {
     74      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getClientID() );
     75    }
    7176  }
    7277 
     
    9398bool FunctionCalls::send()
    9499{
     100  this->minGamestateID_ = GamestateHandler::getInstance()->getCurrentGamestateID();
    95101  assert(this->functionCalls_.size());
    96102  data_=new uint8_t[ currentSize_ ];
    97103  *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID
    98   *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls to 0
    99   uint8_t* temp = data_+2*sizeof(uint32_t);
     104  *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls
     105  *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_
     106  uint8_t* temp = data_+3*sizeof(uint32_t);
    100107 
    101108  while( this->functionCalls_.size() )
  • code/branches/network5/src/libraries/network/packet/FunctionCalls.h

    r7490 r7759  
    6262  std::queue<orxonox::FunctionCall> functionCalls_;
    6363  unsigned int                      clientID_;
     64  uint32_t                          minGamestateID_;
    6465  uint32_t                          currentSize_;
    6566};
  • code/branches/network5/src/libraries/network/packet/Gamestate.cc

    r7758 r7759  
    4343#define GAMESTATE_START(data) (data + GamestateHeader::getSize())
    4444
    45 #define PACKET_FLAG_GAMESTATE  0 //PacketFlag::Reliable
     45// #define PACKET_FLAG_GAMESTATE  PacketFlag::Unsequenced
     46// #define PACKET_FLAG_GAMESTATE  0
     47#define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
    4648
    4749inline bool memzero( uint8_t* data, uint32_t datalength)
     
    364366inline void /*Gamestate::*/diffObject( uint8_t*& newDataPtr, uint8_t*& origDataPtr, uint8_t*& baseDataPtr, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes )
    365367{
    366   //       COUT(4) << "dodiff" << endl;
    367   //       if(baseOffset==0)
    368   //       {
    369   //         assert(origOffset==0);
    370   //       }
    371368  assert( objectHeader.getDataSize() == SynchronisableHeader(baseDataPtr).getDataSize() );
    372369 
     
    382379  else
    383380  {
    384     //         if( Synchronisable::getSynchronisable(origHeader.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() << ":";
    388381    // Now start to diff the Object
    389382    SynchronisableHeaderLight newObjectHeader(newDataPtr);
     
    396389      // check whether variable changed and write id and copy over variable to the new stream
    397390      // otherwise skip variable
    398 //       assert(sizes != this->sizes_.end());
    399391      uint32_t varSize = *sizes;
    400392      assert( varSize == Synchronisable::getSynchronisable(objectHeader.getObjectID())->getVarSize(variableID) );
     
    403395        if ( memcmp(origDataPtr+objectOffset, baseDataPtr+objectOffset, varSize) != 0 )
    404396        {
    405           //               COUT(4) << "copy variable" << endl;
    406397          *(VariableID*)(newDataPtr+diffedObjectOffset) = variableID; // copy over the variableID
    407398          diffedObjectOffset += sizeof(VariableID);
     
    412403        else
    413404        {
    414           //               COUT(4) << "skip variable" << endl;
    415405          objectOffset += varSize;
    416406        }
    417407      }
    418 //           else
    419 //             COUT(4) << "varsize 0" << endl;
    420408
    421409      ++variableID;
    422410      ++sizes;
    423411    }
    424            
     412   
     413    // if there are variables from this object with 0 size left in sizes
    425414    if( Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() != variableID )
    426415      sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() - variableID;
    427     //         COUT(4) << endl;
    428416   
    429417    newObjectHeader.setDiffed(true);
     
    431419    assert(objectOffset == objectHeader.getDataSize()+SynchronisableHeader::getSize());
    432420    assert(newObjectHeader.getDataSize()>0);
     421   
    433422    origDataPtr += 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     //         }
    447423    baseDataPtr += objectOffset;
    448424    newDataPtr += diffedObjectOffset;
     
    455431  // Just copy over the whole Object
    456432  memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() );
     433  SynchronisableHeader(newData).setDiffed(false);
     434 
    457435  newData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
    458436  origData += objectHeader.getDataSize()+SynchronisableHeader::getSize();
     
    547525    assert(sizesIt != this->sizes_.end());
    548526   
     527    assert(Synchronisable::getSynchronisable(origHeader.getObjectID()));
     528    assert(ClassByID(origHeader.getClassID()));
     529    assert(origHeader.getDataSize() < 500);
     530   
    549531    bool diffedObject = false;
    550532    if( findObject(baseDataPtr, baseDataEnd, origHeader) )
    551533    {
     534      SynchronisableHeader baseHeader(baseDataPtr);
     535      assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
     536      assert(ClassByID(baseHeader.getClassID()));
     537      assert(baseHeader.getDataSize() < 500);
    552538      if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
    553539      {
     
    570556      if( findObject(baseDataPtr, oldBaseDataPtr, origHeader) )
    571557      {
     558        SynchronisableHeader baseHeader(baseDataPtr);
     559        assert(Synchronisable::getSynchronisable(baseHeader.getObjectID()));
     560        assert(ClassByID(baseHeader.getClassID()));
     561        assert(baseHeader.getDataSize() < 500);
    572562        if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() )
    573563        {
  • code/branches/network5/src/libraries/network/packet/Packet.cc

    r7163 r7759  
    5353
    5454// Make sure we assume the right values
    55 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)   == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
    56 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequence) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
    57 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
     55BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)    == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
     56BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
     57BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate)  == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
    5858
    5959#define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate
     
    174174  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
    175175  Packet *p = 0;
    176   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
     176//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
    177177  switch( *(Type::Value *)(data + _PACKETID) )
    178178  {
    179179    case Type::Acknowledgement:
    180       COUT(5) << "ack" << std::endl;
     180//       COUT(5) << "ack" << std::endl;
    181181      p = new Acknowledgement( data, clientID );
    182182      break;
    183183    case Type::Chat:
    184       COUT(5) << "chat" << std::endl;
     184//       COUT(5) << "chat" << std::endl;
    185185      p = new Chat( data, clientID );
    186186      break;
    187187    case Type::ClassID:
    188       COUT(5) << "classid" << std::endl;
     188//       COUT(5) << "classid" << std::endl;
    189189      p = new ClassID( data, clientID );
    190190      break;
    191191    case Type::Gamestate:
    192       COUT(5) << "gamestate" << std::endl;
    193       // TODO: remove brackets
     192//       COUT(5) << "gamestate" << std::endl;
    194193      p = new Gamestate( data, clientID );
    195194      break;
    196195    case Type::Welcome:
    197       COUT(5) << "welcome" << std::endl;
     196//       COUT(5) << "welcome" << std::endl;
    198197      p = new Welcome( data, clientID );
    199198      break;
    200199    case Type::DeleteObjects:
    201       COUT(5) << "deleteobjects" << std::endl;
     200//       COUT(5) << "deleteobjects" << std::endl;
    202201      p = new DeleteObjects( data, clientID );
    203202      break;
    204203    case Type::FunctionCalls:
    205       COUT(5) << "functionCalls" << std::endl;
     204//       COUT(5) << "functionCalls" << std::endl;
    206205      p = new FunctionCalls( data, clientID );
    207206      break;
    208207    case Type::FunctionIDs:
    209       COUT(5) << "functionIDs" << std::endl;
     208//       COUT(5) << "functionIDs" << std::endl;
    210209      p = new FunctionIDs( data, clientID );
    211210      break;
    212211    default:
    213       assert(0); //TODO: repair this
     212      assert(0);
    214213      break;
    215214  }
     
    235234  delete it->second;
    236235  packetMap_.erase(it);
    237   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
     236//   COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl;
    238237}
    239238
Note: See TracChangeset for help on using the changeset viewer.