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:
43 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/network/ChatListener.cc

    r2087 r2171  
    3232#include "core/Core.h"
    3333
    34 namespace network
     34namespace orxonox
    3535{
    3636    ChatListener::ChatListener()
  • code/trunk/src/network/ChatListener.h

    r2087 r2171  
    3535#include "core/OrxonoxClass.h"
    3636
    37 namespace network
     37namespace orxonox
    3838{
    39     class _NetworkExport ChatListener : virtual public orxonox::OrxonoxClass
     39    class _NetworkExport ChatListener : virtual public OrxonoxClass
    4040    {
    4141        public:
  • code/trunk/src/network/Client.cc

    r2087 r2171  
    4949// #include "packet/Acknowledgement.h"
    5050
    51 namespace network
     51namespace orxonox
    5252{
    5353//   SetConsoleCommandShortcut(Client, chat);
  • code/trunk/src/network/Client.h

    r2087 r2171  
    5454
    5555
    56 namespace network
     56namespace orxonox
    5757{
    5858  /**
    59   network::Client *client;
     59  Client *client;
    6060  * The network/Client class
    6161  * This class implements all necessary function for the network communication
  • code/trunk/src/network/ClientConnection.cc

    r2087 r2171  
    4848#include "util/Debug.h"
    4949
    50 namespace network
     50namespace orxonox
    5151{
    5252  //static boost::thread_group network_threads;
  • code/trunk/src/network/ClientConnection.h

    r2087 r2171  
    5050namespace boost { class thread; }
    5151
    52 namespace network
     52namespace orxonox
    5353{
    5454
  • code/trunk/src/network/ClientConnectionListener.cc

    r2087 r2171  
    33#include "core/Core.h"
    44
    5 namespace network{
     5namespace orxonox{
    66
    77  ClientConnectionListener::ClientConnectionListener()
     
    1111
    1212  void ClientConnectionListener::getConnectedClients(){
    13     if(orxonox::Core::showsGraphics())
     13    if(Core::showsGraphics())
    1414      this->clientConnected(0); //server client id
    1515    ClientInformation *client = ClientInformation::getBegin();
  • code/trunk/src/network/ClientConnectionListener.h

    r2087 r2171  
    66#include "core/OrxonoxClass.h"
    77
    8 namespace network{
     8namespace orxonox{
    99
    10   class _NetworkExport ClientConnectionListener : virtual public orxonox::OrxonoxClass
     10  class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass
    1111  {
    1212    friend class Server;
  • code/trunk/src/network/ClientInformation.cc

    r2087 r2171  
    4343#include <iostream> //debug
    4444
    45 namespace network
     45namespace orxonox
    4646{
    4747
  • code/trunk/src/network/ClientInformation.h

    r2087 r2171  
    4848// WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE
    4949
    50 namespace network
     50namespace orxonox
    5151{
    5252  static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
  • code/trunk/src/network/ConnectionManager.cc

    r2087 r2171  
    6565}
    6666
    67 namespace network
     67namespace orxonox
    6868{
    6969  //boost::thread_group network_threads;
     
    138138
    139139  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
    140     boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
     140    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    141141    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
    142142      return false;
     
    156156    if(!instance_)
    157157      return false;
    158     boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
     158    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    159159    for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){
    160160      COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl;
     
    169169    if(server==NULL || !instance_)
    170170      return false;
    171     boost::recursive_mutex::scoped_lock lock(enet_mutex);
     171    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    172172    enet_host_flush(server);
    173173    lock.unlock();
     
    180180    atexit(enet_deinitialize);
    181181    { //scope of the mutex
    182       boost::recursive_mutex::scoped_lock lock(enet_mutex);
     182      boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    183183      enet_initialize();
    184184      server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
     
    194194    while(!quit){
    195195      { //mutex scope
    196         boost::recursive_mutex::scoped_lock lock(enet_mutex);
     196        boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    197197        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    198198          // we should never reach this point
     
    236236    // if we're finishied, destroy server
    237237    {
    238       boost::recursive_mutex::scoped_lock lock(enet_mutex);
     238      boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    239239      enet_host_destroy(server);
    240240      lock.unlock();
     
    250250    while(temp!=0){
    251251      {
    252         boost::recursive_mutex::scoped_lock lock(enet_mutex);
     252        boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    253253        enet_peer_disconnect(temp->getPeer(), 0);
    254254        lock.unlock();
     
    258258    //bugfix: might be the reason why server crashes when clients disconnects
    259259    temp = ClientInformation::getBegin()->next();
    260     boost::recursive_mutex::scoped_lock lock(enet_mutex);
     260    boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    261261    while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
    262262      switch (event.type)
     
    306306    unsigned int network_id=0, failures=0;
    307307    std::string classname;
    308     orxonox::Identifier *id;
    309     std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryMapBegin();
    310     while(it != orxonox::Factory::getFactoryMapEnd()){
     308    Identifier *id;
     309    std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();
     310    while(it != Factory::getFactoryMapEnd()){
    311311      id = (*it).second;
    312312      if(id == NULL)
     
    332332  void ConnectionManager::disconnectClient(ClientInformation *client){
    333333    {
    334       boost::recursive_mutex::scoped_lock lock(enet_mutex);
     334      boost::recursive_mutex::scoped_lock lock(ConnectionManager::enet_mutex);
    335335      enet_peer_disconnect(client->getPeer(), 0);
    336336      lock.unlock();
  • code/trunk/src/network/ConnectionManager.h

    r2087 r2171  
    5959}
    6060
    61 namespace network
     61namespace orxonox
    6262{
    6363    const int NETWORK_PORT = 55556;
  • code/trunk/src/network/GamestateClient.cc

    r2087 r2171  
    3939
    4040
    41 namespace network
     41namespace orxonox
    4242{
    4343  struct _NetworkExport GameStateItem{
     
    9494  * @return iterator pointing to the next object in the list
    9595  */
    96   void GamestateClient::removeObject(orxonox::ObjectList<Synchronisable>::iterator &it) {
    97     orxonox::ObjectList<Synchronisable>::iterator temp=it;
     96  void GamestateClient::removeObject(ObjectList<Synchronisable>::iterator &it) {
     97    ObjectList<Synchronisable>::iterator temp=it;
    9898    ++it;
    9999    delete  *temp;
  • code/trunk/src/network/GamestateClient.h

    r2087 r2171  
    5050const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1;
    5151
    52 namespace network
     52namespace orxonox
    5353{
    5454  class _NetworkExport GamestateClient: public GamestateHandler
     
    6666  private:
    6767    packet::Gamestate *processGamestate(packet::Gamestate *gs);
    68     void removeObject(orxonox::ObjectListIterator<Synchronisable> &it);
     68    void removeObject(ObjectListIterator<Synchronisable> &it);
    6969    void printGamestateMap();
    7070    bool sendAck(unsigned int gamestateID);
  • code/trunk/src/network/GamestateHandler.cc

    r1763 r2171  
    44#include "packet/Packet.h"
    55
    6 namespace network {
     6namespace orxonox {
    77
    88GamestateHandler *GamestateHandler::instance_=0;
     
    2222
    2323
    24 }//namespace network
     24}//namespace orxonox
  • code/trunk/src/network/GamestateHandler.h

    r2087 r2171  
    3434#include "packet/Chat.h"
    3535
    36 namespace network {
     36namespace orxonox {
    3737
    3838/**
  • code/trunk/src/network/GamestateManager.cc

    r2087 r2171  
    5151#include "Synchronisable.h"
    5252
    53 namespace network
     53namespace orxonox
    5454{
    5555  GamestateManager::GamestateManager() {
  • code/trunk/src/network/GamestateManager.h

    r2087 r2171  
    4747#include "packet/Gamestate.h"
    4848
    49 namespace network
     49namespace orxonox
    5050{
    5151
  • code/trunk/src/network/Host.cc

    r2087 r2171  
    3434#include "ChatListener.h"
    3535
    36 namespace network {
     36namespace orxonox {
    3737
    3838SetConsoleCommandShortcut(Host, Chat);
     
    8080// }
    8181
    82 // bool Host::receiveChat(network::packet::Chat *message, unsigned int clientID){
     82// bool Host::receiveChat(packet::Chat *message, unsigned int clientID){
    8383//   if(instance_)
    8484//     return instance_->processChat(message, clientID);
     
    110110
    111111bool Host::incomingChat(const std::string& message, unsigned int playerID){
    112   for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it)
     112  for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    113113    it->incomingChat(message, playerID);
    114114
     
    116116}
    117117
    118 }//namespace network
     118}//namespace orxonox
  • code/trunk/src/network/Host.h

    r2087 r2171  
    3434#include "packet/Chat.h"
    3535
    36 namespace network {
     36namespace orxonox {
    3737
    3838/**
  • code/trunk/src/network/NetworkCallback.h

    r2087 r2171  
    44#include "NetworkPrereqs.h"
    55
    6 namespace network{
     6namespace orxonox{
    77  class _NetworkExport NetworkCallbackBase
    88  {
  • code/trunk/src/network/NetworkPrereqs.h

    r2087 r2171  
    5959// Forward declarations
    6060//-----------------------------------------------------------------------
    61 namespace network
     61namespace orxonox
    6262{
    6363  class Client;
  • code/trunk/src/network/PacketBuffer.cc

    r1505 r2171  
    3939#include <boost/thread/mutex.hpp>
    4040
    41 namespace network
     41namespace orxonox
    4242{
    4343   boost::recursive_mutex PacketBuffer::mutex_;
     
    147147  }
    148148
    149 } // namespace network
     149} // namespace orxonox
  • code/trunk/src/network/PacketBuffer.h

    r2087 r2171  
    4747#include <boost/thread/recursive_mutex.hpp>
    4848
    49 namespace network
     49namespace orxonox
    5050{
    5151  struct _NetworkExport PacketEnvelope{
  • code/trunk/src/network/Server.cc

    r2087 r2171  
    6060#include "ChatListener.h"
    6161
    62 namespace network
     62namespace orxonox
    6363{
    6464  const unsigned int MAX_FAILURES = 20;
     
    317317
    318318    // inform all the listeners
    319     orxonox::ObjectList<ClientConnectionListener>::iterator listener = orxonox::ObjectList<ClientConnectionListener>::begin();
     319    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
    320320    while(listener){
    321321      listener->clientConnected(newid);
     
    366366
    367367// inform all the listeners
    368     orxonox::ObjectList<ClientConnectionListener>::iterator listener = orxonox::ObjectList<ClientConnectionListener>::begin();
     368    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
    369369    while(listener){
    370370      listener->clientDisconnected(client->getID());
     
    404404    }
    405405//    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
    406     for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it)
     406    for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    407407      it->incomingChat(message, clientID);
    408408
  • code/trunk/src/network/Server.h

    r2087 r2171  
    4949#include "GamestateManager.h"
    5050
    51 namespace network
     51namespace orxonox
    5252{
    5353  const int CLIENTID_SERVER = 0;
  • code/trunk/src/network/Synchronisable.cc

    r2087 r2171  
    5050// #include "core/Identifier.h"
    5151
    52 namespace network
     52#include "Host.h"
     53namespace orxonox
    5354{
    5455
     
    5758  std::queue<unsigned int> Synchronisable::deletedObjects_;
    5859
    59   int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
     60  uint8_t Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
    6061
    6162  /**
     
    6364  * Initializes all Variables and sets the right objectID
    6465  */
    65   Synchronisable::Synchronisable(orxonox::BaseObject* creator){
     66  Synchronisable::Synchronisable(BaseObject* creator){
    6667    RegisterRootObject(Synchronisable);
    6768    static uint32_t idCounter=0;
    6869    objectFrequency_=1;
    6970    objectMode_=0x1; // by default do not send data to server
    70     objectID=idCounter++;
     71    if ( !Host::running() || ( Host::running() && Host::isServer() ) )
     72    {
     73      this->objectID = idCounter++; //this is only needed when running a server
     74    //add synchronisable to the objectMap
     75      objectMap_[this->objectID] = this;
     76    }
     77    else
     78      objectID=OBJECTID_UNKNOWN;
    7179    classID = (unsigned int)-1;
    7280    syncList = new std::list<synchronisableVariable *>;
     81
     82
     83#ifndef NDEBUG
     84    ObjectList<Synchronisable>::iterator it;
     85    for(it = ObjectList<Synchronisable>::begin(); it!=ObjectList<Synchronisable>::end(); ++it){
     86      if( it->getObjectID()==this->objectID )
     87        assert(*it==this || (it->objectID==OBJECTID_UNKNOWN && it->objectMode_==0x0));
     88    }
     89#endif
    7390
    7491    this->creatorID = OBJECTID_UNKNOWN;
     
    96113  Synchronisable::~Synchronisable(){
    97114    // delete callback function objects
    98     if(!orxonox::Identifier::isCreatingHierarchy()){
     115    if(!Identifier::isCreatingHierarchy()){
    99116      for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++)
    100117        delete (*it)->callback;
    101       if (this->objectMode_ != 0x0)
     118      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
    102119        deletedObjects_.push(objectID);
    103120//       COUT(3) << "destruct synchronisable +++" << objectID << " | " << classID << std::endl;
     
    106123//       objectMap_.erase(objectID);
    107124    }
     125    std::map<unsigned int, Synchronisable*>::iterator it;
     126    it = objectMap_.find(objectID);
     127    if (it != objectMap_.end())
     128      objectMap_.erase(it);
    108129  }
    109130
     
    143164   * @return pointer to the newly created synchronisable
    144165   */
    145   Synchronisable *Synchronisable::fabricate(uint8_t*& mem, int mode)
     166  Synchronisable *Synchronisable::fabricate(uint8_t*& mem, uint8_t mode)
    146167  {
    147168    synchronisableHeader *header = (synchronisableHeader *)mem;
     
    152173      return 0;
    153174    }
    154    
     175
    155176    COUT(4) << "fabricating object with id: " << header->objectID << std::endl;
    156177
    157     orxonox::Identifier* id = ClassByID(header->classID);
     178    Identifier* id = ClassByID(header->classID);
    158179    assert(id);
    159     orxonox::BaseObject* creator = 0;
     180    BaseObject* creator = 0;
    160181    if (header->creatorID != OBJECTID_UNKNOWN)
    161182    {
     
    167188      }
    168189      else
    169         creator = dynamic_cast<orxonox::BaseObject*>(synchronisable_creator);
    170     }
    171     orxonox::BaseObject *bo = id->fabricate(creator);
     190        creator = dynamic_cast<BaseObject*>(synchronisable_creator);
     191    }
     192    assert(getSynchronisable(header->objectID)==0);   //make sure no object with this id exists
     193    BaseObject *bo = id->fabricate(creator);
    172194    assert(bo);
    173195    Synchronisable *no = dynamic_cast<Synchronisable *>(bo);
     
    214236   */
    215237  Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){
    216     orxonox::ObjectList<Synchronisable>::iterator it;
    217     for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    218       if( it->getObjectID()==objectID )
    219            return *it;
     238    std::map<unsigned int, Synchronisable*>::iterator it1;
     239    it1 = objectMap_.find(objectID);
     240    if (it1 != objectMap_.end())
     241      return it1->second;
     242
     243    ObjectList<Synchronisable>::iterator it;
     244    for(it = ObjectList<Synchronisable>::begin(); it; ++it){
     245      if( it->getObjectID()==objectID ){
     246        objectMap_[objectID] = *it;
     247        return *it;
     248      }
    220249    }
    221250    return NULL;
    222 
    223 //     std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID);
    224 //     if(i==objectMap_.end())
    225 //       return NULL;
    226 //     assert(i->second->objectID==objectID);
    227 //     return (*i).second;
    228251  }
    229252
     
    234257  * @param var pointer to the variable
    235258  * @param size size of the datatype the variable consists of
    236   * @param t the type of the variable (network::DATA or network::STRING
     259  * @param t the type of the variable (DATA or STRING
    237260  * @param mode same as in getData
    238261  * @param cb callback object that should get called, if the value of the variable changes
    239262  */
    240   void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){
     263  void Synchronisable::registerVariable(void *var, int size, variableType t, uint8_t mode, NetworkCallbackBase *cb){
    241264    assert( mode==direction::toclient || mode==direction::toserver || mode==direction::serverMaster || mode==direction::clientMaster);
    242265    // create temporary synch.Var struct
     
    249272    if( ( mode & direction::bidirectional ) )
    250273    {
    251       temp->varBuffer = new uint8_t[size];
    252       memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time
     274      if(t!=STRING)
     275      {
     276        temp->varBuffer = new uint8_t[size];
     277        memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time
     278      }
     279      else
     280      {
     281        temp->varBuffer=new std::string( *static_cast<std::string*>(var) );
     282      }
    253283      temp->varReference = 0;
    254284    }
     
    265295#endif
    266296  }
     297
     298  void Synchronisable::unregisterVariable(void *var){
     299    std::list<synchronisableVariable *>::iterator it = syncList->begin();
     300    while(it!=syncList->end()){
     301      if( (*it)->var == var ){
     302        delete *it;
     303        syncList->erase(it);
     304        return;
     305      }
     306      else
     307        it++;
     308    }
     309    bool unregistered_nonexistent_variable = false;
     310    assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     311    // the variable has not been registered before
     312  }
     313
    267314
    268315  /**
     
    280327   * @return true: if !doSync or if everything was successfully saved
    281328   */
    282   bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){
     329  bool Synchronisable::getData(uint8_t*& mem, unsigned int id, uint8_t mode){
     330    if(mode==0x0)
     331      mode=state_;
    283332    //if this tick is we dont synchronise, then abort now
    284     if(!doSync(id))
     333    if(!doSync(id, mode))
    285334      return true;
    286335    //std::cout << "inside getData" << std::endl;
    287336    unsigned int tempsize = 0;
    288     if(mode==0x0)
    289       mode=state_;
    290337    if(classID==0)
    291338      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     
    307354    header->classID = this->classID;
    308355    header->dataAvailable = true;
    309     tempsize+=sizeof(synchronisableHeader);
    310     mem+=sizeof(synchronisableHeader);
     356    tempsize += sizeof(synchronisableHeader);
     357    mem += sizeof(synchronisableHeader);
    311358    // end copy header
    312359
     
    319366        continue;  // this variable should only be received
    320367      }
     368
     369      // =========== start bidirectional stuff =============
    321370      // if the variable gets synchronised bidirectional, then add the reference to the bytestream
    322371      if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
    323372      {
     373        if( ( ((*i)->mode == direction::serverMaster) && (mode == 0x1) ) || \
     374            ( ((*i)->mode == direction::clientMaster) && (mode == 0x2) ) )
     375        {
     376          // MASTER
     377          if((*i)->type==DATA){
     378            if( memcmp((*i)->var,(*i)->varBuffer,(*i)->size) != 0 ) //check whether the variable changed during the last tick
     379            {
     380              ((*i)->varReference)++;   //the variable changed so increase the refnr
     381              memcpy((*i)->varBuffer, (*i)->var, (*i)->size); //set the buffer to the new value
     382            }
     383          }
     384          else //STRING
     385          {
     386            if( *static_cast<std::string*>((*i)->var) != *static_cast<std::string*>((*i)->varBuffer) ) //the string changed
     387            {
     388              ((*i)->varReference)++;   //the variable changed
     389              *static_cast<std::string*>((*i)->varBuffer) = *static_cast<std::string*>((*i)->var);  //now set the buffer to the new value
     390            }
     391          }
     392        }
     393        // copy the reference number to the stream
    324394        *(uint8_t*)mem = (*i)->varReference;
    325395        mem += sizeof( (*i)->varReference );
    326396        tempsize += sizeof( (*i)->varReference );
    327397      }
     398      // ================== end bidirectional stuff
     399
    328400      switch((*i)->type){
    329401        case DATA:
    330402          memcpy( (void *)(mem), (void*)((*i)->var), (*i)->size);
    331           mem+=(*i)->size;
    332           tempsize+=(*i)->size;
     403          mem += (*i)->size;
     404          tempsize += (*i)->size;
    333405          break;
    334406        case STRING:
    335407          memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(size_t) );
    336           mem+=sizeof(size_t);
     408          mem += sizeof(size_t);
    337409          const char *data = ( ( *(std::string *) (*i)->var).c_str());
    338410          memcpy( mem, (void*)data, (*i)->size);
    339411          COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
    340           mem+=(*i)->size;
    341           tempsize+=(*i)->size + sizeof(size_t);
     412          mem += (*i)->size;
     413          tempsize += (*i)->size + sizeof(size_t);
    342414          break;
    343415      }
     
    354426   * @return true/false
    355427   */
    356   bool Synchronisable::updateData(uint8_t*& mem, int mode, bool forceCallback){
     428  bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){
    357429    if(mode==0x0)
    358430      mode=state_;
    359431    std::list<synchronisableVariable *>::iterator i;
     432    //assert(objectMode_!=0x0);
     433    //assert( (mode ^ objectMode_) != 0);
    360434    if(syncList->empty()){
    361435      COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
     
    367441    synchronisableHeader *syncHeader = (synchronisableHeader *)mem;
    368442    assert(syncHeader->objectID==this->objectID);
    369 //    assert(syncHeader->creatorID==this->creatorID);
     443    assert(syncHeader->creatorID==this->creatorID);
     444    assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
    370445    if(syncHeader->dataAvailable==false){
    371       mem+=syncHeader->size;
     446      mem += syncHeader->size;
    372447      return true;
    373448    }
    374449
    375     mem+=sizeof(synchronisableHeader);
     450    mem += sizeof(synchronisableHeader);
    376451    // stop extract header
    377     assert(this->objectID==syncHeader->objectID);
    378 //    assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ?
    379452
    380453    COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl;
     
    382455      if( ((*i)->mode ^ mode) == 0 ){
    383456        COUT(5) << "synchronisable: not updating variable " << std::endl;
     457        // if we have a forcecallback then do the callback
    384458        continue;  // this variable should only be set
    385459      }
    386460      COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
    387461      bool callback=false;
     462      bool master=false;
     463
     464      if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
     465      {
     466        uint8_t refNr = *(uint8_t *)mem;
     467        if( ( ((*i)->mode == direction::serverMaster) && (mode == 0x1) ) || \
     468            ( ((*i)->mode == direction::clientMaster) && (mode == 0x2) ) )
     469        { // MASTER
     470          master=true;
     471          if( refNr != (*i)->varReference || ( memcmp((*i)->var, (*i)->varBuffer, (*i)->size) != 0 ) )
     472          { // DISCARD data
     473            if( (*i)->type == DATA )
     474            {
     475              mem += sizeof((*i)->varReference) + (*i)->size;
     476            }
     477            else //STRING
     478            {
     479              mem += sizeof(size_t) + *(size_t *)mem;
     480            }
     481            if( forceCallback && (*i)->callback)
     482              (*i)->callback->call();
     483            continue;
     484          }//otherwise everything is ok and we update the value
     485        }
     486        else // SLAVE
     487        {
     488          if( (*i)->varReference == refNr ){
     489            //discard data because it's outdated or not different to what we've got
     490            if( (*i)->type == DATA )
     491            {
     492              mem += sizeof((*i)->varReference) + (*i)->size;
     493            }
     494            else //STRING
     495            {
     496              mem += sizeof(size_t) + *(size_t *)mem;
     497            }
     498            if( forceCallback && (*i)->callback)
     499              (*i)->callback->call();
     500            continue;
     501          }
     502          else
     503            (*i)->varReference = refNr; //copy the reference value for this variable
     504        }
     505        mem += sizeof((*i)->varReference);
     506      }
     507
    388508      switch((*i)->type){
    389509        case DATA:
    390           if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
     510          if((*i)->callback) // check whether this variable changed (but only if callback was set)
    391511          {
    392             if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \
    393                   ( mode == 0x2 && (*i)->mode == direction::clientMaster ) )    // if true we are master on this variable
    394             {
    395               uint8_t refNr = *(uint8_t *)mem;
    396               if( refNr != (*i)->varReference )
    397               {
    398                 mem += sizeof((*i)->varReference) + (*i)->size; // the reference for this variable is not recent, discard data
    399                 break;
    400               }
    401             }
    402             else //we are slave for this variable
    403             {
    404               (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable
    405             }
    406             mem += sizeof((*i)->varReference);
     512            if(memcmp((*i)->var, mem, (*i)->size) != 0)
     513              callback=true;
    407514          }
    408           if((*i)->callback) // check whether this variable changed (but only if callback was set)
    409             if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0)
    410               callback=true;
    411           memcpy((void*)(*i)->var, mem, (*i)->size);
    412           mem+=(*i)->size;
     515          if( master )
     516          {
     517            if( callback || memcmp((*i)->var, mem, (*i)->size) != 0 )
     518              //value changed, so set the buffer to the new value
     519              memcpy((*i)->varBuffer, mem, (*i)->size);
     520          }
     521          memcpy((*i)->var, mem, (*i)->size);
     522          mem += (*i)->size;
    413523          break;
    414524        case STRING:
    415           if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional )
     525          (*i)->size = *(size_t *)mem;
     526          mem += sizeof(size_t);
     527
     528          if( (*i)->callback) // check whether this string changed
     529            if( *static_cast<std::string*>((*i)->var) != std::string((char *)mem) )
     530              callback=true;
     531          if( master )
    416532          {
    417             if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \
    418                   ( mode == 0x2 && (*i)->mode == direction::clientMaster ) )    // if true we are master for this variable
    419             {
    420               uint8_t refNr = *(uint8_t *)mem;
    421               mem += sizeof( (*i)->varReference );
    422               if( refNr != (*i)->varReference ){
    423                 mem += sizeof(size_t) + *(size_t *)mem; // the reference for this variable is not recent, discard data
    424                 break;
    425               }
    426             }
    427             else //we are slave for this variable
    428             {
    429               (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable
    430             }
    431             mem += sizeof( (*i)->varReference );
     533            if( callback || *static_cast<std::string*>((*i)->var) != std::string((char *)mem) )
     534              //string changed. set the buffer to the new one
     535              *static_cast<std::string*>((*i)->varBuffer)=*static_cast<std::string*>( (void*)(mem+sizeof(size_t)) );
    432536          }
    433           (*i)->size = *(size_t *)mem;
    434           COUT(5) << "string size: " << (*i)->size << std::endl;
    435           mem += sizeof(size_t);
    436           if((*i)->callback) // check whether this string changed
    437             if( *(std::string *)((*i)->var) != std::string((char *)mem) )
    438               callback=true;
     537
    439538          *((std::string *)((*i)->var)) = std::string((const char*)mem);
    440539          COUT(5) << "synchronisable: char: " << (const char*)mem << " string: " << std::string((const char*)mem) << std::endl;
     
    446545        (*i)->callback->call();
    447546    }
     547    assert(mem == data+syncHeader->size);
    448548    return true;
    449549  }
     
    455555  * @return amount of bytes
    456556  */
    457   uint32_t Synchronisable::getSize(unsigned int id, int mode){
    458     if(!doSync(id))
    459       return 0;
     557  uint32_t Synchronisable::getSize(unsigned int id, uint8_t mode){
    460558    int tsize=sizeof(synchronisableHeader);
    461559    if(mode==0x0)
    462560      mode=state_;
     561    if(!doSync(id, mode))
     562      return 0;
    463563    std::list<synchronisableVariable *>::iterator i;
    464564    for(i=syncList->begin(); i!=syncList->end(); i++){
     
    489589   * @return true/false
    490590   */
    491   bool Synchronisable::doSync(unsigned int id){
    492     return ( (objectMode_&state_)!=0 && (!syncList->empty() ) );
     591  bool Synchronisable::doSync(unsigned int id, uint8_t mode){
     592    if(mode==0x0)
     593      mode=state_;
     594    return ( (objectMode_&mode)!=0 && (!syncList->empty() ) );
    493595  }
    494596
    495597  bool Synchronisable::doSelection(unsigned int id){
    496     return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);
     598    return true; //TODO: change this
     599    //return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);
    497600  }
    498601
     
    510613  /**
    511614   * This function sets the synchronisation mode of the object
     615   * If set to 0x0 variables will not be synchronised at all
    512616   * If set to 0x1 variables will only be synchronised to the client
    513617   * If set to 0x2 variables will only be synchronised to the server
     
    515619   * @param mode same as in registerVar
    516620   */
    517   void Synchronisable::setObjectMode(int mode){
     621  void Synchronisable::setObjectMode(uint8_t mode){
    518622    assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
    519623    objectMode_=mode;
  • code/trunk/src/network/Synchronisable.h

    r2087 r2171  
    4242
    4343#define REGISTERDATA(varname, ...) \
    44     registerVar((void*)&varname, sizeof(varname), network::DATA, __VA_ARGS__)
     44    registerVariable((void*)&varname, sizeof(varname), DATA, __VA_ARGS__)
    4545#define REGISTERSTRING(stringname, ...) \
    46     registerVar(&stringname, stringname.length()+1, network::STRING, __VA_ARGS__)
     46    registerVariable(&stringname, stringname.length()+1, STRING, __VA_ARGS__)
    4747
    48 namespace network
     48namespace orxonox
    4949{
    5050  static const unsigned int OBJECTID_UNKNOWN = (unsigned int)-1;
     
    6262  namespace syncmode{
    6363    enum mode{
    64       one=0,
     64      once=0,
    6565      always=1
    6666    };
     
    8181
    8282  struct _NetworkExport synchronisableVariable{
    83     unsigned int size;
    84     int mode; // this determines in which direction the variable gets synchronised
     83    size_t size;
     84    uint8_t mode; // this determines in which direction the variable gets synchronised
    8585    void *var;
    8686    variableType type;
     
    9595  * @author Oliver Scheuss
    9696  */
    97   class _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{
     97  class _NetworkExport Synchronisable : virtual public OrxonoxClass{
    9898  public:
    9999    friend class packet::Gamestate;
    100     friend class GamestateClient;
    101     friend class Server;
     100//     friend class Server;
    102101    virtual ~Synchronisable();
    103102
     
    106105    static void setClient(bool b);
    107106
    108     static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0);
     107    static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
    109108    static bool deleteObject(unsigned int objectID);
    110109    static Synchronisable *getSynchronisable(unsigned int objectID);
     
    115114    inline unsigned int getClassID(){return classID;}
    116115  protected:
    117     Synchronisable(orxonox::BaseObject* creator);
    118     void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
    119     void setObjectMode(int mode);
     116    Synchronisable(BaseObject* creator);
     117    void registerVariable(void *var, int size, variableType t, uint8_t mode=0x1, NetworkCallbackBase *cb=0);
     118    void unregisterVariable(void *var);
     119    void setObjectMode(uint8_t mode);
    120120    void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; }
    121121
    122122
    123123  private:
    124     bool getData(uint8_t*& men, unsigned int id, int mode=0x0);
    125     uint32_t getSize(unsigned int id, int mode=0x0);
    126     bool updateData(uint8_t*& mem, int mode=0x0, bool forceCallback=false);
     124    bool getData(uint8_t*& men, unsigned int id, uint8_t mode=0x0);
     125    uint32_t getSize(unsigned int id, uint8_t mode=0x0);
     126    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
    127127    bool isMyData(uint8_t* mem);
    128128    bool doSelection(unsigned int id);
    129     bool doSync(unsigned int id);
     129    bool doSync(unsigned int id, uint8_t mode=0x0);
    130130
    131131    unsigned int objectID;
     
    134134
    135135    std::list<synchronisableVariable *> *syncList;
    136     static int state_; // detemines wheter we are server (default) or client
     136    static uint8_t state_; // detemines wheter we are server (default) or client
    137137    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
    138138    unsigned int objectFrequency_;
  • 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.