Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7759


Ignore:
Timestamp:
Dec 14, 2010, 8:54:00 PM (13 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
Files:
16 edited

Legend:

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

    r7495 r7759  
    164164          COUT(4) << "client tick: sending gs " << gs << std::endl;
    165165          if( !gs->send() )
    166             COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
     166            COUT(2) << "Problem adding partial gamestate to queue" << std::endl;
    167167        // gs gets automatically deleted by enet callback
    168168        }
  • code/branches/network5/src/libraries/network/FunctionCallManager.cc

    r7495 r7759  
    3030#include "packet/FunctionCalls.h"
    3131#include "core/GameMode.h"
     32#include "GamestateHandler.h"
    3233
    3334namespace orxonox {
    3435
    3536std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sClientMap_;
    36 std::vector<FunctionCall> FunctionCallManager::sIncomingFunctionCallBuffer_;
     37std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_;
    3738
    3839// Static calls
     
    164165}
    165166
    166 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall)
     167void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID)
    167168{
    168   if( !GameMode::isMaster() )
    169     FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( fctCall );
     169  FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, clientID)));
    170170}
    171171
    172172void FunctionCallManager::processBufferedFunctionCalls()
    173173{
    174   std::vector<FunctionCall>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
     174  std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();
    175175  while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() )
    176176  {
    177     if( it->execute() )
     177    uint32_t minGamestateID = it->second.first;
     178    uint32_t clientID       = it->second.second;
     179    if( minGamestateID <= GamestateHandler::getInstance()->getLastProcessedGamestateID(clientID) && it->first.execute() )
    178180      FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it);
    179181    else
     182    {
    180183      ++it;
     184    }
    181185  }
    182186}
  • code/branches/network5/src/libraries/network/FunctionCallManager.h

    r7495 r7759  
    3434#include <map>
    3535#include <vector>
     36#include <utility>
    3637#include "util/UtilPrereqs.h"
    3738#include "FunctionCall.h"
     
    6162  static void sendCalls();
    6263 
    63   static void bufferIncomingFunctionCall( const FunctionCall& fctCall );
     64  static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t clientID );
    6465  static void processBufferedFunctionCalls();
    6566
    66   static std::map<uint32_t, packet::FunctionCalls*> sClientMap_;
    67   static std::vector<FunctionCall>                  sIncomingFunctionCallBuffer_;
     67  static std::map<uint32_t, packet::FunctionCalls*>                           sClientMap_;
     68  static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_;
    6869protected:
    6970  FunctionCallManager();
  • code/branches/network5/src/libraries/network/GamestateClient.cc

    r7401 r7759  
    3939namespace orxonox
    4040{
    41   struct _NetworkExport GameStateItem{
     41  struct _NetworkExport GameStateItem
     42  {
    4243    packet::Gamestate *state;
    4344    unsigned int id;
    4445  };
    4546
    46   GamestateClient::GamestateClient() {
     47  GamestateClient::GamestateClient()
     48  {
    4749    COUT(5) << "this: " << this << std::endl;
    48     last_diff_=0;
    49     last_gamestate_=GAMESTATEID_INITIAL-1;
     50    lastAckedGamestateID_=GAMESTATEID_INITIAL-1;
     51    lastProcessedGamestateID_=GAMESTATEID_INITIAL-1;
    5052    tempGamestate_=NULL;
    5153  }
    5254
    53   GamestateClient::~GamestateClient() {
     55  GamestateClient::~GamestateClient()
     56  {
    5457      std::map<unsigned int, packet::Gamestate *>::iterator it;
    5558      for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
     
    5962  }
    6063
    61   bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){
     64  bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID)
     65  {
    6266    return true;
    6367  }
    6468
    65   bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){
    66     if(tempGamestate_!=NULL){
     69  bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID)
     70  {
     71    if(tempGamestate_!=NULL)
     72    {
    6773      //delete the obsolete gamestate
    6874      if(tempGamestate_->getID()>gs->getID())
     
    7480  }
    7581
    76   bool GamestateClient::processGamestates(){
     82  bool GamestateClient::processGamestates()
     83  {
    7784    if(tempGamestate_==NULL)
    7885      return false;
     
    8592    NetworkCallbackManager::callCallbacks();
    8693
    87     if (!processed){
     94    if (!processed)
     95    {
     96      assert(0);
    8897      sendAck(0);
    8998      return false;
     
    92101    tempGamestate_=NULL;
    93102    gamestateMap_[processed->getID()]=processed;
     103    lastProcessedGamestateID_ = processed->getID();
    94104    if(isDiffed)
    95       last_diff_ = processed->getBaseID();
     105      lastAckedGamestateID_ = processed->getBaseID();
    96106    id = processed->getID();
    97107    sendAck(id);
     
    105115  * @return iterator pointing to the next object in the list
    106116  */
    107   void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) {
     117  void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it)
     118  {
    108119    ObjectListIterator<Synchronisable> temp=it;
    109120    ++it;
     
    111122  }
    112123
    113   packet::Gamestate *GamestateClient::getGamestate(){
     124  packet::Gamestate *GamestateClient::getGamestate()
     125  {
    114126    packet::Gamestate *gs = new packet::Gamestate();
    115     if(!gs->collectData(0,0x2)){
     127    if(!gs->collectData(this->getLastProcessedGamestateID(NETWORK_PEER_ID_SERVER), 0x2))
     128    {
    116129      delete gs;
    117130      return 0;
     
    120133  }
    121134
    122   void GamestateClient::cleanup(){
     135  void GamestateClient::cleanup()
     136  {
    123137    std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();
    124     while(it!=gamestateMap_.end()){
    125       if(it->first>=last_diff_)
     138    while(it!=gamestateMap_.end())
     139    {
     140      if(it->first>=lastAckedGamestateID_)
    126141        break;
    127142      // otherwise delete that stuff
     
    133148  }
    134149
    135   void GamestateClient::printGamestateMap(){
     150  void GamestateClient::printGamestateMap()
     151  {
    136152    std::map<unsigned int, packet::Gamestate*>::iterator it;
    137153    COUT(4) << "gamestates: ";
    138     for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){
     154    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++)
     155    {
    139156      COUT(4) << it->first << ':' << it->second << '|';
    140157    }
     
    143160  }
    144161
    145   bool GamestateClient::sendAck(unsigned int gamestateID){
     162  bool GamestateClient::sendAck(unsigned int gamestateID)
     163  {
    146164    packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0);
    147     if(!ack->send()){
     165    if(!ack->send())
     166    {
    148167      COUT(3) << "could not ack gamestate: " << gamestateID << std::endl;
    149168      return false;
    150169    }
    151     else{
     170    else
     171    {
    152172      COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
    153173      return true;
     
    155175  }
    156176
    157   packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
     177  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs)
     178  {
    158179    if(gs->isCompressed())
    159180    {
  • code/branches/network5/src/libraries/network/GamestateClient.h

    r5781 r7759  
    5757    ~GamestateClient();
    5858
    59     bool add(packet::Gamestate *gs, unsigned int clientID);
    60     bool ack(unsigned int gamestateID, unsigned int clientID);
     59    virtual bool      add(packet::Gamestate *gs, unsigned int clientID);
     60    virtual bool      ack(unsigned int gamestateID, unsigned int clientID);
     61    virtual uint32_t  getLastProcessedGamestateID(unsigned int clientID) { return this->lastProcessedGamestateID_; }
     62    virtual uint32_t  getCurrentGamestateID(){ return this->lastProcessedGamestateID_; }
    6163
    6264    bool processGamestates();
     
    6971    bool sendAck(unsigned int gamestateID);
    7072
    71     unsigned int           last_diff_;
    72     unsigned int           last_gamestate_;
     73    unsigned int           lastAckedGamestateID_;
     74    unsigned int           lastProcessedGamestateID_;
    7375    std::map<unsigned int, packet::Gamestate *> gamestateMap_;
    7476    packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue
  • code/branches/network5/src/libraries/network/GamestateHandler.h

    r6073 r7759  
    3232#include "NetworkPrereqs.h"
    3333
     34#include <cassert>
     35
    3436namespace orxonox {
    3537
     
    3941class _NetworkExport GamestateHandler{
    4042  private:
    41     virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0;
    42     virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0;
     43    virtual bool      add(packet::Gamestate *gs, unsigned int clientID)=0;
     44    virtual bool      ack(unsigned int gamestateID, unsigned int clientID)=0;
    4345
    44     static GamestateHandler *instance_;
     46    static GamestateHandler* instance_;
    4547
    4648
     
    5052
    5153  public:
    52     static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); }
    53     static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); }
     54    static bool     addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); }
     55    static bool     ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); }
     56    static GamestateHandler* getInstance(){ assert(instance_); return instance_; }
     57   
     58    virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID )=0;
     59    virtual uint32_t  getCurrentGamestateID()=0;
    5460};
    5561
  • code/branches/network5/src/libraries/network/GamestateManager.cc

    r7758 r7759  
    258258    return true;
    259259  }
     260 
     261  uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int clientID)
     262  {
     263    assert( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() );
     264    if( this->lastProcessedGamestateID_.find(clientID) != this->lastProcessedGamestateID_.end() )
     265      return this->lastProcessedGamestateID_[clientID];
     266    else
     267      return GAMESTATEID_INITIAL;
     268  }
    260269
    261270  void GamestateManager::removeClient(ClientInformation* client){
     
    277286    }
    278287    assert(!gs->isDiffed());
    279     return gs->spreadData(0x1);
     288    if( gs->spreadData(0x1) )
     289    {
     290      this->lastProcessedGamestateID_[gs->getClientID()] = gs->getID();
     291      return true;
     292    }
     293    else
     294      return false;
    280295  }
    281296
  • code/branches/network5/src/libraries/network/GamestateManager.h

    r7163 r7759  
    4646#include "GamestateHandler.h"
    4747#include "core/CorePrereqs.h"
     48#include "packet/Gamestate.h"
    4849
    4950namespace orxonox
     
    7172    ~GamestateManager();
    7273
    73     bool add(packet::Gamestate *gs, unsigned int clientID);
     74    virtual bool      add(packet::Gamestate *gs, unsigned int clientID);
     75    virtual bool      ack(unsigned int gamestateID, unsigned int clientID);
     76    virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID );
     77    virtual uint32_t  getCurrentGamestateID(){ return reference->getID(); }
     78   
    7479    bool processGamestates();
    7580    bool update();
     
    8085    bool getSnapshot();
    8186
    82     bool ack(unsigned int gamestateID, unsigned int clientID);
    8387    void removeClient(ClientInformation *client);
    8488  private:
     
    8791    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;
    8892    std::map<unsigned int, packet::Gamestate*> gamestateQueue;
     93    std::map<unsigned int, uint32_t> lastProcessedGamestateID_;
    8994    packet::Gamestate *reference;
    9095    TrafficControl *trafficControl_;
  • code/branches/network5/src/libraries/network/MasterServerComm.cc

    r7756 r7759  
    8989
    9090    /* Wait up to 2 seconds for the connection attempt to succeed. */
    91     if (enet_host_service (this->client, this->event, 2000) > 0 &&
     91    if (enet_host_service (this->client, this->event, 500) > 0 &&
    9292        this->event->type == ENET_EVENT_TYPE_CONNECT )
    9393      COUT(3) << "Connection to master server succeeded.\n";
  • code/branches/network5/src/libraries/network/NetworkPrereqs.h

    r7490 r7759  
    6969  extern const char* LAN_DISCOVERY_ACK;
    7070  static const unsigned int LAN_DISCOVERY_PORT      = 55557;
     71  static const unsigned int NETWORK_PEER_ID_SERVER = 0;
    7172}
    7273
     
    8384      enum Value
    8485      {
    85         Reliable   = 1,
    86         Unsequence = 2,
    87         NoAllocate = 4
     86        Reliable    = 1,
     87        Unsequenced = 2,
     88        NoAllocate  = 4
    8889      };
    8990    }
  • code/branches/network5/src/libraries/network/Server.cc

    r7756 r7759  
    217217      // process incoming gamestates
    218218      GamestateManager::processGamestates();
     219      FunctionCallManager::processBufferedFunctionCalls();
    219220
    220221      // send function calls to clients
  • 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
  • code/branches/network5/src/libraries/network/synchronisable/Synchronisable.h

    r7163 r7759  
    6565    };
    6666  }
    67  
    68   typedef uint8_t VariableID;
    69 
    70   /**
    71    * @brief: stores information about a Synchronisable
    72    *
    73    * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
    74    * in an emulated bitset.
    75    * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    76    * Bit 32 is a bool and defines whether the variables are stored in diff mode
    77    * Byte 5 to 8: objectID_
    78    * Byte 9 to 12: classID_
    79    * Byte 13 to 16: creatorID_
    80    */
    81   class _NetworkExport SynchronisableHeader{
    82     friend class SynchronisableHeaderLight;
    83     private:
    84       uint8_t* data_;
    85     public:
    86       SynchronisableHeader(uint8_t* data)
    87         { data_ = data; }
    88       inline static uint32_t getSize()
    89         { return 14; }
    90       inline uint16_t getDataSize() const
    91         { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits
    92       inline void setDataSize(uint16_t size)
    93         { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(uint16_t*)(data_) & 0x8000 ); }
    94       inline bool isDiffed() const
    95         { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }
    96       inline void setDiffed( bool b)
    97         { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }
    98       inline uint32_t getObjectID() const
    99         { return *(uint32_t*)(data_+2); }
    100       inline void setObjectID(uint32_t objectID_)
    101         { *(uint32_t*)(data_+2) = objectID_; }
    102       inline uint32_t getClassID() const
    103         { return *(uint32_t*)(data_+6); }
    104       inline void setClassID(uint32_t classID_)
    105         { *(uint32_t*)(data_+6) = classID_; }
    106       inline uint32_t getCreatorID() const
    107         { return *(uint32_t*)(data_+10); }
    108       inline void setCreatorID(uint32_t creatorID_)
    109         { *(uint32_t*)(data_+10) = creatorID_; }
    110       inline void operator=(SynchronisableHeader& h)
    111         { memcpy(data_, h.data_, getSize()); }
    112   };
    11367
    11468    /**
     
    12175   * Byte 5 to 8: objectID_
    12276   */
    123   class _NetworkExport SynchronisableHeaderLight{
    124     private:
     77  class _NetworkExport SynchronisableHeaderLight
     78  {
     79    protected:
    12580      uint8_t* data_;
    12681    public:
     
    14196      inline void setObjectID(uint32_t objectID_)
    14297        { *(uint32_t*)(data_+2) = objectID_; }
     98      inline void operator=(SynchronisableHeaderLight& h)
     99        { memcpy(data_, h.data_, SynchronisableHeaderLight::getSize()); }
     100  };
     101 
     102  typedef uint8_t VariableID;
     103 
     104  /**
     105   * @brief: stores information about a Synchronisable
     106   *
     107   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
     108   * in an emulated bitset.
     109   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
     110   * Bit 32 is a bool and defines whether the variables are stored in diff mode
     111   * Byte 5 to 8: objectID_
     112   * Byte 9 to 12: classID_
     113   * Byte 13 to 16: creatorID_
     114   */
     115  class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight
     116  {
     117    public:
     118      SynchronisableHeader(uint8_t* data): SynchronisableHeaderLight(data)
     119        {}
     120      inline static uint32_t getSize()
     121        { return SynchronisableHeaderLight::getSize()+8; }
     122      inline uint32_t getClassID() const
     123        { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()); }
     124      inline void setClassID(uint32_t classID_)
     125        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; }
     126      inline uint32_t getCreatorID() const
     127        { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); }
     128      inline void setCreatorID(uint32_t creatorID_)
     129        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = creatorID_; }
    143130      inline void operator=(SynchronisableHeader& h)
    144131        { memcpy(data_, h.data_, getSize()); }
    145132  };
     133 
     134//   inline void operator=(SynchronisableHeaderLight& h1, SynchronisableHeader& h2)
     135//   {
     136//     memcpy(h1.data_, h2.data_, h1.getSize());
     137//   }
    146138
    147139  /**
Note: See TracChangeset for help on using the changeset viewer.