Changeset 6160 for code/branches/presentation2
- Timestamp:
- Nov 26, 2009, 2:11:48 PM (15 years ago)
- Location:
- code/branches/presentation2/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/network/NetworkFunction.cc
r5929 r6160 32 32 namespace orxonox 33 33 { 34 std::map<std::string, NetworkFunctionBase*> NetworkFunctionBase::nameMap_;35 34 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 40 36 std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_; … … 49 45 50 46 this->name_ = name; 51 nameMap_[name] = this;47 NetworkFunctionBase::getNameMap()[name] = this; 52 48 } 53 49 NetworkFunctionBase::~NetworkFunctionBase() … … 58 54 void NetworkFunctionBase::destroyAllNetworkFunctions() 59 55 { 56 std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap(); 60 57 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 ) 62 59 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_; 63 67 } 64 68 … … 70 74 71 75 this->functor_ = functor; 72 functorMap_[p] = this;73 idMap_[ this->getNetworkID() ] = this;76 NetworkFunctionStatic::getFunctorMap()[p] = this; 77 NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this; 74 78 } 75 79 … … 79 83 } 80 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 } 81 96 82 97 … … 86 101 RegisterObject(NetworkMemberFunctionBase); 87 102 88 functorMap_[p] = this;89 idMap_[ this->getNetworkID() ] = this;103 this->functorMap_[p] = this; 104 this->idMap_[ this->getNetworkID() ] = this; 90 105 } 91 106 -
code/branches/presentation2/src/libraries/network/NetworkFunction.h
r5781 r6160 80 80 static inline bool isStatic( uint32_t networkID ) { return isStaticMap_[networkID]; } 81 81 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 } 83 88 84 89 static void destroyAllNetworkFunctions(); … … 88 93 89 94 private: 90 static std::map<std::string, NetworkFunctionBase*> nameMap_;95 static std::map<std::string, NetworkFunctionBase*>& getNameMap(); 91 96 uint32_t networkID_; 92 97 std::string name_; … … 107 112 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 113 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(); 118 126 FunctorStatic* functor_; 119 127 -
code/branches/presentation2/src/libraries/tools/interfaces/TimeFactorListener.h
r5781 r6160 37 37 class _ToolsExport TimeFactorListener : virtual public OrxonoxClass 38 38 { 39 friend class GSRoot;40 41 39 public: 42 40 TimeFactorListener(); 43 41 virtual ~TimeFactorListener() {} 42 43 static void setTimeFactor( float factor ); 44 static void setTimeFactorInternal( float factor ); 45 static inline float getTimeFactor(){ return TimeFactorListener::timefactor_s; } 44 46 45 47 protected: 46 48 virtual void changedTimeFactor(float factor_new, float factor_old) {} 47 inline float getTimeFactor() const48 { return TimeFactorListener::timefactor_s; }49 49 50 50 private: -
code/branches/presentation2/src/libraries/tools/interfaces/ToolsInterfaceCompilation.cc
r5781 r6160 37 37 38 38 #include "core/CoreIncludes.h" 39 #include "core/GameMode.h" 40 #include "network/NetworkFunction.h" 39 41 40 42 namespace orxonox … … 43 45 // TimeFactorListener 44 46 //---------------------------- 47 registerStaticNetworkFunction( &TimeFactorListener::setTimeFactorInternal ); 48 45 49 float TimeFactorListener::timefactor_s = 1.0f; 46 50 … … 48 52 { 49 53 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); 50 69 } 51 70 -
code/branches/presentation2/src/orxonox/gamestates/GSRoot.cc
r6105 r6160 45 45 GSRoot::GSRoot(const GameStateInfo& info) 46 46 : GameState(info) 47 , timeFactor_(1.0f)48 47 , bPaused_(false) 49 48 , timeFactorPauseBackup_(1.0f) … … 73 72 { 74 73 // reset game speed to normal 75 this->timeFactor_ = 1.0f;74 TimeFactorListener::setTimeFactor(1.0f); 76 75 77 76 // time factor console command … … 102 101 } 103 102 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ) 104 (it++)->tick(leveldt * this->timeFactor_);103 (it++)->tick(leveldt * TimeFactorListener::getTimeFactor()); 105 104 /*** HACK *** HACK ***/ 106 105 } … … 119 118 if (!this->bPaused_) 120 119 { 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); 127 121 } 128 122 else … … 137 131 if (!this->bPaused_) 138 132 { 139 this->timeFactorPauseBackup_ = this->timeFactor_;133 this->timeFactorPauseBackup_ = TimeFactorListener::getTimeFactor(); 140 134 this->setTimeFactor(0.0f); 141 135 this->bPaused_ = true; … … 148 142 } 149 143 } 144 145 float GSRoot::getTimeFactor() 146 { 147 return TimeFactorListener::getTimeFactor(); 148 } 150 149 } -
code/branches/presentation2/src/orxonox/gamestates/GSRoot.h
r5929 r6160 51 51 void setTimeFactor(float factor); 52 52 void pause(); 53 float getTimeFactor() { return this->timeFactor_; }53 float getTimeFactor(); 54 54 55 55 private: 56 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal.57 56 bool bPaused_; 58 57 float timeFactorPauseBackup_;
Note: See TracChangeset
for help on using the changeset viewer.