- Timestamp:
- Sep 3, 2010, 1:06:52 AM (14 years ago)
- Location:
- code/branches/doc/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/util/Clock.cc
r6417 r7331 50 50 long, which will eventually overflow. But if you use the subtraction of 51 51 the current time minus the last time the timer gave us and sum these up to 52 a 64 bit integer, we get the desired result. 52 a 64 bit integer, we get the desired result. <br> 53 53 Also mind that we don't have to store the last timer's time as unsigned long 54 54 as well because (unsigned long)tickTime_ will do exactly that. -
code/branches/doc/src/libraries/util/Clock.h
r6417 r7331 35 35 namespace orxonox 36 36 { 37 /** Simple real time clock based on Ogre::Timer 38 @details 39 The class can be used to both capture the current real time or to 40 incrementally capture the time and then distribute that time information 41 via Clock& references (for instance for the game tick). <br> 42 Precision: <br> 43 The maximum precision is given by the Ogre::Timer and that is somewhere 44 in the microsecond range for both Windows and UNIX. 45 @remarks 46 For proper functionality this class MUST be used in the same thread! <br> 47 Further more it might be possible that the Ogre::Timer has a performance 48 caveat on Windows because it will only capture the time on the same 49 CPU core. Confining the main thread to one process could speed up the game. 50 See command line argument 'limitToCPU'. 51 */ 37 52 class _UtilExport Clock 38 53 { 39 54 public: 55 //! Starts the time at 0 40 56 Clock(); 41 57 ~Clock(); 42 58 59 //! Internally captures the time and stays at that particular time 43 60 void capture(); 44 61 45 unsigned long long getMicroseconds() const { return tickTime_; } 46 unsigned long long getMilliseconds() const { return tickTime_ / 1000; } 47 unsigned long getSeconds() const { return static_cast<long> (tickTime_ / 1000000); } 48 float getSecondsPrecise() const { return static_cast<float>(tickTime_ / 1000000.0f); } 62 //! Returns the last captured absolute time in microseconds 63 unsigned long long getMicroseconds() const 64 { return tickTime_; } 65 //! Returns the last captured absolute time in milliseconds 66 unsigned long long getMilliseconds() const 67 { return tickTime_ / 1000; } 68 //! Returns the last captured absolute time in seconds 69 unsigned long getSeconds() const 70 { return static_cast<long> (tickTime_ / 1000000); } 71 //! Returns the last captured absolute time in seconds as float 72 float getSecondsPrecise() const 73 { return static_cast<float>(tickTime_ / 1000000.0f); } 49 74 50 float getDeltaTime() const { return tickDtFloat_; } 51 long getDeltaTimeMicroseconds() const { return tickDt_; } 75 //! Returns the timespan in seconds between the last two calls to capture() 76 float getDeltaTime() const 77 { return tickDtFloat_; } 78 //! Returns the timespan in microseconds between the last two calls to capture() 79 long getDeltaTimeMicroseconds() const 80 { return tickDt_; } 52 81 82 /** Returns the current real time in microseconds 83 @note 84 This is especially useful to measure execution times because of the 85 high precision. 86 */ 53 87 unsigned long long getRealMicroseconds() const; 54 88 55 89 private: 90 //! Undefined 56 91 Clock(const Clock& instance); 57 92 58 Ogre::Timer* timer_; 59 unsigned long long tickTime_; 60 long tickDt_; 61 float tickDtFloat_; 93 Ogre::Timer* timer_; //!< Ogre timer object 94 unsigned long long tickTime_; //!< Currently captured time 95 long tickDt_; //!< Delta time in microseconds (cache value) 96 float tickDtFloat_; //!< Delta time in seconds (cache value) 62 97 }; 63 98 }
Note: See TracChangeset
for help on using the changeset viewer.