Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 10:23:58 PM (15 years ago)
Author:
rgrieder
Message:

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
Location:
code/trunk
Files:
1 deleted
40 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/Client.cc

    r5965 r6417  
    6262  Client::Client():
    6363      isSynched_(false),
    64       gameStateFailure_(false)
     64      gameStateFailure_(false),
     65      timeSinceLastUpdate_(0)
    6566  {
    6667  }
     
    7374  Client::Client(const std::string& address, int port):
    7475      isSynched_(false),
    75       gameStateFailure_(false)
     76      gameStateFailure_(false),
     77      timeSinceLastUpdate_(0)
    7678  {
    7779      setPort( port );
     
    111113    return true;
    112114  }
    113  
     115
    114116  void Client::printRTT(){
    115117    COUT(0) << "Round trip time to server is " << ClientConnection::getRTT() << " ms" << endl;
     
    137139    {
    138140      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
    139       //     COUT(3) << ".";
     141      //     COUT(3) << '.';
    140142      if ( isConnected() && isSynched_ )
    141143      {
     
    153155    }
    154156    sendPackets(); // flush the enet queue
    155    
     157
    156158    Connection::processQueue();
    157159    if(gamestate.processGamestates())
     
    165167    return;
    166168  }
    167  
     169
    168170  void Client::connectionClosed()
    169171  {
  • code/trunk/src/libraries/network/ClientConnection.cc

    r5965 r6417  
    6969  {
    7070    ENetEvent event;
    71    
     71
    7272    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
    7373    if ( this->host_ == NULL )
     
    9999  bool ClientConnection::closeConnection() {
    100100    ENetEvent event;
    101    
     101
    102102    if ( !this->established_ )
    103103      return true;
     
    146146    this->connectionClosed();
    147147  }
    148  
     148
    149149  uint32_t ClientConnection::getRTT()
    150   { 
     150  {
    151151    assert(server_);
    152152    return server_->roundTripTime;
  • code/trunk/src/libraries/network/ClientConnection.h

    r5961 r6417  
    2626 *
    2727 */
    28  
     28
    2929#ifndef _ClientConnection_H__
    3030#define _ClientConnection_H__
     
    4040    ClientConnection();
    4141    virtual ~ClientConnection();
    42    
     42
    4343    void setServerAddress( const std::string& serverAddress );
    4444    void setPort( unsigned int port );
    45    
     45
    4646    ENetEvent *getEvent();
    4747    // check wheter the packet queue is empty
     
    5959    virtual void addPeer(ENetEvent* event);
    6060    virtual void removePeer(ENetEvent* event);
    61    
     61
    6262    bool disconnectConnection();
    6363    // enet stuff
  • code/trunk/src/libraries/network/ClientConnectionListener.cc

    r5929 r6417  
    3636{
    3737    ClientConnectionListener::ClientConnectionListener()
    38     { 
    39         RegisterRootObject(ClientConnectionListener); 
     38    {
     39        RegisterRootObject(ClientConnectionListener);
    4040    }
    4141
     
    4545            it->clientConnected(clientID);
    4646    }
    47    
     47
    4848    void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID)
    4949    {
  • code/trunk/src/libraries/network/ClientConnectionListener.h

    r5929 r6417  
    4040            ClientConnectionListener();
    4141            virtual ~ClientConnectionListener() {}
    42            
     42
    4343            static void broadcastClientConnected(unsigned int clientID);
    4444            static void broadcastClientDisconnected(unsigned int clientID);
  • code/trunk/src/libraries/network/ClientInformation.cc

    r5961 r6417  
    4646namespace orxonox
    4747{
    48  
     48
    4949
    5050  ClientInformation *ClientInformation::head_=0;
  • code/trunk/src/libraries/network/Connection.cc

    r5929 r6417  
    7575  void Connection::processQueue() {
    7676    ENetEvent event;
    77    
     77
    7878    assert(this->host_);
    7979
  • code/trunk/src/libraries/network/Connection.h

    r5929 r6417  
    5454  public:
    5555    virtual ~Connection();
    56    
     56
    5757    static bool addPacket(ENetPacket *packet, ENetPeer *peer);
    5858    bool sendPackets();
     
    6262    Connection();
    6363    static Connection* getInstance(){ return Connection::instance_; }
    64    
     64
    6565    int service(ENetEvent* event);
    6666    virtual void disconnectPeer(ENetPeer *peer);
    67    
     67
    6868    void processQueue();
    6969    virtual void addPeer(ENetEvent* event)=0;
    7070    virtual void removePeer(ENetEvent* event)=0;
    7171    virtual bool processPacket(ENetEvent* event);
    72    
     72
    7373    ENetHost *host_;
    7474  private:
  • code/trunk/src/libraries/network/FunctionCallManager.cc

    r6073 r6417  
    3131
    3232namespace orxonox {
    33    
     33
    3434std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::clientMap_;
    3535
     
    3737
    3838void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)
    39 { 
    40   if(clientMap_.find(clientID)==clientMap_.end()) 
     39{
     40  if(clientMap_.find(clientID)==clientMap_.end())
    4141  {
    42     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    43     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    44   } 
     42    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     43    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     44  }
    4545  FunctionCallManager::clientMap_[clientID]->addCallStatic(functionID);
    4646}
    4747void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)
    48 { 
    49   if(clientMap_.find(clientID)==clientMap_.end()) 
     48{
     49  if(clientMap_.find(clientID)==clientMap_.end())
    5050  {
    51     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    52     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    53   } 
     51    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     52    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     53  }
    5454  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1);
    5555}
    5656void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
    57 { 
    58   if(clientMap_.find(clientID)==clientMap_.end()) 
     57{
     58  if(clientMap_.find(clientID)==clientMap_.end())
    5959  {
    60     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    61     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    62   } 
     60    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     61    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     62  }
    6363  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);
    6464}
    6565void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
    66 { 
    67   if(clientMap_.find(clientID)==clientMap_.end()) 
     66{
     67  if(clientMap_.find(clientID)==clientMap_.end())
    6868  {
    69     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    70     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    71   } 
     69    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     70    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     71  }
    7272  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);
    7373}
    7474void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
    75 { 
    76   if(clientMap_.find(clientID)==clientMap_.end()) 
     75{
     76  if(clientMap_.find(clientID)==clientMap_.end())
    7777  {
    78     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    79     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    80   } 
     78    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     79    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     80  }
    8181  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);
    8282}
    8383void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
    84 { 
    85   if(clientMap_.find(clientID)==clientMap_.end()) 
     84{
     85  if(clientMap_.find(clientID)==clientMap_.end())
    8686  {
    87     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    88     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    89   } 
     87    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     88    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     89  }
    9090  FunctionCallManager:: clientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);
    9191}
     
    9595
    9696void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)
    97 { 
    98   if(clientMap_.find(clientID)==clientMap_.end()) 
     97{
     98  if(clientMap_.find(clientID)==clientMap_.end())
    9999  {
    100     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    101     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    102   } 
     100    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     101    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     102  }
    103103  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID);
    104104}
    105105void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)
    106 { 
    107   if(clientMap_.find(clientID)==clientMap_.end()) 
     106{
     107  if(clientMap_.find(clientID)==clientMap_.end())
    108108  {
    109     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    110     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    111   } 
     109    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     110    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     111  }
    112112  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1);
    113113}
    114114void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)
    115 { 
    116   if(clientMap_.find(clientID)==clientMap_.end()) 
     115{
     116  if(clientMap_.find(clientID)==clientMap_.end())
    117117  {
    118     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    119     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    120   } 
     118    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     119    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     120  }
    121121  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);
    122122}
    123123void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
    124 { 
    125   if(clientMap_.find(clientID)==clientMap_.end()) 
     124{
     125  if(clientMap_.find(clientID)==clientMap_.end())
    126126  {
    127     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    128     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    129   } 
     127    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     128    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     129  }
    130130  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);
    131131}
    132132void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
    133 { 
    134   if(clientMap_.find(clientID)==clientMap_.end()) 
     133{
     134  if(clientMap_.find(clientID)==clientMap_.end())
    135135  {
    136     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    137     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    138   } 
     136    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     137    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     138  }
    139139  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);
    140140}
    141141void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
    142 { 
    143   if(clientMap_.find(clientID)==clientMap_.end()) 
     142{
     143  if(clientMap_.find(clientID)==clientMap_.end())
    144144  {
    145     FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls; 
    146     FunctionCallManager::clientMap_[clientID]->setClientID(clientID); 
    147   } 
     145    FunctionCallManager::clientMap_[clientID] = new packet::FunctionCalls;
     146    FunctionCallManager::clientMap_[clientID]->setClientID(clientID);
     147  }
    148148  FunctionCallManager::clientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);
    149149}
  • code/trunk/src/libraries/network/FunctionCallManager.h

    r6073 r6417  
    4949  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
    5050  static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
    51  
     51
    5252  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);
    5353  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);
     
    5656  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);
    5757  static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);
    58  
     58
    5959  static void sendCalls();
    60  
     60
    6161  static std::map<uint32_t, packet::FunctionCalls*> clientMap_;
    6262protected:
  • code/trunk/src/libraries/network/GamestateClient.cc

    r5929 r6417  
    5454      std::map<unsigned int, packet::Gamestate *>::iterator it;
    5555      for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it )
    56           delete (*it).second;
     56          delete it->second;
    5757      if( this->tempGamestate_ )
    5858          delete this->tempGamestate_;
     
    8181    packet::Gamestate *processed = processGamestate(tempGamestate_);
    8282    assert(processed);
    83    
     83
    8484    //now call the queued callbacks
    8585    NetworkCallbackManager::callCallbacks();
    86    
     86
    8787    if (!processed){
    8888      sendAck(0);
     
    126126        break;
    127127      // otherwise delete that stuff
    128       delete (*it).second;
     128      delete it->second;
    129129      temp=it++;
    130130      gamestateMap_.erase(temp);
     
    137137    COUT(4) << "gamestates: ";
    138138    for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){
    139       COUT(4) << it->first << ":" << it->second << "|";
     139      COUT(4) << it->first << ':' << it->second << '|';
    140140    }
    141141    COUT(4) << std::endl;
  • code/trunk/src/libraries/network/GamestateHandler.cc

    r5781 r6417  
    3333
    3434GamestateHandler *GamestateHandler::instance_=0;
    35  
     35
    3636GamestateHandler::GamestateHandler()
    3737{
  • code/trunk/src/libraries/network/GamestateManager.cc

    r5929 r6417  
    6969        delete this->reference;std::map<unsigned int, packet::Gamestate*>::iterator it;
    7070    for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
    71       delete (*it).second;
     71      delete it->second;
    7272    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;
    7373    std::map<unsigned int, packet::Gamestate*>::iterator it2;
     
    7575    {
    7676      for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2 )
    77         delete (*it2).second;
     77        delete it2->second;
    7878    }
    7979    this->trafficControl_->destroy();
     
    126126    return true;
    127127  }
    128  
     128
    129129  void GamestateManager::sendGamestates()
    130130  {
     
    142142      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
    143143      int cid = temp->getID(); //get client id
    144      
     144
    145145      unsigned int gID = temp->getGamestateID();
    146146      if(!reference)
    147147        return;
    148      
     148
    149149      packet::Gamestate *client=0;
    150150      if(gID != GAMESTATEID_INITIAL){
     
    156156        }
    157157      }
    158      
     158
    159159      clientGamestates.push(0);
    160160      finishGamestate( cid, &clientGamestates.back(), client, reference );
    161       //FunctorMember<GamestateManager>* functor = 
     161      //FunctorMember<GamestateManager>* functor =
    162162//       ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) );
    163163//       executor->setDefaultValues( cid, &clientGamestates.back(), client, reference );
     
    165165//       this->threadPool_->passFunction( executor, true );
    166166//       (*functor)( cid, &(clientGamestates.back()), client, reference );
    167      
     167
    168168      temp = temp->next();
    169169    }
    170    
     170
    171171//     threadPool_->synchronise();
    172    
     172
    173173    while( !clientGamestates.empty() )
    174174    {
     
    185185    // save the (undiffed) gamestate in the clients gamestate map
    186186    //chose wheather the next gamestate is the first or not
    187    
     187
    188188    packet::Gamestate *gs = gamestate->doSelection(clientID, 20000);
    189189//     packet::Gamestate *gs = new packet::Gamestate(*gamestate);
     
    193193    gamestateMap_[clientID][gamestate->getID()]=gs;
    194194//     this->threadMutex_->unlock();
    195    
     195
    196196    if(base)
    197197    {
    198        
     198
    199199//       COUT(3) << "diffing" << std::endl;
    200200//       packet::Gamestate* gs1  = gs;
     
    210210      gs = new packet::Gamestate(*gs);
    211211    }
    212    
    213    
     212
     213
    214214    bool b = gs->compressData();
    215215    assert(b);
  • code/trunk/src/libraries/network/NetworkFunction.cc

    r5929 r6417  
    3232namespace orxonox
    3333{
    34   std::map<std::string, NetworkFunctionBase*> NetworkFunctionBase::nameMap_;
    3534  std::map<uint32_t, bool> NetworkFunctionBase::isStaticMap_;
    36  
    37   std::map<NetworkFunctionPointer, NetworkFunctionStatic*> NetworkFunctionStatic::functorMap_;
    38   std::map<uint32_t, NetworkFunctionStatic*> NetworkFunctionStatic::idMap_;
    39      
     35
    4036  std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_;
    4137  std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_;
     
    4440  {
    4541    RegisterRootObject(NetworkFunctionBase);
    46    
     42
    4743    static uint32_t networkID = 0;
    4844    this->networkID_ = networkID++;
    49    
     45
    5046    this->name_ = name;
    51     nameMap_[name] = this;
     47    NetworkFunctionBase::getNameMap()[name] = this;
    5248  }
    5349  NetworkFunctionBase::~NetworkFunctionBase()
    5450  {
    5551  }
    56  
    57  
     52
     53
    5854  void NetworkFunctionBase::destroyAllNetworkFunctions()
    5955  {
     56    std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap();
    6057    std::map<std::string, NetworkFunctionBase*>::iterator it;
    61     for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )
     58    for( it=map.begin(); it!=map.end(); ++it )
    6259      it->second->destroy();
    6360  }
    64  
    65  
     61
     62
     63  /*static*/ std::map<std::string, NetworkFunctionBase*>& NetworkFunctionBase::getNameMap()
     64  {
     65    static std::map<std::string, NetworkFunctionBase*> nameMap_;
     66    return nameMap_;
     67  }
     68
     69
    6670  NetworkFunctionStatic::NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p):
    6771    NetworkFunctionBase(name)
    6872  {
    6973    RegisterObject(NetworkFunctionStatic);
    70    
     74
    7175    this->functor_ = functor;
    72     functorMap_[p] = this;
    73     idMap_[ this->getNetworkID() ] = this;
     76    NetworkFunctionStatic::getFunctorMap()[p] = this;
     77    NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this;
    7478  }
    75  
     79
    7680  NetworkFunctionStatic::~NetworkFunctionStatic()
    7781  {
    7882    delete this->functor_;
    7983  }
    80  
    81  
    82  
     84
     85  /*static*/ std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& NetworkFunctionStatic::getFunctorMap()
     86  {
     87    static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_;
     88    return functorMap_;
     89  }
     90
     91  /*static*/ std::map<uint32_t, NetworkFunctionStatic*>& NetworkFunctionStatic::getIdMap()
     92  {
     93    static std::map<uint32_t, NetworkFunctionStatic*> idMap_;
     94    return idMap_;
     95  }
     96
     97
    8398  NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p):
    8499    NetworkFunctionBase(name)
    85100  {
    86101    RegisterObject(NetworkMemberFunctionBase);
    87    
    88     functorMap_[p] = this;
    89     idMap_[ this->getNetworkID() ] = this;
     102
     103    this->functorMap_[p] = this;
     104    this->idMap_[ this->getNetworkID() ] = this;
    90105  }
    91  
     106
    92107  NetworkMemberFunctionBase::~NetworkMemberFunctionBase()
    93108  {
    94109  }
    95  
     110
    96111
    97112}
  • code/trunk/src/libraries/network/NetworkFunction.h

    r5781 r6417  
    7474    NetworkFunctionBase(const std::string& name);
    7575    ~NetworkFunctionBase();
    76    
     76
    7777    virtual void        setNetworkID(uint32_t id)       { this->networkID_ = id; }
    7878    inline uint32_t     getNetworkID() const            { return this->networkID_; }
    7979    inline const std::string& getName() const           { return name_; }
    8080    static inline bool  isStatic( uint32_t networkID )  { return isStaticMap_[networkID]; }
    81    
    82     static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
    83    
     81
     82    static inline void setNetworkID(const std::string& name, uint32_t id)
     83    {
     84        std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap();
     85        assert( map.find(name)!=map.end() );
     86        map[name]->setNetworkID(id);
     87    }
     88
    8489    static void destroyAllNetworkFunctions();
    85    
     90
    8691  protected:
    8792    static std::map<uint32_t, bool> isStaticMap_;
    88    
    89   private:
    90     static std::map<std::string, NetworkFunctionBase*> nameMap_;
     93
     94  private:
     95    static std::map<std::string, NetworkFunctionBase*>& getNameMap();
    9196    uint32_t networkID_;
    9297    std::string name_;
    93      
     98
    9499};
    95100
     
    99104    NetworkFunctionStatic(FunctorStatic* functor, const std::string& name, const NetworkFunctionPointer& p);
    100105    ~NetworkFunctionStatic();
    101    
     106
    102107    inline void call(){ (*this->functor_)(); }
    103108    inline void call(const MultiType& mt1){ (*this->functor_)(mt1); }
     
    106111    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); }
    107112    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); }
    108    
    109     virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
    110     static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; }
    111     static NetworkFunctionStatic* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
    112     static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
    113    
    114   private:
    115     static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_;
    116     static std::map<uint32_t, NetworkFunctionStatic*> idMap_;
    117    
     113
     114    virtual void setNetworkID( uint32_t id )
     115        { NetworkFunctionBase::setNetworkID( id ); NetworkFunctionStatic::getIdMap()[id] = this; }
     116    static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id)
     117        { assert( NetworkFunctionStatic::getIdMap().find(id)!=NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; }
     118    static NetworkFunctionStatic* getFunction( uint32_t id )
     119        { assert( NetworkFunctionStatic::getIdMap().find(id) != NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; }
     120    static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p )
     121        { assert( NetworkFunctionStatic::getFunctorMap().find(p) != NetworkFunctionStatic::getFunctorMap().end() ); return NetworkFunctionStatic::getFunctorMap()[p]; }
     122
     123  private:
     124    static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap();
     125    static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap();
    118126    FunctorStatic* functor_;
    119    
     127
    120128};
    121129
     
    125133    NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p);
    126134    ~NetworkMemberFunctionBase();
    127    
     135
    128136    virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
    129137    static inline NetworkMemberFunctionBase* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; }
    130138    static NetworkMemberFunctionBase* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
    131139    static NetworkMemberFunctionBase* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
    132    
    133     // 
     140
     141    //
    134142    virtual void call(uint32_t objectID)=0;
    135143    virtual void call(uint32_t objectID, const MultiType& mt1)=0;
     
    138146    virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0;
    139147    virtual void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0;
    140    
     148
    141149  private:
    142150    static std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> functorMap_;
     
    149157    NetworkMemberFunction(FunctorMember<T>* functor, const std::string& name, const NetworkFunctionPointer& p);
    150158    ~NetworkMemberFunction();
    151    
     159
    152160    inline void call(uint32_t objectID)
    153     { 
     161    {
    154162      if ( Synchronisable::getSynchronisable(objectID)!=0 )
    155163        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)));
    156164    }
    157165    inline void call(uint32_t objectID, const MultiType& mt1)
    158     { 
     166    {
    159167      if ( Synchronisable::getSynchronisable(objectID)!=0 )
    160168        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1);
    161169    }
    162170    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2)
    163     { 
     171    {
    164172      if ( Synchronisable::getSynchronisable(objectID)!=0 )
    165173        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2);
    166174    }
    167175    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)
    168     { 
     176    {
    169177      if ( Synchronisable::getSynchronisable(objectID)!=0 )
    170178        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3);
    171179    }
    172180    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)
    173     { 
     181    {
    174182      if ( Synchronisable::getSynchronisable(objectID)!=0 )
    175183        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4);
    176184    }
    177185    inline void call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)
    178     { 
     186    {
    179187      if ( Synchronisable::getSynchronisable(objectID)!=0 )
    180188        (*this->functor_)(orxonox_cast<T*>(Synchronisable::getSynchronisable(objectID)), mt1, mt2, mt3, mt4, mt5);
    181189    }
    182    
     190
    183191  private:
    184192    FunctorMember<T>* functor_;
  • code/trunk/src/libraries/network/NetworkPrereqs.h

    r5929 r6417  
    144144  template <class T>
    145145  class NetworkCallback;
     146  template <class T, class U>
     147  class NetworkCallbackNotify;
    146148  class NetworkCallbackBase;
    147149  class NetworkCallbackManager;
  • code/trunk/src/libraries/network/Server.cc

    r5961 r6417  
    137137    // receive incoming packets
    138138    Connection::processQueue();
    139    
     139
    140140    if ( ClientInformation::hasClients() )
    141141    {
    142142      // process incoming gamestates
    143143      GamestateManager::processGamestates();
    144      
     144
    145145      // send function calls to clients
    146146      FunctionCallManager::sendCalls();
    147      
     147
    148148      //this steers our network frequency
    149149      timeSinceLastUpdate_+=time.getDeltaTime();
     
    160160    return ServerConnection::addPacket(packet, clientID);
    161161  }
    162  
    163   /**
    164    * @brief: returns ping time to client in milliseconds 
     162
     163  /**
     164   * @brief: returns ping time to client in milliseconds
    165165   */
    166166  unsigned int Server::getRTT(unsigned int clientID){
     
    168168    return ClientInformation::findClient(clientID)->getRTT();
    169169  }
    170  
     170
    171171  void Server::printRTT()
    172172  {
     
    317317    }
    318318    COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    319    
     319
    320320    // synchronise class ids
    321321    syncClassid(temp->getID());
    322    
     322
    323323    // now synchronise functionIDs
    324324    packet::FunctionIDs *fIDs = new packet::FunctionIDs();
     
    326326    bool b = fIDs->send();
    327327    assert(b);
    328    
     328
    329329    temp->setSynched(true);
    330330    COUT(4) << "sending welcome" << std::endl;
     
    344344    return true;
    345345  }
    346  
     346
    347347  void Server::disconnectClient( ClientInformation *client ){
    348348    ServerConnection::disconnectClient( client );
  • code/trunk/src/libraries/network/Server.h

    r5961 r6417  
    6666    unsigned int shipID(){return 0;}
    6767    unsigned int playerID(){return 0;}
    68    
     68
    6969    void addPeer(ENetEvent *event);
    7070    void removePeer(ENetEvent *event);
    71    
     71
    7272    bool createClient(int clientID);
    7373    void disconnectClient( ClientInformation *client);
  • code/trunk/src/libraries/network/ServerConnection.cc

    r5929 r6417  
    9999    return true;
    100100  }
    101  
     101
    102102  void ServerConnection::disconnectClient(ClientInformation *client)
    103103  {
    104104    Connection::disconnectPeer( client->getPeer() );
    105105  }
    106  
     106
    107107  void ServerConnection::disconnectClient(int clientID){
    108108    ClientInformation *client = ClientInformation::findClient(clientID);
  • code/trunk/src/libraries/network/ServerConnection.h

    r5929 r6417  
    5050  public:
    5151    ~ServerConnection();
    52    
     52
    5353    void setBindAddress( const std::string& bindAddress );
    5454    void setPort( unsigned int port );
    55    
     55
    5656    bool openListener();
    5757    bool closeListener();
  • code/trunk/src/libraries/network/TrafficControl.cc

    r6073 r6417  
    145145    assert(clientListPerm_.find(clientID) != clientListPerm_.end() );
    146146    assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
    147    
     147
    148148    // shortcut for maps
    149149    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     
    152152    for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++)
    153153      {
    154       if(objectListPerm.find((*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists
    155       {
    156         objectListPerm[(*itvec).objID].objCurGS = gamestateID;
    157         objectListPerm[(*itvec).objID].objValueSched = 0; //set scheduling value back
     154      if(objectListPerm.find(itvec->objID) != objectListPerm.end()) // check whether the obj already exists in our lists
     155      {
     156        objectListPerm[itvec->objID].objCurGS = gamestateID;
     157        objectListPerm[itvec->objID].objValueSched = 0; //set scheduling value back
    158158      }
    159159      else
    160160      {
    161161        assert(0);
    162         objectListPerm[(*itvec).objID].objCurGS = gamestateID;
    163         objectListPerm[(*itvec).objID].objID = (*itvec).objID;
    164         objectListPerm[(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
    165         objectListPerm[(*itvec).objID].objSize = (*itvec).objSize;
     162        objectListPerm[itvec->objID].objCurGS = gamestateID;
     163        objectListPerm[itvec->objID].objID = itvec->objID;
     164        objectListPerm[itvec->objID].objCreatorID = itvec->objCreatorID;
     165        objectListPerm[itvec->objID].objSize = itvec->objSize;
    166166      }
    167167      }
     
    205205    for(itvec = list.begin(); itvec != list.end();)
    206206    {
    207       assert( (*itvec).objSize < 1000);
    208       if ( ( size + (*itvec).objSize ) < targetsize )
    209       {
    210         size += (*itvec).objSize;//objSize is given in bytes
     207      assert( itvec->objSize < 1000);
     208      if ( ( size + itvec->objSize ) < targetsize )
     209      {
     210        size += itvec->objSize;//objSize is given in bytes
    211211        ++itvec;
    212212      }
    213213      else
    214214      {
    215         clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
     215        clientListPerm_[currentClientID][itvec->objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
    216216        list.erase(itvec, list.end());
    217217        break;
     
    236236      //if listToProcess contains new Objects, add them to clientListPerm
    237237      std::list<obj>::iterator itvec;
    238    
     238
    239239      std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
    240    
     240
    241241      for( itvec=list.begin(); itvec != list.end(); itvec++)
    242242      {
    243         if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
     243        if ( objectListPerm.find( itvec->objID) != objectListPerm.end() )
    244244        {
    245245        // we already have the object in our map
    246246        //obj bleibt in liste und permanente prio wird berechnet
    247           objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
     247          objectListPerm[itvec->objID].objDiffGS = currentGamestateID - objectListPerm[itvec->objID].objCurGS;
    248248          continue;//check next objId
    249249        }
     
    256256      }
    257257    //end compare listToProcess vs clientListPerm
    258      
     258
    259259      //sort copied list according to priorities
    260260      // use boost bind here because we need to pass a memberfunction to stl sort
    261261//       sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    262262      list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    263      
     263
    264264//       list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    265265
     
    277277//       sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    278278      list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    279      
     279
    280280      //diese Funktion updateClientList muss noch gemacht werden
    281281      updateClientListTemp(list);
     
    289289    COUT(0) << "=========== Objectlist ===========" << endl;
    290290    for( it=list.begin(); it!=list.end(); it++)
    291       COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;
     291      COUT(0) << "ObjectID: " << it->objID << " creatorID: " << it->objCreatorID << " Priority: " << clientListPerm_[clientID][it->objID].objValuePerm + clientListPerm_[clientID][it->objID].objValueSched << " size: " << it->objSize << endl;
    292292  }
    293293
    294294  void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj>& list, unsigned int clientID)
    295295  {
    296     if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )
    297       return;
    298     if( clientListPerm_[clientID][(*it1).objCreatorID].objCurGS != GAMESTATEID_INITIAL )
     296    if ( it1->objCreatorID == OBJECTID_UNKNOWN )
     297      return;
     298    if( clientListPerm_[clientID][it1->objCreatorID].objCurGS != GAMESTATEID_INITIAL )
    299299      return;
    300300    std::list<obj>::iterator it2, it3=it1;
    301301    for( it2 = ++it3; it2 != list.end(); it2++ )
    302302    {
    303       if( (*it2).objID == (*it1).objCreatorID )
     303      if( it2->objID == it1->objCreatorID )
    304304      {
    305305        it3 = list.insert(it1, *it2); //insert creator before it1
  • code/trunk/src/libraries/network/TrafficControl.h

    r6073 r6417  
    6969      obj( uint32_t ID, uint32_t creatorID, uint32_t size, uint32_t offset );
    7070  };
    71  
     71
    7272
    7373
     
    9797    unsigned int targetSize;
    9898    bool         bActive_;
    99    
     99
    100100    void insertinClientListPerm(unsigned int clientID, obj objinf);
    101    
     101
    102102    void cut(std::list<obj>& list, unsigned int targetsize);
    103103    void updateClientListTemp(std::list<obj>& list);//done
     
    105105    *evaluates Data given (list) and produces result(->Data to be updated)
    106106    */
    107     void evaluateList(unsigned int clientID, std::list<obj>& list);//done   
     107    void evaluateList(unsigned int clientID, std::list<obj>& list);//done
    108108    void ack(unsigned int clientID, unsigned int gamestateID);  // this function gets called when the server receives an ack from the client
    109    
     109
    110110    //ClientConnectionListener functions
    111111    virtual void clientConnected(unsigned int clientID){};
    112112    virtual void clientDisconnected(unsigned int clientID);
    113113
    114  
     114
    115115  protected:
    116116    static TrafficControl *instance_;
     
    121121    /**
    122122    *is being used by GSManager from Server:
    123     *list contains: ObjIds, CreatorIds, Size (in this order) from Client XY 
     123    *list contains: ObjIds, CreatorIds, Size (in this order) from Client XY
    124124    *Elements of list are accessed by *list[i]
    125125    *Elements of struct i are therefore: *list[i].objID
     
    131131    { return instance_->ack(clientID, gamestateID); }
    132132    void deleteObject(unsigned int objectID);               // this function gets called when an object has been deleted (in order to clean up lists and maps)
    133    
     133
    134134    bool prioritySort(uint32_t clientID, obj i, obj j);
    135135    bool dataSort(obj i, obj j);
  • code/trunk/src/libraries/network/packet/Acknowledgement.cc

    r5781 r6417  
    3838#define _PACKETID           0
    3939#define _ACKID              _PACKETID + sizeof(packet::Type::Value)
    40  
     40
    4141Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )
    4242 : Packet()
  • code/trunk/src/libraries/network/packet/Chat.cc

    r5781 r6417  
    3535namespace orxonox {
    3636namespace packet {
    37  
     37
    3838#define   PACKET_FLAGS_CHAT PacketFlag::Reliable
    3939#define   _PACKETID         0
  • code/trunk/src/libraries/network/packet/ClassID.cc

    r5929 r6417  
    4848ClassID::ClassID( ) : Packet(){
    4949  Identifier *id;
    50   std::string classname;
    5150  unsigned int nrOfClasses=0;
    5251  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses
     
    5857  std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin();
    5958  for(;it != Identifier::getStringIdentifierMapEnd();++it){
    60     id = (*it).second;
     59    id = it->second;
    6160    if(id == NULL || !id->hasFactory())
    6261      continue;
    63     classname = id->getName();
     62    const std::string& classname = id->getName();
    6463    network_id = id->getNetworkID();
    6564    // now push the network id and the classname to the stack
  • code/trunk/src/libraries/network/packet/ClassID.h

    r6073 r6417  
    3636namespace packet {
    3737
    38  
     38
    3939/**
    4040    @author
  • code/trunk/src/libraries/network/packet/DeleteObjects.cc

    r5781 r6417  
    4141#define _QUANTITY           _PACKETID + sizeof(Type::Value)
    4242#define _OBJECTIDS          _QUANTITY + sizeof(uint32_t)
    43  
     43
    4444DeleteObjects::DeleteObjects()
    4545 : Packet()
     
    7171  for(unsigned int i=0; i<number; i++){
    7272    unsigned int temp = Synchronisable::popDeletedObject();
    73 //     assert(temp<10000); //ugly hack
    7473    *reinterpret_cast<uint32_t*>(tdata) = temp;
    75     COUT(4) << temp << " ";
     74    COUT(4) << temp << ' ';
    7675    tdata += sizeof(uint32_t);
    7776  }
  • code/trunk/src/libraries/network/packet/FunctionCalls.cc

    r5781 r6417  
    3636namespace orxonox {
    3737namespace packet {
    38  
     38
    3939#define   PACKET_FLAGS_FUNCTIONCALLS PacketFlag::Reliable
    4040#define   _PACKETID         0
    4141const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000;
    42    
     42
    4343FunctionCalls::FunctionCalls()
    4444 : Packet()
     
    171171void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    172172  assert(!isDataENetAllocated());
    173  
     173
    174174  // first determine the size that has to be reserved for this call
    175175  uint32_t callsize = 2*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and for bool isStatic
     
    200200    }
    201201  }
    202  
     202
    203203  // now allocated mem if neccessary
    204204  if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
     
    210210    data_ = temp;
    211211  }
    212  
     212
    213213  // now serialise the mt values and copy the function id and isStatic
    214214  uint8_t* temp = data_+currentSize_;
     
    240240  //currentSize_ += callsize;
    241241  currentSize_ = temp-data_;
    242  
     242
    243243}
    244244
    245245void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){
    246246  assert(!isDataENetAllocated());
    247  
     247
    248248  // first determine the size that has to be reserved for this call
    249249  uint32_t callsize = 3*sizeof(uint32_t)+sizeof(uint8_t); //size for network-function-id and nrOfArguments and the objectID
     
    274274    }
    275275  }
    276  
     276
    277277  // now allocated mem if neccessary
    278278  if( currentSize_ + callsize > currentMemBlocks_*FUNCTIONCALLS_MEM_ALLOCATION )
     
    284284    data_ = temp;
    285285  }
    286  
     286
    287287  // now serialise the mt values and copy the function id
    288288  uint8_t* temp = data_+currentSize_;
     
    314314  }
    315315  currentSize_ += callsize;
    316  
     316
    317317}
    318318
  • code/trunk/src/libraries/network/packet/FunctionIDs.cc

    r5781 r6417  
    4747
    4848FunctionIDs::FunctionIDs( ) : Packet(){
    49   std::string functionname;
    50   unsigned int nrOfFunctions=0;
     49  unsigned int nrOfFunctions=0;
    5150  unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions
    5251  uint32_t networkID;
    5352  flags_ = flags_ | PACKET_FLAGS_FUNCTIONIDS;
    5453  std::queue<std::pair<uint32_t, std::string> > tempQueue;
    55  
     54
    5655  //calculate total needed size (for all strings and integers)
    5756  ObjectList<NetworkFunctionBase>::iterator it;
    5857  for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){
    59     functionname = it->getName();
     58    const std::string& functionname = it->getName();
    6059    networkID = it->getNetworkID();
    6160    // now push the network id and the classname to the stack
     
    6463    packetSize += (functionname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t); // reserver size for the functionname string, the functionname length and the networkID
    6564  }
    66  
     65
    6766  this->data_=new uint8_t[ packetSize ];
    6867  //set the appropriate packet id
    6968  assert(this->data_);
    7069  *(Type::Value *)(this->data_ + _PACKETID ) = Type::FunctionIDs;
    71  
     70
    7271  uint8_t *temp=data_+sizeof(uint32_t);
    7372  // save the number of all classes
    7473  *(uint32_t*)temp = nrOfFunctions;
    7574  temp += sizeof(uint32_t);
    76  
     75
    7776  // now save all classids and classnames
    7877  std::pair<uint32_t, std::string> tempPair;
     
    8584    temp+=2*sizeof(uint32_t)+tempPair.second.size()+1;
    8685  }
    87  
     86
    8887  COUT(5) << "FunctionIDs packetSize is " << packetSize << endl;
    89  
     88
    9089}
    9190
     
    106105  temp += sizeof(uint32_t);
    107106  totalsize += sizeof(uint32_t); // storage size for nr of all classes
    108  
     107
    109108  for(unsigned int i=0; i<nrOfFunctions; i++){
    110109    totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t)); // for each network function add size for id, sizeof(string) and length of string itself to totalsize
     
    121120  uint32_t stringsize;
    122121  unsigned char *functionname;
    123  
     122
    124123  COUT(4) << "=== processing functionids: " << endl;
    125124  std::pair<uint32_t, std::string> tempPair;
     
    127126  nrOfFunctions = *(uint32_t*)temp;
    128127  temp += sizeof(uint32_t);
    129  
     128
    130129  for( int i=0; i<nrOfFunctions; i++){
    131130    networkID = *(uint32_t*)temp;
  • code/trunk/src/libraries/network/packet/FunctionIDs.h

    r6073 r6417  
    3636namespace packet {
    3737
    38  
     38
    3939/**
    4040    @author
  • code/trunk/src/libraries/network/packet/Gamestate.cc

    r5929 r6417  
    9595    return false;
    9696  }
    97  
     97
    9898  // create the header object
    9999  assert( header_ == 0 );
     
    105105  ObjectList<Synchronisable>::iterator it;
    106106  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    107    
     107
    108108//     tempsize=it->getSize(id, mode);
    109109
     
    111111    if ( tempsize != 0 )
    112112      dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
    113    
     113
    114114#ifndef NDEBUG
    115115    if(currentsize+tempsize > size){
     
    362362  assert(!header_->isCompressed() && !base->header_->isCompressed());
    363363  assert(!header_->isDiffed());
    364  
     364
    365365  uint8_t *basep = GAMESTATE_START(base->data_);
    366366  uint8_t *gs = GAMESTATE_START(this->data_);
    367367  uint32_t dest_length = header_->getDataSize();
    368  
     368
    369369  if(dest_length==0)
    370370    return NULL;
    371  
     371
    372372  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    373373  uint8_t *dest = GAMESTATE_START(ndata);
    374  
     374
    375375  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
    376376#ifndef NDEBUG
     
    398398  assert(!header_->isCompressed() && !base->header_->isCompressed());
    399399  assert(header_->isDiffed());
    400  
     400
    401401  uint8_t *basep = GAMESTATE_START(base->data_);
    402402  uint8_t *gs = GAMESTATE_START(this->data_);
    403403  uint32_t dest_length = header_->getDataSize();
    404  
     404
    405405  if(dest_length==0)
    406406    return NULL;
    407  
     407
    408408  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    409409  uint8_t *dest = ndata + GamestateHeader::getSize();
    410  
     410
    411411  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
    412  
     412
    413413  Gamestate *g = new Gamestate(ndata, getClientID());
    414414  assert(g->header_);
     
    437437//   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
    438438//   uint8_t *dest = ndata + GamestateHeader::getSize();
    439 //   
    440 //   
     439//
     440//
    441441//   // LOOP-UNROLLED DIFFING
    442442//   uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
     
    465465//     }
    466466//   }
    467 // 
     467//
    468468//   Gamestate *g = new Gamestate(ndata, getClientID());
    469469//   *(g->header_) = *header_;
     
    481481  uint64_t* bd = (uint64_t*)basedata;
    482482  uint64_t* nd = (uint64_t*)newdata;
    483  
     483
    484484  unsigned int i;
    485485  for( i=0; i<datalength/8; i++ )
     
    529529//   COUT(0) << "myvector contains:";
    530530//   for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )
    531 //     COUT(0) << " " << (*itt).objID;
     531//     COUT(0) << ' ' << (*itt).objID;
    532532//   COUT(0) << endl;
    533533  for(it=dataVector_.begin(); it!=dataVector_.end();){
    534534    SynchronisableHeader oldobjectheader(origdata);
    535535    SynchronisableHeader newobjectheader(newdata);
    536     if ( (*it).objSize == 0 )
     536    if ( it->objSize == 0 )
    537537    {
    538538      ++it;
     
    541541    objectsize = oldobjectheader.getDataSize();
    542542    objectOffset=SynchronisableHeader::getSize(); //skip the size and the availableData variables in the objectheader
    543     if ( (*it).objID == oldobjectheader.getObjectID() ){
     543    if ( it->objID == oldobjectheader.getObjectID() ){
    544544      memcpy(newdata, origdata, objectsize);
    545545      assert(newobjectheader.isDataAvailable()==true);
  • code/trunk/src/libraries/network/packet/Packet.cc

    r6105 r6417  
    101101@brief
    102102    Destroys a packet completely.
    103    
    104     That also means destroying the ENetPacket if one exists. There 
     103
     104    That also means destroying the ENetPacket if one exists. There
    105105*/
    106106Packet::~Packet(){
  • code/trunk/src/libraries/network/synchronisable/CMakeLists.txt

    r5781 r6417  
    22  NetworkCallbackManager.cc
    33  Synchronisable.cc
    4   SynchronisableSpecialisations.cc
    54  SynchronisableVariable.cc
    65)
  • code/trunk/src/libraries/network/synchronisable/NetworkCallback.h

    r6073 r6417  
    3333#include "network/NetworkPrereqs.h"
    3434#include "NetworkCallbackManager.h"
     35// #include "util/MultiType.h"
    3536
    3637namespace orxonox{
    37  
     38
     39  struct EmptyType{};
     40
    3841  class _NetworkExport NetworkCallbackBase
    3942  {
     
    5861  };
    5962
     63  template <class T, class U>
     64  class NetworkCallbackNotify: public NetworkCallbackBase
     65  {
     66    public:
     67      NetworkCallbackNotify(T* object, void (T::*function) (const U&)) : object_(object), function_(function) {}
     68      NetworkCallbackNotify() {}
     69      virtual ~NetworkCallbackNotify() {}
     70      virtual void call()
     71        { (this->object_->*function_)( this->oldValue_ ); }
     72      void setOldValue(const U& value){ this->oldValue_ = value; }
     73    private:
     74      T* object_;
     75      U oldValue_;
     76      void (T::*function_) (const U&);
     77  };
     78
    6079}
    6180
  • code/trunk/src/libraries/network/synchronisable/NetworkCallbackManager.cc

    r5781 r6417  
    2626 *
    2727 */
    28  
     28
    2929#include "NetworkCallbackManager.h"
    3030#include "NetworkCallback.h"
    3131
    3232namespace orxonox{
    33  
     33
    3434  std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_;
    3535  std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_;
    36  
     36
    3737  void NetworkCallbackManager::registerCallback(NetworkCallbackBase *cb)
    38   { 
    39     callbackSet_.insert(cb); 
     38  {
     39    callbackSet_.insert(cb);
    4040  }
    4141  void NetworkCallbackManager::deleteCallback(NetworkCallbackBase *cb)
     
    4848    }
    4949  }
    50  
     50
    5151  void NetworkCallbackManager::triggerCallback(NetworkCallbackBase *cb)
    5252  {
  • code/trunk/src/libraries/network/synchronisable/NetworkCallbackManager.h

    r5781 r6417  
    3737
    3838namespace orxonox{
    39  
     39
    4040  class _NetworkExport NetworkCallbackManager{
    4141    public:
     
    4848      static std::queue<NetworkCallbackBase*> triggeredCallbacks_;
    4949  };
    50  
     50
    5151
    5252}
  • code/trunk/src/libraries/network/synchronisable/Synchronisable.cc

    r5929 r6417  
    6262    }
    6363    classID_ = static_cast<uint32_t>(-1);
    64    
     64
    6565    // set dataSize to 0
    6666    this->dataSize_ = 0;
     
    277277      //tempsize += (*i)->getSize( mode );
    278278    }
    279    
     279
    280280    tempsize += SynchronisableHeader::getSize();
    281281    header.setObjectID( this->objectID_ );
     
    284284    header.setDataAvailable( true );
    285285    header.setDataSize( tempsize );
    286    
     286
    287287#ifndef NDEBUG
    288288    uint32_t size;
     
    390390  }
    391391
     392  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     393  {
     394    SynchronisableVariableBase* sv;
     395    if (bidirectional)
     396      sv = new SynchronisableVariableBidirectional<std::string>(variable, mode, cb);
     397    else
     398      sv = new SynchronisableVariable<std::string>(variable, mode, cb);
     399    syncList.push_back(sv);
     400    stringList.push_back(sv);
     401  }
     402
    392403
    393404}
  • code/trunk/src/libraries/network/synchronisable/Synchronisable.h

    r5929 r6417  
    6666
    6767  /**
    68    * @brief: stores information about a Synchronisable 
    69    * 
     68   * @brief: stores information about a Synchronisable
     69   *
    7070   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
    7171   * in an emulated bitset.
     
    132132    inline unsigned int getPriority() const { return this->objectFrequency_;}
    133133    inline uint8_t getSyncMode() const { return this->objectMode_; }
    134    
     134
    135135    void setSyncMode(uint8_t mode);
    136136
     
    138138    Synchronisable(BaseObject* creator);
    139139    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    140     //template <class T> void unregisterVariable(T& var);
     140
    141141    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
    142142
     
    148148    bool isMyData(uint8_t* mem);
    149149    bool doSync(int32_t id, uint8_t mode=0x0);
    150    
     150
    151151    inline void setObjectID(uint32_t id){ this->objectID_ = id; objectMap_[this->objectID_] = this; }
    152152    inline void setClassID(uint32_t id){ this->classID_ = id; }
     
    167167  };
    168168
    169   // ================= Specialisation declarations
    170  
    171 //   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    172   template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    173   template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    174   template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    175   template <> _NetworkExport void Synchronisable::registerVariable( const Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    176   template <> _NetworkExport void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    177   template <> _NetworkExport void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    178   template <> _NetworkExport void Synchronisable::registerVariable( Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    179   template <> _NetworkExport void Synchronisable::registerVariable( const Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    180   template <> _NetworkExport void Synchronisable::registerVariable( Vector4& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    181   template <> _NetworkExport void Synchronisable::registerVariable( mbool& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    182   template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    183   template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    184  
    185169  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    186170  {
    187171    if (bidirectional)
    188172    {
    189       syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
     173      syncList.push_back(new SynchronisableVariableBidirectional<T>(variable, mode, cb));
    190174      this->dataSize_ += syncList.back()->getSize(state_);
    191175    }
    192176    else
    193177    {
    194       syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
     178      syncList.push_back(new SynchronisableVariable<T>(variable, mode, cb));
    195179      if ( this->state_ == mode )
    196180        this->dataSize_ += syncList.back()->getSize(state_);
    197181    }
    198182  }
    199  
     183
     184  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    200185
    201186
    202 //   template <class T> void Synchronisable::unregisterVariable(T& var){
    203 //     std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
    204 //     while(it!=syncList.end()){
    205 //       if( ((*it)->getReference()) == &var ){
    206 //         delete (*it);
    207 //         syncList.erase(it);
    208 //         return;
    209 //       }
    210 //       else
    211 //         it++;
    212 //     }
    213 //     bool unregistered_nonexistent_variable = false;
    214 //     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
    215 //     // the variable has not been registered before
    216 //   }
    217 
    218  
    219187}
    220188
  • code/trunk/src/libraries/network/synchronisable/SynchronisableVariable.h

    r5781 r6417  
    3535#include <cassert>
    3636#include <cstring>
    37 #include "util/Serialise.h"
     37#include "Serialise.h"
    3838#include "util/TypeTraits.h"
    3939#include "core/GameMode.h"
     
    4141
    4242namespace orxonox{
    43  
     43
    4444  namespace VariableDirection{
    4545    enum Value{
     
    5454    };
    5555  }
    56  
     56
    5757  class _NetworkExport SynchronisableVariableBase
    5858  {
     
    8181      virtual inline void* getReference(){ return static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->variable_)); }
    8282    protected:
    83      
    84       T& variable_;
    85       uint8_t mode_;
    86       NetworkCallbackBase *callback_;
     83      T&                       variable_;
     84      uint8_t                  mode_;
     85      NetworkCallbackBase      *callback_;
    8786  };
    88  
     87
    8988  template <class T>
    9089  class SynchronisableVariableBidirectional: public SynchronisableVariable<T>
     
    9392      SynchronisableVariableBidirectional(T& variable, uint8_t master=Bidirectionality::ServerMaster, NetworkCallbackBase *cb=0);
    9493      virtual ~SynchronisableVariableBidirectional();
    95      
     94
    9695      virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^
    9796      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
     
    113112    }
    114113  }
    115  
     114
    116115  template <class T> SynchronisableVariable<T>::~SynchronisableVariable()
    117116  {
    118     if (this->callback_ != 0)
     117    if (this->callback_)
    119118    {
    120119      NetworkCallbackManager::deleteCallback(this->callback_); //safe call for deletion
     
    141140      return;
    142141  // check whether we need to consider a callback
    143     if ( this->callback_ != 0 )
    144     {
    145       if( forceCallback || !checkEquality( this->variable_, mem ) )
    146         callback = true;
     142    if ( this->callback_ )
     143    {
     144      callback = forceCallback || !checkEquality( this->variable_, mem );
     145    }
     146  // now do a callback if neccessary
     147    if ( callback )
     148    {
     149      NetworkCallbackManager::triggerCallback( this->callback_ );
    147150    }
    148151  // write the data
    149152    loadAndIncrease( this->variable_, mem );
    150   // now do a callback if neccessary
    151     if ( callback )
    152       NetworkCallbackManager::triggerCallback( this->callback_ );
    153153  }
    154154
     
    216216            mem += sizeof(varReference_);
    217217            memcpy(static_cast<void*>(const_cast<typename Loki::TypeTraits<T>::UnqualifiedType*>(&this->varBuffer_)), &this->variable_, sizeof(T));
    218             if ( this->callback_ != 0 )
     218            if ( this->callback_ )
    219219              callback = true;
    220220          }
     
    235235          {
    236236            // value changed so remark for callback
    237             if ( this->callback_ != 0 )
     237            if ( this->callback_ )
    238238              callback = true;
    239239          }
    240240        }
    241241      }
     242  // now do a callback if neccessary
     243      if ( callback )
     244      {
     245        NetworkCallbackManager::triggerCallback( this->callback_ );
     246      }
    242247  // now write the data
    243248      loadAndIncrease(this->variable_, mem);
    244   // now do a callback if neccessary
    245       if ( callback )
    246         NetworkCallbackManager::triggerCallback( this->callback_ );
    247249    }
    248250
     
    251253      return returnSize( this->variable_ ) + sizeof(varReference_);
    252254    }
    253  
     255
    254256
    255257}
Note: See TracChangeset for help on using the changeset viewer.