Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 26, 2009, 2:11:48 PM (15 years ago)
Author:
scheusso
Message:

server may now pause/slow the game (also on clients) with commands setTimeFactor & pause

Location:
code/branches/presentation2/src/libraries/network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/network/NetworkFunction.cc

    r5929 r6160  
    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_;
    3935     
    4036  std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_;
     
    4945   
    5046    this->name_ = name;
    51     nameMap_[name] = this;
     47    NetworkFunctionBase::getNameMap()[name] = this;
    5248  }
    5349  NetworkFunctionBase::~NetworkFunctionBase()
     
    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();
     60  }
     61 
     62 
     63  /*static*/ std::map<std::string, NetworkFunctionBase*>& NetworkFunctionBase::getNameMap()
     64  {
     65    static std::map<std::string, NetworkFunctionBase*> nameMap_;
     66    return nameMap_;
    6367  }
    6468 
     
    7074   
    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  }
    7579 
     
    7983  }
    8084 
     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  }
    8196 
    8297 
     
    86101    RegisterObject(NetworkMemberFunctionBase);
    87102   
    88     functorMap_[p] = this;
    89     idMap_[ this->getNetworkID() ] = this;
     103    this->functorMap_[p] = this;
     104    this->idMap_[ this->getNetworkID() ] = this;
    90105  }
    91106 
  • code/branches/presentation2/src/libraries/network/NetworkFunction.h

    r5781 r6160  
    8080    static inline bool  isStatic( uint32_t networkID )  { return isStaticMap_[networkID]; }
    8181   
    82     static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); }
     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    }
    8388   
    8489    static void destroyAllNetworkFunctions();
     
    8893   
    8994  private:
    90     static std::map<std::string, NetworkFunctionBase*> nameMap_;
     95    static std::map<std::string, NetworkFunctionBase*>& getNameMap();
    9196    uint32_t networkID_;
    9297    std::string name_;
     
    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); }
    108113   
    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    
     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_;
    119127   
Note: See TracChangeset for help on using the changeset viewer.