[Orxonox-commit 1601] r6319 - code/branches/presentation2/src/libraries/util

rgrieder at orxonox.net rgrieder at orxonox.net
Fri Dec 11 00:04:21 CET 2009


Author: rgrieder
Date: 2009-12-11 00:04:21 +0100 (Fri, 11 Dec 2009)
New Revision: 6319

Modified:
   code/branches/presentation2/src/libraries/util/Clock.cc
   code/branches/presentation2/src/libraries/util/Clock.h
Log:
Simplified the Clock code a little (doesn't mean it got simpler though ^^).

Modified: code/branches/presentation2/src/libraries/util/Clock.cc
===================================================================
--- code/branches/presentation2/src/libraries/util/Clock.cc	2009-12-10 22:40:07 UTC (rev 6318)
+++ code/branches/presentation2/src/libraries/util/Clock.cc	2009-12-10 23:04:21 UTC (rev 6319)
@@ -33,11 +33,9 @@
 {
     Clock::Clock()
         : timer_(new Ogre::Timer())
-        , storedTime_(0)
         , tickTime_(0)
         , tickDt_(0)
         , tickDtFloat_(0.0f)
-        , lastTimersTime_(0)
     {
     }
 
@@ -46,28 +44,24 @@
         delete timer_;
     }
     
+    /**
+    @remarks
+        Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned
+        long, which will eventually overflow. But if you use the subtraction of
+        the current time minus the last time the timer gave us and sum these up to
+        a 64 bit integer, we get the desired result.
+        Also mind that we don't have to store the last timer's time as unsigned long
+        as well because (unsigned long)tickTime_ will do exactly that.
+    */
     void Clock::capture()
     {
-        unsigned long timersTime = timer_->getMicroseconds();
-        tickTime_ = storedTime_ + timersTime;
-        tickDt_ = timersTime - lastTimersTime_;
+        tickDt_ = timer_->getMicroseconds() - (unsigned long)tickTime_;
+        tickTime_ += tickDt_;
         tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
-
-        if (timersTime > 0xFFFFFFFF/4)
-        {
-            // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
-            storedTime_ += timersTime;
-            lastTimersTime_ = 0;
-            timer_->reset();
-        }
-        else
-        {
-            lastTimersTime_ = timersTime;
-        }
     }
 
     unsigned long long Clock::getRealMicroseconds() const
     {
-        return this->timer_->getMicroseconds() + this->storedTime_;
+        return tickTime_ + (timer_->getMicroseconds() - (unsigned long)tickTime_);
     }
 }

Modified: code/branches/presentation2/src/libraries/util/Clock.h
===================================================================
--- code/branches/presentation2/src/libraries/util/Clock.h	2009-12-10 22:40:07 UTC (rev 6318)
+++ code/branches/presentation2/src/libraries/util/Clock.h	2009-12-10 23:04:21 UTC (rev 6319)
@@ -56,11 +56,9 @@
         Clock(const Clock& instance);
 
         Ogre::Timer*       timer_;
-        unsigned long long storedTime_;
         unsigned long long tickTime_;
         long               tickDt_;
         float              tickDtFloat_;
-        unsigned long      lastTimersTime_;
     };
 }
 




More information about the Orxonox-commit mailing list