Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6160


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
Files:
6 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   
  • code/branches/presentation2/src/libraries/tools/interfaces/TimeFactorListener.h

    r5781 r6160  
    3737    class _ToolsExport TimeFactorListener : virtual public OrxonoxClass
    3838    {
    39         friend class GSRoot;
    40 
    4139        public:
    4240            TimeFactorListener();
    4341            virtual ~TimeFactorListener() {}
     42           
     43            static void setTimeFactor( float factor );
     44            static void setTimeFactorInternal( float factor );
     45            static inline float getTimeFactor(){ return TimeFactorListener::timefactor_s; }
    4446
    4547        protected:
    4648            virtual void changedTimeFactor(float factor_new, float factor_old) {}
    47             inline float getTimeFactor() const
    48                 { return TimeFactorListener::timefactor_s; }
    4949
    5050        private:
  • code/branches/presentation2/src/libraries/tools/interfaces/ToolsInterfaceCompilation.cc

    r5781 r6160  
    3737
    3838#include "core/CoreIncludes.h"
     39#include "core/GameMode.h"
     40#include "network/NetworkFunction.h"
    3941
    4042namespace orxonox
     
    4345    // TimeFactorListener
    4446    //----------------------------
     47    registerStaticNetworkFunction( &TimeFactorListener::setTimeFactorInternal );
     48   
    4549    float TimeFactorListener::timefactor_s = 1.0f;
    4650
     
    4852    {
    4953        RegisterRootObject(TimeFactorListener);
     54    }
     55
     56    /*static*/ void TimeFactorListener::setTimeFactor( float factor )
     57    {
     58        if ( !GameMode::isStandalone() )
     59            callStaticNetworkFunction( &TimeFactorListener::setTimeFactorInternal, CLIENTID_UNKNOWN, factor );
     60        TimeFactorListener::setTimeFactorInternal(factor);
     61    }
     62   
     63    /*static*/ void TimeFactorListener::setTimeFactorInternal( float factor )
     64    {
     65        float oldFactor = TimeFactorListener::timefactor_s;
     66        TimeFactorListener::timefactor_s = factor;
     67        for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
     68            it->changedTimeFactor(factor, oldFactor);
    5069    }
    5170
  • code/branches/presentation2/src/orxonox/gamestates/GSRoot.cc

    r6105 r6160  
    4545    GSRoot::GSRoot(const GameStateInfo& info)
    4646        : GameState(info)
    47         , timeFactor_(1.0f)
    4847        , bPaused_(false)
    4948        , timeFactorPauseBackup_(1.0f)
     
    7372    {
    7473        // reset game speed to normal
    75         this->timeFactor_ = 1.0f;
     74        TimeFactorListener::setTimeFactor(1.0f);
    7675
    7776        // time factor console command
     
    102101        }
    103102        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; )
    104             (it++)->tick(leveldt * this->timeFactor_);
     103            (it++)->tick(leveldt * TimeFactorListener::getTimeFactor());
    105104        /*** HACK *** HACK ***/
    106105    }
     
    119118            if (!this->bPaused_)
    120119            {
    121                 TimeFactorListener::timefactor_s = factor;
    122 
    123                 for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
    124                     it->changedTimeFactor(factor, this->timeFactor_);
    125 
    126                 this->timeFactor_ = factor;
     120                TimeFactorListener::setTimeFactor(factor);
    127121            }
    128122            else
     
    137131            if (!this->bPaused_)
    138132            {
    139                 this->timeFactorPauseBackup_ = this->timeFactor_;
     133                this->timeFactorPauseBackup_ = TimeFactorListener::getTimeFactor();
    140134                this->setTimeFactor(0.0f);
    141135                this->bPaused_ = true;
     
    148142        }
    149143    }
     144
     145    float GSRoot::getTimeFactor()
     146    {
     147        return TimeFactorListener::getTimeFactor();
     148    }
    150149}
  • code/branches/presentation2/src/orxonox/gamestates/GSRoot.h

    r5929 r6160  
    5151        void setTimeFactor(float factor);
    5252        void pause();
    53         float getTimeFactor() { return this->timeFactor_; }
     53        float getTimeFactor();
    5454
    5555    private:
    56         float                 timeFactor_;              //!< A factor that sets the gamespeed. 1 is normal.
    5756        bool                  bPaused_;
    5857        float                 timeFactorPauseBackup_;
Note: See TracChangeset for help on using the changeset viewer.