Changeset 1755 for code/trunk/src/orxonox/tools/Timer.h
- Timestamp:
- Sep 10, 2008, 1:37:36 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/gui (added) merged: 1636,1638,1640-1647,1649-1654,1656,1659-1665,1670,1672-1674,1686,1688-1692,1694-1697,1704 /code/branches/input (added) merged: 1629-1630
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/tools/Timer.h
r1608 r1755 62 62 63 63 #include "OrxonoxPrereqs.h" 64 #include " objects/Tickable.h"64 #include "core/OrxonoxClass.h" 65 65 66 66 namespace orxonox … … 72 72 73 73 //! TimerBase is the parent of the Timer class. 74 class _OrxonoxExport TimerBase : public Tickable74 class _OrxonoxExport TimerBase : public OrxonoxClass 75 75 { 76 76 public: … … 97 97 /** @brief Returns the remaining time until the Timer calls the function. @return The remaining time */ 98 98 inline float getRemainingTime() const 99 { return this->time_; }99 { return (float)this->time_ / 1000000.0f; } 100 100 /** @brief Gives the Timer some extra time. @param time The amount of extra time in seconds */ 101 101 inline void addTime(float time) 102 { this->time_ += time; }102 { if (time > 0.0f) this->time_ += (long long)(time * 1000000.0f); } 103 103 /** @brief Decreases the remaining time of the Timer. @param time The amount of time to remove */ 104 104 inline void removeTime(float time) 105 { this->time_ -= time; }105 { if (time > 0.0f) this->time_ -= (long long)(time * 1000000.0f); } 106 106 /** @brief Sets the interval of the Timer. @param interval The interval */ 107 107 inline void setInterval(float interval) 108 { this->interval_ = interval; }108 { this->interval_ = (long long)(interval * 1000000.0f); } 109 109 /** @brief Sets bLoop to a given value. @param bLoop True = loop */ 110 110 inline void setLoop(bool bLoop) 111 111 { this->bLoop_ = bLoop; } 112 112 113 void tick( float dt);113 void tick(const Clock& time); 114 114 115 115 protected: … … 118 118 Executor* executor_; //!< The executor of the function that should be called when the time expires 119 119 120 float interval_; //!< The time-interval inseconds120 long long interval_; //!< The time-interval in micro seconds 121 121 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 122 122 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 123 123 124 float time_;//!< Internal variable, counting the time till the next function-call124 long long time_; //!< Internal variable, counting the time till the next function-call 125 125 }; 126 126 … … 155 155 this->deleteExecutor(); 156 156 157 this-> interval_ = interval;157 this->setInterval(interval); 158 158 this->bLoop_ = bLoop; 159 159 executor->setObject(object); … … 161 161 this->bActive_ = true; 162 162 163 this->time_ = interval;163 this->time_ = this->interval_; 164 164 } 165 165 }; … … 193 193 this->deleteExecutor(); 194 194 195 this-> interval_ = interval;195 this->setInterval(interval); 196 196 this->bLoop_ = bLoop; 197 197 this->executor_ = (Executor*)executor; 198 198 this->bActive_ = true; 199 199 200 this->time_ = interval;200 this->time_ = this->interval_; 201 201 } 202 202 };
Note: See TracChangeset
for help on using the changeset viewer.