Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 19, 2010, 2:27:06 PM (15 years ago)
Author:
scheusso
Message:

some () structural changes
some functional changes (GamestateClient replaced through GamestateManager on client)
reliable packets get buffered until a recent gamestate arrived and got processed

Location:
code/branches/network5/src/libraries/network/packet
Files:
18 edited

Legend:

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

    r6417 r7777  
    3131#include "util/Debug.h"
    3232#include "network/GamestateHandler.h"
     33#include "network/Host.h"
    3334
    3435namespace orxonox {
     
    3940#define _ACKID              _PACKETID + sizeof(packet::Type::Value)
    4041
    41 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
     42Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
    4243 : Packet()
    4344{
     
    4647  *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement;
    4748  *(uint32_t *)(data_ + _ACKID ) = id;
    48   clientID_=clientID;
     49  peerID_=peerID;
    4950}
    5051
    51 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )
    52   : Packet(data, clientID)
     52Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID )
     53  : Packet(data, peerID)
    5354{
    5455}
     
    6263}
    6364
    64 bool Acknowledgement::process(){
     65bool Acknowledgement::process(orxonox::Host* host){
    6566  COUT(5) << "processing ACK with ID: " << getAckID() << endl;
    66   bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
     67  bool b = host->ackGamestate(getAckID(), peerID_);
    6768  delete this;
    6869  return b;
  • code/branches/network5/src/libraries/network/packet/Acknowledgement.h

    r6073 r7777  
    4242{
    4343public:
    44   Acknowledgement( unsigned int id, unsigned int clientID );
    45   Acknowledgement( uint8_t* data, unsigned int clientID );
     44  Acknowledgement( unsigned int id, unsigned int peerID );
     45  Acknowledgement( uint8_t* data, unsigned int peerID );
    4646  ~Acknowledgement();
    4747
    4848  inline unsigned int getSize() const;
    49   bool process();
     49  virtual bool process(orxonox::Host* host);
    5050
    5151  unsigned int getAckID();
  • code/branches/network5/src/libraries/network/packet/Chat.cc

    r7163 r7777  
    8080}
    8181
    82 bool Chat::process(){
    83   bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
     82bool Chat::process(orxonox::Host* host){
     83  bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));
    8484  delete this;
    8585  return b;
  • code/branches/network5/src/libraries/network/packet/Chat.h

    r7163 r7777  
    5252
    5353  /* process chat message packet and remove it afterwards */
    54   bool process();
     54  virtual bool process(orxonox::Host* host);
    5555
    5656  /* Get the length of the message (not the full size of the packet) */
  • code/branches/network5/src/libraries/network/packet/ClassID.cc

    r7163 r7777  
    120120
    121121
    122 bool ClassID::process(){
     122bool ClassID::process(orxonox::Host* host){
    123123  int nrOfClasses;
    124124  uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
  • code/branches/network5/src/libraries/network/packet/ClassID.h

    r6417 r7777  
    4848
    4949  uint32_t getSize() const;
    50   bool process();
     50  virtual bool process(orxonox::Host* host);
    5151
    5252private:
  • code/branches/network5/src/libraries/network/packet/DeleteObjects.cc

    r6417 r7777  
    5757}
    5858
    59 bool DeleteObjects::fetchIDs(){
     59bool DeleteObjects::fetchIDs()
     60{
    6061  unsigned int number = Synchronisable::getNumberOfDeletedObject();
    6162  if(number==0)
     
    7980}
    8081
    81 unsigned int DeleteObjects::getSize() const{
     82unsigned int DeleteObjects::getSize() const
     83{
    8284  assert(data_);
    8385  return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t);
    8486}
    8587
    86 bool DeleteObjects::process(){
    87   for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){
     88bool DeleteObjects::process(orxonox::Host* host)
     89{
     90  for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++)
     91  {
    8892    COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl;
    8993    Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) );
  • code/branches/network5/src/libraries/network/packet/DeleteObjects.h

    r6073 r7777  
    3232#include "Packet.h"
    3333
    34 namespace orxonox {
    35 namespace packet {
     34namespace orxonox
     35{
     36namespace packet
     37{
    3638/**
    3739    @author
     
    4749
    4850  inline unsigned int getSize() const;
    49   bool process();
     51  virtual bool process(orxonox::Host* host);
    5052
    5153private:
  • code/branches/network5/src/libraries/network/packet/FunctionCalls.cc

    r7759 r7777  
    5858
    5959
    60 bool FunctionCalls::process(){
     60bool FunctionCalls::process(orxonox::Host* host)
     61{
    6162  assert(isDataENetAllocated());
    6263 
     
    7071    FunctionCall fctCall;
    7172    fctCall.loadData(temp);
    72     if( this->minGamestateID_ > GamestateHandler::getInstance()->getLastProcessedGamestateID(this->getClientID()) || !fctCall.execute() )
     73    if( this->minGamestateID_ > host->getLastProcessedGamestateID(this->getPeerID()) || !fctCall.execute() )
    7374    {
    74       FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getClientID() );
     75      FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() );
    7576    }
    7677  }
     
    8081}
    8182
    82 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
     83void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
     84{
    8385  assert(!isDataENetAllocated());
    8486 
     
    8890}
    8991
    90 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
     92void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5)
     93{
    9194  assert(!isDataENetAllocated());
    9295 
     
    9699}
    97100
    98 bool FunctionCalls::send()
     101bool FunctionCalls::send(orxonox::Host* host)
    99102{
    100   this->minGamestateID_ = GamestateHandler::getInstance()->getCurrentGamestateID();
     103  this->minGamestateID_ = host->getCurrentGamestateID();
    101104  assert(this->functionCalls_.size());
    102105  data_=new uint8_t[ currentSize_ ];
     
    114117  assert( temp==data_+currentSize_ );
    115118 
    116   Packet::send();
     119  Packet::send(host);
    117120  return true;
    118121}
  • code/branches/network5/src/libraries/network/packet/FunctionCalls.h

    r7759 r7777  
    5454  inline unsigned int getSize() const
    5555    { assert(!this->isDataENetAllocated()); return currentSize_; }
    56   bool process();
     56  virtual bool process(orxonox::Host* host);
    5757
    5858  void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
    5959  void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0);
    60   virtual bool send();
     60  virtual bool send(orxonox::Host* host);
    6161private:
    6262  std::queue<orxonox::FunctionCall> functionCalls_;
  • code/branches/network5/src/libraries/network/packet/FunctionIDs.cc

    r6417 r7777  
    4646
    4747
    48 FunctionIDs::FunctionIDs( ) : Packet(){
     48FunctionIDs::FunctionIDs( ) : Packet()
     49{
    4950  unsigned int nrOfFunctions=0;
    5051  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions
     
    5556  //calculate total needed size (for all strings and integers)
    5657  ObjectList<NetworkFunctionBase>::iterator it;
    57   for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){
     58  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it)
     59  {
    5860    const std::string& functionname = it->getName();
    5961    networkID = it->getNetworkID();
     
    7678  // now save all classids and classnames
    7779  std::pair<uint32_t, std::string> tempPair;
    78   while( !tempQueue.empty() ){
     80  while( !tempQueue.empty() )
     81  {
    7982    tempPair = tempQueue.front();
    8083    tempQueue.pop();
     
    98101}
    99102
    100 uint32_t FunctionIDs::getSize() const{
     103uint32_t FunctionIDs::getSize() const
     104{
    101105  assert(this->data_);
    102106  uint8_t *temp = data_+sizeof(uint32_t); // packet identification
     
    114118
    115119
    116 bool FunctionIDs::process(){
     120bool FunctionIDs::process(orxonox::Host* host)
     121{
    117122  int nrOfFunctions;
    118123  uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid
     
    127132  temp += sizeof(uint32_t);
    128133
    129   for( int i=0; i<nrOfFunctions; i++){
     134  for( int i=0; i<nrOfFunctions; i++)
     135  {
    130136    networkID = *(uint32_t*)temp;
    131137    stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
  • code/branches/network5/src/libraries/network/packet/FunctionIDs.h

    r6417 r7777  
    4747  ~FunctionIDs();
    4848
    49   uint32_t getSize() const;
    50   bool process();
     49  virtual uint32_t getSize() const;
     50  virtual bool process(orxonox::Host* host);
    5151
    5252private:
  • code/branches/network5/src/libraries/network/packet/Gamestate.cc

    r7759 r7777  
    3636#include "network/synchronisable/Synchronisable.h"
    3737#include "network/GamestateHandler.h"
     38#include "network/Host.h"
    3839
    3940namespace orxonox {
     
    4445
    4546// #define PACKET_FLAG_GAMESTATE  PacketFlag::Unsequenced
    46 // #define PACKET_FLAG_GAMESTATE  0
    47 #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
     47#define PACKET_FLAG_GAMESTATE  0
     48// #define PACKET_FLAG_GAMESTATE  PacketFlag::Reliable
    4849
    4950inline bool memzero( uint8_t* data, uint32_t datalength)
     
    138139      assert(0); // if we don't use multithreading this part shouldn't be neccessary
    139140      // start allocate additional memory
    140       COUT(3) << "G.St.Man: need additional memory" << std::endl;
     141      COUT(3) << "Gamestate: need additional memory" << std::endl;
    141142      ObjectList<Synchronisable>::iterator temp = it;
    142143      uint32_t addsize=tempsize;
     
    165166  //stop write gamestate header
    166167
    167   COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl;
    168   COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
     168  COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl;
     169  COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl;
    169170  return true;
    170171}
     
    173174bool Gamestate::spreadData(uint8_t mode)
    174175{
    175   COUT(4) << "processing gamestate with id " << header_.getID() << endl;
     176  COUT(5) << "processing gamestate with id " << header_.getID() << endl;
    176177  assert(data_);
    177178  assert(!header_.isCompressed());
     
    204205    }
    205206  }
     207  assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize());
     208 
    206209   // In debug mode, check first, whether there are no duplicate objectIDs
    207210#ifndef NDEBUG
     
    269272
    270273
    271 bool Gamestate::process()
    272 {
    273   return GamestateHandler::addGamestate(this, getClientID());
     274bool Gamestate::process(orxonox::Host* host)
     275{
     276  return host->addGamestate(this, getPeerID());
    274277}
    275278
     
    585588
    586589
    587   Gamestate *g = new Gamestate(newData, getClientID());
     590  Gamestate *g = new Gamestate(newData, getPeerID());
    588591  (g->header_) = header_;
    589592  g->header_.setBaseID( base->getID() );
     
    757760
    758761
    759 uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
     762uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode)
    760763{
    761764  uint32_t size = 0;
  • code/branches/network5/src/libraries/network/packet/Gamestate.h

    r7758 r7777  
    4242#include "Packet.h"
    4343
    44 namespace orxonox {
     44namespace orxonox
     45{
    4546
    46 namespace packet {
     47namespace packet
     48{
     49   
     50static const uint8_t GAMESTATE_MODE_SERVER = 0x1;
     51static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;
    4752
    48 class _NetworkExport GamestateHeader{
     53class _NetworkExport GamestateHeader
     54{
    4955  public:
    5056    GamestateHeader(){ data_=0; }
     
    5864      { return 21; }
    5965
    60     inline int32_t getID() const
    61       { assert(data_); return *(int32_t*)(data_+4); }
    62     inline void setID(int32_t id)
    63       { assert(data_); *(int32_t*)(data_+4) = id; }
     66    inline uint32_t getID() const
     67      { assert(data_); return *(uint32_t*)(data_+4); }
     68    inline void setID(uint32_t id)
     69      { assert(data_); *(uint32_t*)(data_+4) = id; }
    6470
    65     inline int32_t getBaseID() const
    66       { assert(data_); return *(int32_t*)(data_+8); }
    67     inline void setBaseID(int32_t id)
    68       { assert(data_); *(int32_t*)(data_+8) = id; }
     71    inline uint32_t getBaseID() const
     72      { assert(data_); return *(uint32_t*)(data_+8); }
     73    inline void setBaseID(uint32_t id)
     74      { assert(data_); *(uint32_t*)(data_+8) = id; }
    6975
    7076    inline uint32_t getDataSize() const
     
    103109    @author Oliver Scheuss
    104110*/
    105 class _NetworkExport Gamestate: public Packet{
     111class _NetworkExport Gamestate: public Packet
     112{
    106113  public:
    107114    Gamestate();
     
    114121    bool collectData(int id, uint8_t mode=0x0);
    115122    bool spreadData( uint8_t mode=0x0);
    116     inline int32_t getID() const { return header_.getID(); }
     123    inline uint32_t getID() const { return header_.getID(); }
    117124    inline bool isDiffed() const { return header_.isDiffed(); }
    118125    inline bool isCompressed() const { return header_.isCompressed(); }
     
    132139//     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
    133140    virtual uint32_t getSize() const;
    134     virtual inline bool process();
    135     uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
     141    virtual bool process(orxonox::Host* host);
     142    uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0);
    136143//     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
    137144//     inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
  • code/branches/network5/src/libraries/network/packet/Packet.cc

    r7773 r7777  
    6868  flags_ = PACKET_FLAG_DEFAULT;
    6969  packetDirection_ = Direction::Outgoing;
    70   clientID_=0;
     70  peerID_=0;
    7171  data_=0;
    7272  enetPacket_=0;
     
    7474}
    7575
    76 Packet::Packet(uint8_t *data, unsigned int clientID)
     76Packet::Packet(uint8_t *data, unsigned int peerID)
    7777{
    7878  flags_ = PACKET_FLAG_DEFAULT;
    7979  packetDirection_ = Direction::Incoming;
    80   clientID_=clientID;
     80  peerID_=peerID;
    8181  data_=data;
    8282  enetPacket_=0;
     
    8989  flags_=p.flags_;
    9090  packetDirection_ = p.packetDirection_;
    91   clientID_ = p.clientID_;
     91  peerID_ = p.peerID_;
    9292  if(p.data_){
    9393    data_ = new uint8_t[p.getSize()];
     
    125125}
    126126
    127 bool Packet::send(){
     127bool Packet::send(orxonox::Host* host){
    128128  if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
    129129    assert(0);
     
    169169//  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
    170170  if( this->flags_ & PacketFlag::Reliable )
    171     Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_DEFAULT);
     171    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
    172172  else
    173     Host::addPacket( enetPacket_, clientID_, NETWORK_CHANNEL_UNRELIABLE);
     173    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE);
    174174  return true;
    175175}
     
    178178  uint8_t *data = packet->data;
    179179  assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
    180   unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
     180  unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
    181181  Packet *p = 0;
    182182//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
     
    185185    case Type::Acknowledgement:
    186186//       COUT(5) << "ack" << std::endl;
    187       p = new Acknowledgement( data, clientID );
     187    p = new Acknowledgement( data, peerID );
    188188      break;
    189189    case Type::Chat:
    190190//       COUT(5) << "chat" << std::endl;
    191       p = new Chat( data, clientID );
     191      p = new Chat( data, peerID );
    192192      break;
    193193    case Type::ClassID:
    194194//       COUT(5) << "classid" << std::endl;
    195       p = new ClassID( data, clientID );
     195      p = new ClassID( data, peerID );
    196196      break;
    197197    case Type::Gamestate:
    198198//       COUT(5) << "gamestate" << std::endl;
    199       p = new Gamestate( data, clientID );
     199      p = new Gamestate( data, peerID );
    200200      break;
    201201    case Type::Welcome:
    202202//       COUT(5) << "welcome" << std::endl;
    203       p = new Welcome( data, clientID );
     203      p = new Welcome( data, peerID );
    204204      break;
    205205    case Type::DeleteObjects:
    206206//       COUT(5) << "deleteobjects" << std::endl;
    207       p = new DeleteObjects( data, clientID );
     207      p = new DeleteObjects( data, peerID );
    208208      break;
    209209    case Type::FunctionCalls:
    210210//       COUT(5) << "functionCalls" << std::endl;
    211       p = new FunctionCalls( data, clientID );
     211      p = new FunctionCalls( data, peerID );
    212212      break;
    213213    case Type::FunctionIDs:
    214214//       COUT(5) << "functionIDs" << std::endl;
    215       p = new FunctionIDs( data, clientID );
     215      p = new FunctionIDs( data, peerID );
    216216      break;
    217217    default:
  • code/branches/network5/src/libraries/network/packet/Packet.h

    r7772 r7777  
    6868    virtual unsigned char *getData(){ return data_; };
    6969    virtual unsigned int getSize() const =0;
    70     virtual bool process()=0;
     70    virtual bool process(orxonox::Host* host)=0;
    7171    inline uint32_t getFlags()
    7272      { return flags_; }
    73     inline int getClientID()
    74       { return clientID_; }
    75     inline void setClientID( int id )
    76       { clientID_ = id; }
     73    inline int getPeerID()
     74      { return peerID_; }
     75    inline void setPeerID( int id )
     76      { peerID_ = id; }
     77    inline bool isReliable()
     78      { return this->flags_ & PacketFlag::Reliable; }
     79    inline uint32_t getRequiredGamestateID()
     80      { return this->requiredGamestateID_; }
    7781
    78     virtual bool send();
     82    virtual bool send(orxonox::Host* host);
    7983  protected:
    8084    Packet();
    81     Packet(uint8_t *data, unsigned int clientID);
     85    Packet(uint8_t *data, unsigned int peerID);
    8286//    Packet(ENetPacket *packet, ENetPeer *peer);
    8387    inline bool isDataENetAllocated() const
     
    8589
    8690    uint32_t flags_;
    87     unsigned int clientID_;
     91    unsigned int peerID_;
     92    uint32_t requiredGamestateID_;
    8893    Direction::Value packetDirection_;
    8994    /** Pointer to the data. Be careful when deleting it because it might
  • code/branches/network5/src/libraries/network/packet/Welcome.cc

    r5781 r7777  
    7373}
    7474
    75 bool Welcome::process(){
     75bool Welcome::process(orxonox::Host* host){
    7676  uint32_t clientID;
    7777  clientID = *(uint32_t *)(data_ + _CLIENTID );
    7878  assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321);
    79   Host::setClientID(clientID);
     79  host->setClientID(clientID);
    8080  COUT(3) << "Welcome set clientId: " << clientID << endl;
    8181  Synchronisable::setClient(true);
  • code/branches/network5/src/libraries/network/packet/Welcome.h

    r6073 r7777  
    4747  uint8_t *getData();
    4848  inline unsigned int getSize() const;
    49   bool process();
     49  virtual bool process(orxonox::Host* host);
    5050
    5151private:
Note: See TracChangeset for help on using the changeset viewer.