Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (9 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/packet/Acknowledgement.cc

    r8858 r11071  
    3838#define PACKET_FLAGS_ACK    0
    3939#define _PACKETID           0
    40 #define _ACKID              _PACKETID + sizeof(packet::Type::Value)
     40#define _ACKID              _PACKETID + sizeof(packet::Type)
    4141
    4242Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID )
     
    4545  flags_ = flags_ | PACKET_FLAGS_ACK;
    4646  data_=new uint8_t[ getSize() ];
    47   *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement;
     47  *(Type *)(data_ + _PACKETID ) = Type::Acknowledgement;
    4848  *(uint32_t *)(data_ + _ACKID ) = id;
    4949  peerID_=peerID;
  • code/trunk/src/libraries/network/packet/Acknowledgement.h

    r7801 r11071  
    4646  ~Acknowledgement();
    4747
    48   inline unsigned int getSize() const;
    49   virtual bool process(orxonox::Host* host);
     48  virtual inline unsigned int getSize() const override;
     49  virtual bool process(orxonox::Host* host) override;
    5050
    5151  unsigned int getAckID();
  • code/trunk/src/libraries/network/packet/Chat.cc

    r8858 r11071  
    4040/* Some lengths */
    4141#define _PACKETID         0
    42 #define _SOURCEID         _PACKETID + sizeof(Type::Value)
     42#define _SOURCEID         _PACKETID + sizeof(Type)
    4343#define _TARGETID         _SOURCEID + sizeof(uint32_t)
    4444#define _MESSAGELENGTH    _TARGETID + sizeof(uint32_t)
     
    5757  data_=new unsigned char[ getSize() ];
    5858
    59   *(Type::Value *)(data_ + _PACKETID ) = Type::Chat;
     59  *(Type *)(data_ + _PACKETID ) = Type::Chat;
    6060  *(unsigned int *)(data_ + _SOURCEID ) = sourceID;
    6161  *(unsigned int *)(data_ + _TARGETID ) = targetID;
  • code/trunk/src/libraries/network/packet/Chat.h

    r8858 r11071  
    4949
    5050  /* get size of packet */
    51   inline unsigned int getSize() const;
     51  virtual inline unsigned int getSize() const override;
    5252
    5353  /* process chat message packet and remove it afterwards */
    54   virtual bool process(orxonox::Host* host);
     54  virtual bool process(orxonox::Host* host) override;
    5555
    5656  /* Get the length of the message (not the full size of the packet) */
  • code/trunk/src/libraries/network/packet/ClassID.cc

    r9667 r11071  
    5252  uint32_t network_id;
    5353  flags_ = flags_ | PACKET_FLAGS_CLASSID;
    54   std::queue<std::pair<uint32_t, std::string> > tempQueue;
     54  std::queue<std::pair<uint32_t, std::string>> tempQueue;
    5555
    5656  //calculate total needed size (for all strings and integers)
    57   std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getInstance().getIdentifierByStringMap().begin();
    58   for(;it != IdentifierManager::getInstance().getIdentifierByStringMap().end();++it){
    59     id = it->second;
    60     if(id == NULL || !id->hasFactory())
     57  for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()){
     58    id = mapEntry.second;
     59    if(id == nullptr || !id->hasFactory())
    6160      continue;
    6261    const std::string& classname = id->getName();
     
    7170  //set the appropriate packet id
    7271  assert(this->data_);
    73   *(Type::Value *)(this->data_ + _PACKETID ) = Type::ClassID;
     72  *(Type *)(this->data_ + _PACKETID ) = Type::ClassID;
    7473
    7574  uint8_t *temp=data_+sizeof(uint32_t);
     
    144143    id=ClassByString( std::string((const char*)classname) );
    145144    orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl;
    146     if(id==NULL){
     145    if(id==nullptr){
    147146      orxout(user_error, context::packets) << "Received a bad classname" << endl;
    148147      abort();
  • code/trunk/src/libraries/network/packet/ClassID.h

    r7801 r11071  
    4747  ~ClassID();
    4848
    49   uint32_t getSize() const;
    50   virtual bool process(orxonox::Host* host);
     49  virtual uint32_t getSize() const override;
     50  virtual bool process(orxonox::Host* host) override;
    5151
    5252private:
  • code/trunk/src/libraries/network/packet/DeleteObjects.cc

    r8858 r11071  
    3939#define PACKET_FLAG_DELETE  PacketFlag::Reliable
    4040#define _PACKETID           0
    41 #define _QUANTITY           _PACKETID + sizeof(Type::Value)
     41#define _QUANTITY           _PACKETID + sizeof(Type)
    4242#define _OBJECTIDS          _QUANTITY + sizeof(uint32_t)
    4343
     
    6363    return false;
    6464  orxout(verbose, context::packets) << "sending DeleteObjects: ";
    65   unsigned int size = sizeof(Type::Value) + sizeof(uint32_t)*(number+1);
     65  unsigned int size = sizeof(Type) + sizeof(uint32_t)*(number+1);
    6666  data_ = new uint8_t[size];
    6767  uint8_t *tdata = data_;
    68   *reinterpret_cast<Type::Value*>(tdata) = Type::DeleteObjects;
    69   tdata += sizeof(Type::Value);
     68  *reinterpret_cast<Type*>(tdata) = Type::DeleteObjects;
     69  tdata += sizeof(Type);
    7070  *(uint32_t *)tdata = number;
    7171  tdata += sizeof(uint32_t);
  • code/trunk/src/libraries/network/packet/DeleteObjects.h

    r7801 r11071  
    4848  bool fetchIDs();
    4949
    50   inline unsigned int getSize() const;
    51   virtual bool process(orxonox::Host* host);
     50  virtual inline unsigned int getSize() const override;
     51  virtual bool process(orxonox::Host* host) override;
    5252
    5353private:
  • code/trunk/src/libraries/network/packet/FunctionCalls.cc

    r10624 r11071  
    9696  assert(this->functionCalls_.size());
    9797  data_=new uint8_t[ currentSize_ ];
    98   *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID
     98  *(Type *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID
    9999  *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls
    100100  *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_
  • code/trunk/src/libraries/network/packet/FunctionCalls.h

    r10624 r11071  
    5252  ~FunctionCalls();
    5353
    54   inline unsigned int getSize() const
     54  virtual inline unsigned int getSize() const override
    5555    { assert(!this->isDataENetAllocated()); return currentSize_; }
    56   virtual bool process(orxonox::Host* host);
     56  virtual bool process(orxonox::Host* host) override;
    5757
    5858  void addCall( uint32_t networkID, uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
    59   virtual bool send(orxonox::Host* host);
     59  virtual bool send(orxonox::Host* host) override;
    6060private:
    6161  std::queue<orxonox::FunctionCall> functionCalls_;
  • code/trunk/src/libraries/network/packet/FunctionIDs.cc

    r10624 r11071  
    5353  uint32_t networkID;
    5454  flags_ = flags_ | PACKET_FLAGS_FUNCTIONIDS;
    55   std::queue<std::pair<uint32_t, std::string> > tempQueue;
     55  std::queue<std::pair<uint32_t, std::string>> tempQueue;
    5656
    5757  //calculate total needed size (for all strings and integers)
     
    7171  //set the appropriate packet id
    7272  assert(this->data_);
    73   *(Type::Value *)(this->data_ + _PACKETID ) = Type::FunctionIDs;
     73  *(Type *)(this->data_ + _PACKETID ) = Type::FunctionIDs;
    7474
    7575  uint8_t *temp=data_+sizeof(uint32_t);
  • code/trunk/src/libraries/network/packet/FunctionIDs.h

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

    r9667 r11071  
    106106{
    107107  uint32_t tempsize=0, currentsize=0;
    108   assert(data_==0);
     108  assert(data_==nullptr);
    109109  uint32_t size = calcGamestateSize(id, mode);
    110110
     
    126126  mem += GamestateHeader::getSize();
    127127  ObjectList<Synchronisable>::iterator it;
    128   for(it = ObjectList<Synchronisable>::begin(); it; ++it)
     128  for(it = ObjectList<Synchronisable>().begin(); it; ++it)
    129129  {
    130130
     
    133133    tempsize = it->getData(mem, this->sizes_, id, mode);
    134134    if ( tempsize != 0 )
    135       dataVector_.push_back( obj(it->getObjectID(), it->getContextID(), tempsize, mem-data_) );
     135      dataVector_.emplace_back(it->getObjectID(), it->getContextID(), tempsize, mem-data_);
    136136
    137137#ifndef NDEBUG
     
    213213  {
    214214    std::list<uint32_t> v1;
    215     ObjectList<Synchronisable>::iterator it;
    216     for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it)
    217     {
    218       if (it->getObjectID() == OBJECTID_UNKNOWN)
    219       {
    220         if (it->objectMode_ != 0x0)
     215    for (Synchronisable* synchronisable : ObjectList<Synchronisable>())
     216    {
     217      if (synchronisable->getObjectID() == OBJECTID_UNKNOWN)
     218      {
     219        if (synchronisable->objectMode_ != 0x0)
    221220        {
    222221          orxout(user_error, context::packets) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << endl;
    223222          orxout(user_error, context::packets) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << endl;
    224           orxout(user_error, context::packets) << "Objects class: " << it->getIdentifier()->getName() << endl;
     223          orxout(user_error, context::packets) << "Objects class: " << synchronisable->getIdentifier()->getName() << endl;
    225224          assert(false);
    226225        }
     
    228227      else
    229228      {
    230         std::list<uint32_t>::iterator it2;
    231         for (it2 = v1.begin(); it2 != v1.end(); ++it2)
     229        for (uint32_t id : v1)
    232230        {
    233           if (it->getObjectID() == *it2)
     231          if (synchronisable->getObjectID() == id)
    234232          {
    235233            orxout(user_error, context::packets) << "Found duplicate objectIDs on the client!" << endl
     
    239237          }
    240238        }
    241         v1.push_back(it->getObjectID());
     239        v1.push_back(synchronisable->getObjectID());
    242240      }
    243241    }
     
    608606
    609607  if(dest_length==0)
    610     return NULL;
     608    return nullptr;
    611609
    612610  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     
    645643
    646644  if(dest_length==0)
    647     return NULL;
     645    return nullptr;
    648646
    649647  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     
    762760  uint32_t size = 0;
    763761  uint32_t nrOfVariables = 0;
    764     // get the start of the Synchronisable list
    765   ObjectList<Synchronisable>::iterator it;
    766762    // get total size of gamestate
    767   for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    768     size+=it->getSize(id, mode); // size of the actual data of the synchronisable
    769     nrOfVariables += it->getNrOfVariables();
     763  for(Synchronisable* synchronisable : ObjectList<Synchronisable>()){
     764    size+=synchronisable->getSize(id, mode); // size of the actual data of the synchronisable
     765    nrOfVariables += synchronisable->getNrOfVariables();
    770766  }
    771767//   orxout() << "allocating " << nrOfVariables << " ints" << endl;
  • code/trunk/src/libraries/network/packet/Gamestate.h

    r7801 r11071  
    4848{
    4949   
    50 static const uint8_t GAMESTATE_MODE_SERVER = 0x1;
    51 static const uint8_t GAMESTATE_MODE_CLIENT = 0x2;
     50static constexpr uint8_t GAMESTATE_MODE_SERVER = 0x1;
     51static constexpr uint8_t GAMESTATE_MODE_CLIENT = 0x2;
    5252
    5353class _NetworkExport GamestateHeader
    5454{
    5555  public:
    56     GamestateHeader(){ data_=0; }
     56    GamestateHeader(){ data_=nullptr; }
    5757    GamestateHeader(uint8_t* data)
    58       { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
     58      { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; }
    5959    /*GamestateHeader(uint8_t* data, GamestateHeader* h)
    6060      { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/
    6161    void setData(uint8_t* data)
    62       { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; }
     62      { assert(data); data_ = data; *(Type*)data_ = Type::Gamestate; }
    6363    static inline uint32_t getSize()
    6464      { return 21; }
     
    138138//     void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
    139139//     inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );
    140     virtual uint32_t getSize() const;
    141     virtual bool process(orxonox::Host* host);
     140    virtual uint32_t getSize() const override;
     141    virtual bool process(orxonox::Host* host) override;
    142142    uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0);
    143143//     inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes );
  • code/trunk/src/libraries/network/packet/Packet.cc

    r8858 r11071  
    3434#define WIN32_LEAN_AND_MEAN
    3535#include <enet/enet.h>
    36 #include <boost/static_assert.hpp>
    3736#include <boost/thread/mutex.hpp>
    3837
     
    5453
    5554// Make sure we assume the right values
    56 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable)    == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));
    57 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));
    58 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate)  == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));
     55static_assert(static_cast<int>(PacketFlag::Reliable)    == static_cast<int>(ENET_PACKET_FLAG_RELIABLE),    "check enum");
     56static_assert(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED), "check enum");
     57static_assert(static_cast<int>(PacketFlag::NoAllocate)  == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE), "check enum");
    5958
    6059#define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate
     
    6968  packetDirection_ = Direction::Outgoing;
    7069  peerID_=0;
    71   data_=0;
    72   enetPacket_=0;
     70  data_=nullptr;
     71  enetPacket_=nullptr;
    7372  bDataENetAllocated_ = false;
    7473}
     
    8079  peerID_=peerID;
    8180  data_=data;
    82   enetPacket_=0;
     81  enetPacket_=nullptr;
    8382  bDataENetAllocated_ = false;
    8483}
     
    9594    memcpy(data_, p.data_, p.getSize());
    9695  }else
    97     data_=0;
     96    data_=nullptr;
    9897  bDataENetAllocated_ = p.bDataENetAllocated_;
    9998}
     
    122121  // Destroy the ENetPacket if necessary.
    123122  // Note: For the case ENet used the callback to destroy the packet, we have already set
    124   // enetPacket_ to NULL to avoid destroying it again.
     123  // enetPacket_ to nullptr to avoid destroying it again.
    125124  if (this->enetPacket_)
    126125  {
     
    158157  }
    159158#ifndef NDEBUG
    160   switch( *(Type::Value *)(data_ + _PACKETID) )
     159  switch( *(Type *)(data_ + _PACKETID) )
    161160  {
    162161    case Type::Acknowledgement:
     
    175174#endif
    176175//  ENetPacket *temp = enetPacket_;
    177 //  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
     176//  enetPacket_ = nullptr; // otherwise we have a double free because enet already handles the deallocation of the packet
    178177  if( this->flags_ & PacketFlag::Reliable )
    179178    host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT);
     
    191190//   if( peerID==static_cast<unsigned int>(-2))
    192191//     peerID = NETWORK_PEER_ID_SERVER;
    193   Packet *p = 0;
    194 //   orxout(verbose_ultra, context::packets) << "packet type: " << *(Type::Value *)&data[_PACKETID] << endl;
    195   switch( *(Type::Value *)(data + _PACKETID) )
     192  Packet *p = nullptr;
     193//   orxout(verbose_ultra, context::packets) << "packet type: " << *(Type *)&data[_PACKETID] << endl;
     194  switch( *(Type *)(data + _PACKETID) )
    196195  {
    197196    case Type::Acknowledgement:
     
    251250  assert(it != packetMap_.end());
    252251  // Make sure we don't delete it again in the destructor
    253   it->second->enetPacket_ = 0;
     252  it->second->enetPacket_ = nullptr;
    254253  delete it->second;
    255254  packetMap_.erase(it);
  • code/trunk/src/libraries/network/packet/Packet.h

    r8327 r11071  
    3838{
    3939
    40 namespace Direction
     40enum class Direction
    4141{
    42   enum Value
    43   {
    44     Incoming,
    45     Outgoing,
    46     Bidirectional
    47   };
    48 }
    49 namespace Type
     42  Incoming,
     43  Outgoing,
     44  Bidirectional
     45};
     46enum class Type : uint8_t
    5047{
    51   enum Value
    52   {
    53     Acknowledgement,
    54     Chat,
    55     ClassID,
    56     DeleteObjects,
    57     FunctionIDs,
    58     FunctionCalls,
    59     Gamestate,
    60     Welcome
    61   };
    62 }
     48  Acknowledgement,
     49  Chat,
     50  ClassID,
     51  DeleteObjects,
     52  FunctionIDs,
     53  FunctionCalls,
     54  Gamestate,
     55  Welcome
     56};
    6357
    6458/**
     
    9892    unsigned int peerID_;
    9993    uint32_t requiredGamestateID_;
    100     Direction::Value packetDirection_;
     94    Direction packetDirection_;
    10195    /** Pointer to the data. Be careful when deleting it because it might
    10296        point to a location that was allocated by ENet.
  • code/trunk/src/libraries/network/packet/ServerInformation.cc

    r10622 r11071  
    8787  } // namespace packet
    8888
    89   std::ostream& operator<<(std::ostream& out, const ENetAddress& address)
    90   {
    91       char addr[64];
    92       if (!enet_address_get_host_ip(&address, addr, 64))
    93           out << addr;
    94       return out;
    95   }
    9689} // namespace orxonox
     90
     91std::ostream& operator<<(std::ostream& out, const ENetAddress& address)
     92{
     93    char addr[64];
     94    if (!enet_address_get_host_ip(&address, addr, 64))
     95        out << addr;
     96    return out;
     97}
  • code/trunk/src/libraries/network/packet/ServerInformation.h

    r10622 r11071  
    5050        void          send( ENetPeer* peer );
    5151        void          setServerName(std::string name) { this->serverName_ = name; }
    52         std::string   getServerName() { return this->serverName_; }
     52        std::string   getServerName() const { return this->serverName_; }
    5353        void          setServerIP( std::string IP ) { this->serverIP_ = IP; }
    54         std::string   getServerIP() { return this->serverIP_; }
     54        std::string   getServerIP() const { return this->serverIP_; }
    5555        void          setClientNumber( int clientNumber ) { this->clientNumber_ = clientNumber; }
    56         int           getClientNumber() { return this->clientNumber_; }
    57         uint32_t      getServerRTT() { return this->serverRTT_; }
     56        int           getClientNumber() const { return this->clientNumber_; }
     57        uint32_t      getServerRTT() const { return this->serverRTT_; }
    5858
    5959      private:
     
    6666  }
    6767
    68   _NetworkExport std::ostream& operator<<(std::ostream& out, const ENetAddress& address);
    6968}
    7069
     70_NetworkExport std::ostream& operator<<(std::ostream& out, const ENetAddress& address);
     71
    7172#endif // SERVERINFORMATION_H
  • code/trunk/src/libraries/network/packet/Welcome.cc

    r8858 r11071  
    4141#define PACKET_FLAGS_CLASSID  PacketFlag::Reliable
    4242#define _PACKETID             0
    43 #define _CLIENTID             _PACKETID + sizeof(Type::Value)
     43#define _CLIENTID             _PACKETID + sizeof(Type)
    4444#define _ENDIANTEST           _CLIENTID + sizeof(uint32_t)
    4545
     
    5151  data_=new uint8_t[ getSize() ];
    5252  assert(data_);
    53   *(packet::Type::Value *)(data_ + _PACKETID ) = packet::Type::Welcome;
     53  *(packet::Type *)(data_ + _PACKETID ) = packet::Type::Welcome;
    5454  *(uint32_t *)(data_ + _CLIENTID ) = static_cast<uint32_t>(clientID);
    5555  *(uint32_t *)(data_ + _ENDIANTEST ) = 0xFEDC4321;
     
    7070
    7171unsigned int Welcome::getSize() const{
    72   return sizeof(packet::Type::Value) + 2*sizeof(uint32_t);
     72  return sizeof(packet::Type) + 2*sizeof(uint32_t);
    7373}
    7474
  • code/trunk/src/libraries/network/packet/Welcome.h

    r8706 r11071  
    4545  virtual ~Welcome();
    4646
    47   uint8_t *getData();
    48   inline unsigned int getSize() const;
    49   virtual bool process(orxonox::Host* host);
     47  virtual uint8_t *getData() override;
     48  virtual inline unsigned int getSize() const override;
     49  virtual bool process(orxonox::Host* host) override;
    5050
    5151private:
Note: See TracChangeset for help on using the changeset viewer.