Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 10, 2008, 12:05:03 AM (16 years ago)
Author:
landauf
Message:

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

Location:
code/trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r1907 r2171  
    3333#include "core/CoreIncludes.h"
    3434
    35 namespace network {
     35namespace orxonox {
    3636namespace packet {
    3737
    3838#define PACKET_FLAGS_ACK    0
    3939#define _PACKETID           0
    40 #define _ACKID              _PACKETID + sizeof(network::packet::ENUM::Type)
     40#define _ACKID              _PACKETID + sizeof(packet::ENUM::Type)
    4141 
    4242Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
     
    7474
    7575} //namespace packet
    76 } //namespace network
     76} //namespace orxonox
  • code/trunk/src/network/packet/Acknowledgement.h

    r2087 r2171  
    3333
    3434
    35 namespace network {
     35namespace orxonox {
    3636namespace packet {
    3737/**
     
    5353
    5454} //namespace packet
    55 } //namespace network
     55} //namespace orxonox
    5656
    5757#endif
  • code/trunk/src/network/packet/Chat.cc

    r1907 r2171  
    3131#include "network/Host.h"
    3232
    33 namespace network {
     33namespace orxonox {
    3434namespace packet {
    3535 
     
    7777
    7878} //namespace packet
    79 } //namespace network
     79} //namespace orxonox
  • code/trunk/src/network/packet/Chat.h

    r2087 r2171  
    1010#include "Packet.h"
    1111
    12 namespace network {
     12namespace orxonox {
    1313namespace packet {
    1414/**
     
    3333
    3434} //namespace packet
    35 } //namespace network
     35} //namespace orxonox
    3636
    3737#endif
  • code/trunk/src/network/packet/ClassID.cc

    r1907 r2171  
    3434#include <assert.h>
    3535
    36 namespace network {
     36namespace orxonox {
    3737namespace packet {
    3838
     
    6868
    6969unsigned int ClassID::getSize() const{
    70   return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;
     70  return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t) + classNameLength_;
    7171}
    7272
    7373bool ClassID::process(){
    7474  COUT(3) << "processing classid: " << getClassID() << " name: " << (const char*)(data_+_CLASSNAME) << std::endl;
    75   orxonox::Identifier *id=ClassByID( std::string((const char*)(data_+_CLASSNAME) ));
     75  Identifier *id=ClassByID( std::string((const char*)(data_+_CLASSNAME) ));
    7676  if(id==NULL)
    7777    return false;
     
    8686
    8787} //namespace packet
    88 }//namespace network
     88}//namespace orxonox
  • code/trunk/src/network/packet/ClassID.h

    r2087 r2171  
    3535#include "Packet.h"
    3636
    37 namespace network {
     37namespace orxonox {
    3838namespace packet {
    3939
     
    5959
    6060} //namespace packet
    61 } //namespace network
     61} //namespace orxonox
    6262
    6363#endif
  • code/trunk/src/network/packet/DeleteObjects.cc

    r1907 r2171  
    3434#include <assert.h>
    3535
    36 namespace network {
     36namespace orxonox {
    3737namespace packet {
    3838
     
    9595
    9696} //namespace packet
    97 } //namespace network
     97} //namespace orxonox
  • code/trunk/src/network/packet/DeleteObjects.h

    r2087 r2171  
    3434
    3535
    36 namespace network {
     36namespace orxonox {
    3737namespace packet {
    3838/**
     
    5555
    5656} //namespace packet
    57 } //namespace network
     57} //namespace orxonox
    5858
    5959#endif
  • code/trunk/src/network/packet/Gamestate.cc

    r2087 r2171  
    3838
    3939
    40 namespace network {
     40namespace orxonox {
    4141
    4242namespace packet {
     
    7171}
    7272
    73 bool Gamestate::collectData(int id, int mode)
    74 {
    75   int tempsize=0, currentsize=0;
     73bool Gamestate::collectData(int id, uint8_t mode)
     74{
     75  unsigned int tempsize=0, currentsize=0;
    7676  assert(data_==0);
    77   int size = calcGamestateSize(id, mode);
     77  unsigned int size = calcGamestateSize(id, mode);
    7878
    7979  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
     
    8686  }
    8787
    88 #ifndef NDEBUG
    89   std::list<Synchronisable*> slist;
    90   std::list<Synchronisable*>::iterator iit;
    91 #endif
    9288  //start collect data synchronisable by synchronisable
    9389  uint8_t *mem=data_;
    9490  mem+=sizeof(GamestateHeader);
    95   orxonox::ObjectList<Synchronisable>::iterator it;
    96   for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
     91  ObjectList<Synchronisable>::iterator it;
     92  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    9793    tempsize=it->getSize(id, mode);
    9894
    9995    if(currentsize+tempsize > size){
     96      assert(0); // if we don't use multithreading this part shouldn't be neccessary
    10097      // start allocate additional memory
    10198      COUT(3) << "G.St.Man: need additional memory" << std::endl;
    102       orxonox::ObjectList<Synchronisable>::iterator temp = it;
     99      ObjectList<Synchronisable>::iterator temp = it;
    103100      int addsize=tempsize;
    104101      while(++temp)
     
    110107    }// stop allocate additional memory
    111108
    112 #ifndef NDEBUG
    113     for(iit=slist.begin(); iit!=slist.end(); iit++)
    114       assert((*iit)!=*it);
    115     slist.push_back(*it);
    116 #endif
    117109
    118110    //if(it->doSelection(id))
     
    127119  //start write gamestate header
    128120  HEADER->packetType = ENUM::Gamestate;
    129   assert( *(ENUM::Type *)(data_) == ENUM::Gamestate);
    130121  HEADER->datasize = currentsize;
    131122  HEADER->id = id;
     
    140131}
    141132
    142 bool Gamestate::spreadData(int mode)
     133bool Gamestate::spreadData(uint8_t mode)
    143134{
    144135  assert(data_);
     
    147138  uint8_t *mem=data_+sizeof(GamestateHeader);
    148139    // get the start of the Synchronisable list
    149   //orxonox::ObjectList<Synchronisable>::iterator it=orxonox::ObjectList<Synchronisable>::begin();
     140  //ObjectList<Synchronisable>::iterator it=ObjectList<Synchronisable>::begin();
    150141  Synchronisable *s;
    151142
     
    163154      bool b = s->updateData(mem, mode);
    164155      assert(b);
    165       //if(!s->updateData(mem, mode))
    166         //return false;
    167156    }
    168157  }
     
    367356    assert(it->second->objectID==oldobjectheader->objectID);
    368357    *newobjectheader = *oldobjectheader;
    369     objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableData variables in the objectheader
     358    objectOffset=sizeof(synchronisableHeader); //skip the size and the availableData variables in the objectheader
    370359    if(it->second->doSelection(HEADER->id)){
    371       newobjectheader->dataAvailable=true; //TODO: probably not neccessary
    372       while(objectOffset<objectsize){
    373         *(newdata + objectOffset)=*(origdata + objectOffset);    // copy the data
    374         objectOffset++;
    375       }
     360      assert(newobjectheader->dataAvailable==true);
     361      memcpy(newdata+objectOffset, origdata+objectOffset, objectsize-objectOffset);
    376362    }else{
    377363      newobjectheader->dataAvailable=false;
    378       while(objectOffset<objectsize){
    379         *(newdata+objectOffset)=0;    // set to 0
    380         objectOffset++;
    381       }
     364      memset(newdata+objectOffset, 0, objectsize-objectOffset);
    382365      assert(objectOffset==objectsize);
    383366    }
     
    565548
    566549
    567 unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode)
    568 {
    569   int size=0;
     550unsigned int Gamestate::calcGamestateSize(unsigned int id, uint8_t mode)
     551{
     552  unsigned int size=0;
    570553    // get the start of the Synchronisable list
    571   orxonox::ObjectList<Synchronisable>::iterator it;
     554  ObjectList<Synchronisable>::iterator it;
    572555    // get total size of gamestate
    573   for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it)
     556  for(it = ObjectList<Synchronisable>::begin(); it; ++it)
    574557    size+=it->getSize(id, mode); // size of the actual data of the synchronisable
    575558//  size+=sizeof(GamestateHeader);
     
    582565 * @return iterator pointing to the next object in the list
    583566 */
    584   void Gamestate::removeObject(orxonox::ObjectList<Synchronisable>::iterator &it) {
    585     orxonox::ObjectList<Synchronisable>::iterator temp=it;
     567  void Gamestate::removeObject(ObjectList<Synchronisable>::iterator &it) {
     568    ObjectList<Synchronisable>::iterator temp=it;
    586569    ++it;
    587570    delete  *temp;
  • code/trunk/src/network/packet/Gamestate.h

    r2087 r2171  
    4040#endif
    4141
    42 namespace network {
     42namespace orxonox {
    4343
    4444namespace packet {
     
    6969    ~Gamestate();
    7070
    71     bool collectData(int id, int mode=0x0);
    72     bool spreadData(int mode=0x0);
     71    bool collectData(int id, uint8_t mode=0x0);
     72    bool spreadData( uint8_t mode=0x0);
    7373    int getID();
    7474    bool isDiffed();
     
    9090    bool operator ==(packet::Gamestate gs);
    9191  private:
    92     unsigned int calcGamestateSize(unsigned int id, int mode=0x0);
    93     void removeObject(orxonox::ObjectListIterator<Synchronisable> &it);
     92    unsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);
     93    void removeObject(ObjectListIterator<Synchronisable> &it);
    9494    std::map<unsigned int, Synchronisable*> dataMap_;
    9595};
  • code/trunk/src/network/packet/Packet.cc

    r2087 r2171  
    4646#include "core/CoreIncludes.h"
    4747
    48 namespace network{
     48namespace orxonox{
    4949
    5050namespace packet{
     
    5353#define _PACKETID           0
    5454
    55 std::map<ENetPacket *, Packet *> Packet::packetMap_;
     55std::map<size_t, Packet *> Packet::packetMap_;
     56boost::recursive_mutex Packet::packetMap_mutex;
    5657
    5758Packet::Packet(){
     
    128129      return false;
    129130    }
     131    // Assures we don't create a packet and destroy it right after in another thread
     132    // without having a reference in the packetMap_
     133    boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex);
    130134    // We deliver ENet the data address so that it doesn't memcpy everything again.
    131135    // --> We have to delete data_ ourselves!
     
    134138    // Add the packet to a global list so we can access it again once enet calls our
    135139    // deletePacket method. We can of course only give a one argument function to the ENet C library.
    136     packetMap_[enetPacket_] = this;
     140    packetMap_[(size_t)(void*)enetPacket_] = this;
    137141  }
    138142#ifndef NDEBUG
     
    153157//  ENetPacket *temp = enetPacket_;
    154158//  enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet
    155   network::Host::addPacket( enetPacket_, clientID_);
     159  Host::addPacket( enetPacket_, clientID_);
    156160  return true;
    157161}
     
    207211*/
    208212void Packet::deletePacket(ENetPacket *enetPacket){
     213  boost::recursive_mutex::scoped_lock lock(Packet::packetMap_mutex);
    209214  // Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
    210   std::map<ENetPacket*, Packet*>::iterator it = packetMap_.find(enetPacket);
     215  std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket);
    211216  assert(it != packetMap_.end());
    212217  // Make sure we don't delete it again in the destructor
    213218  it->second->enetPacket_ = 0;
    214219  delete it->second;
    215   //packetMap_.erase(it);
     220  packetMap_.erase(it);
    216221  COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl;
    217222}
     
    219224} // namespace packet
    220225
    221 } // namespace network
    222 
     226} // namespace orxonox
     227
  • code/trunk/src/network/packet/Packet.h

    r2087 r2171  
    2929#define NETWORKPACKET_H
    3030
    31 #include "../NetworkPrereqs.h"
     31#include "network/NetworkPrereqs.h"
    3232
    3333#include <map>
    3434#include <enet/enet.h>
     35#include <boost/thread/recursive_mutex.hpp>
    3536
    3637#include "util/Integers.h"
    3738
    38 namespace network {
     39namespace orxonox {
    3940
    4041namespace packet{
     
    9293    bool bDataENetAllocated_;
    9394  private:
    94     static std::map<ENetPacket *, Packet *> packetMap_;
     95    static std::map<size_t, Packet *> packetMap_;
     96    //! Static mutex for any packetMap_ access
     97    static boost::recursive_mutex packetMap_mutex;
    9598    ENetPacket *enetPacket_;
    9699};
     
    98101} //namespace packet
    99102
    100 } //namespace network
     103} //namespace orxonox
    101104
    102105#endif
  • code/trunk/src/network/packet/Welcome.cc

    r1907 r2171  
    3636#include <assert.h>
    3737
    38 namespace network {
     38namespace orxonox {
    3939namespace packet {
    4040
     
    7070
    7171unsigned int Welcome::getSize() const{
    72   return sizeof(network::packet::ENUM::Type) + 2*sizeof(uint32_t);
     72  return sizeof(packet::ENUM::Type) + 2*sizeof(uint32_t);
    7373}
    7474
     
    8787
    8888} //namespace packet
    89 }//namespace network
     89}//namespace orxonox
  • code/trunk/src/network/packet/Welcome.h

    r2087 r2171  
    3333#include "Packet.h"
    3434
    35 namespace network {
     35namespace orxonox {
    3636namespace packet {
    3737
     
    5454
    5555} //namespace packet
    56 } //namespace network
     56} //namespace orxonox
    5757
    5858#endif
Note: See TracChangeset for help on using the changeset viewer.