Changeset 1968 for code/branches/objecthierarchy/src/orxonox/tools
- Timestamp:
- Oct 20, 2008, 1:47:41 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/tools/Timer.cc
r1755 r1968 92 92 this->bLoop_ = false; 93 93 this->bActive_ = false; 94 this->bKillAfterCall_ = false; 94 95 95 96 this->time_ = 0; … … 112 113 { 113 114 (*this->executor_)(); 115 116 if (this->bKillAfterCall_) 117 delete this; 114 118 } 115 119 … … 136 140 { 137 141 // It's time to call the function 138 if (this->bLoop_ )142 if (this->bLoop_ && !this->bKillAfterCall_) 139 143 { 140 144 this->time_ += this->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously. -
code/branches/objecthierarchy/src/orxonox/tools/Timer.h
r1755 r1968 116 116 TimerBase(); 117 117 118 Executor* executor_; //!< The executor of the function that should be called when the time expires 119 120 long long interval_; //!< The time-interval in micro seconds 121 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 122 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 123 124 long long time_; //!< Internal variable, counting the time till the next function-call 118 Executor* executor_; //!< The executor of the function that should be called when the time expires 119 120 long long interval_; //!< The time-interval in micro seconds 121 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 122 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 123 bool bKillAfterCall_; //!< If true the timer gets deleted after it called the function 124 125 long long time_; //!< Internal variable, counting the time till the next function-call 125 126 }; 126 127 … … 139 140 @param exeuctor A executor of the function to call 140 141 */ 141 Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor )142 { 143 this->setTimer(interval, bLoop, object, exeuctor );142 Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false) 143 { 144 this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall); 144 145 } 145 146 … … 151 152 @param exeuctor A executor of the function to call 152 153 */ 153 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor )154 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false) 154 155 { 155 156 this->deleteExecutor(); … … 162 163 163 164 this->time_ = this->interval_; 165 this->bKillAfterCall_ = bKillAfterCall; 164 166 } 165 167 }; … … 177 179 @param exeuctor A executor of the function to call 178 180 */ 179 StaticTimer(float interval, bool bLoop, ExecutorStatic* executor )180 { 181 this->setTimer(interval, bLoop, executor );181 StaticTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false) 182 { 183 this->setTimer(interval, bLoop, executor, bKillAfterCall); 182 184 } 183 185 … … 189 191 @param executor A executor of the function to call 190 192 */ 191 void setTimer(float interval, bool bLoop, ExecutorStatic* executor )193 void setTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false) 192 194 { 193 195 this->deleteExecutor(); … … 199 201 200 202 this->time_ = this->interval_; 203 this->bKillAfterCall_ = bKillAfterCall; 201 204 } 202 205 };
Note: See TracChangeset
for help on using the changeset viewer.