Changeset 6319 for code/branches/presentation2/src/libraries
- Timestamp:
- Dec 11, 2009, 12:04:21 AM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/util/Clock.cc
r5929 r6319 34 34 Clock::Clock() 35 35 : timer_(new Ogre::Timer()) 36 , storedTime_(0)37 36 , tickTime_(0) 38 37 , tickDt_(0) 39 38 , tickDtFloat_(0.0f) 40 , lastTimersTime_(0)41 39 { 42 40 } … … 47 45 } 48 46 47 /** 48 @remarks 49 Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned 50 long, which will eventually overflow. But if you use the subtraction of 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. 53 Also mind that we don't have to store the last timer's time as unsigned long 54 as well because (unsigned long)tickTime_ will do exactly that. 55 */ 49 56 void Clock::capture() 50 57 { 51 unsigned long timersTime = timer_->getMicroseconds(); 52 tickTime_ = storedTime_ + timersTime; 53 tickDt_ = timersTime - lastTimersTime_; 58 tickDt_ = timer_->getMicroseconds() - (unsigned long)tickTime_; 59 tickTime_ += tickDt_; 54 60 tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f; 55 56 if (timersTime > 0xFFFFFFFF/4)57 {58 // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit59 storedTime_ += timersTime;60 lastTimersTime_ = 0;61 timer_->reset();62 }63 else64 {65 lastTimersTime_ = timersTime;66 }67 61 } 68 62 69 63 unsigned long long Clock::getRealMicroseconds() const 70 64 { 71 return t his->timer_->getMicroseconds() + this->storedTime_;65 return tickTime_ + (timer_->getMicroseconds() - (unsigned long)tickTime_); 72 66 } 73 67 } -
code/branches/presentation2/src/libraries/util/Clock.h
r5929 r6319 57 57 58 58 Ogre::Timer* timer_; 59 unsigned long long storedTime_;60 59 unsigned long long tickTime_; 61 60 long tickDt_; 62 61 float tickDtFloat_; 63 unsigned long lastTimersTime_;64 62 }; 65 63 }
Note: See TracChangeset
for help on using the changeset viewer.