Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 11, 2009, 12:04:21 AM (15 years ago)
Author:
rgrieder
Message:

Simplified the Clock code a little (doesn't mean it got simpler though ).

Location:
code/branches/presentation2/src/libraries/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/util/Clock.cc

    r5929 r6319  
    3434    Clock::Clock()
    3535        : timer_(new Ogre::Timer())
    36         , storedTime_(0)
    3736        , tickTime_(0)
    3837        , tickDt_(0)
    3938        , tickDtFloat_(0.0f)
    40         , lastTimersTime_(0)
    4139    {
    4240    }
     
    4745    }
    4846   
     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    */
    4956    void Clock::capture()
    5057    {
    51         unsigned long timersTime = timer_->getMicroseconds();
    52         tickTime_ = storedTime_ + timersTime;
    53         tickDt_ = timersTime - lastTimersTime_;
     58        tickDt_ = timer_->getMicroseconds() - (unsigned long)tickTime_;
     59        tickTime_ += tickDt_;
    5460        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 bit
    59             storedTime_ += timersTime;
    60             lastTimersTime_ = 0;
    61             timer_->reset();
    62         }
    63         else
    64         {
    65             lastTimersTime_ = timersTime;
    66         }
    6761    }
    6862
    6963    unsigned long long Clock::getRealMicroseconds() const
    7064    {
    71         return this->timer_->getMicroseconds() + this->storedTime_;
     65        return tickTime_ + (timer_->getMicroseconds() - (unsigned long)tickTime_);
    7266    }
    7367}
  • code/branches/presentation2/src/libraries/util/Clock.h

    r5929 r6319  
    5757
    5858        Ogre::Timer*       timer_;
    59         unsigned long long storedTime_;
    6059        unsigned long long tickTime_;
    6160        long               tickDt_;
    6261        float              tickDtFloat_;
    63         unsigned long      lastTimersTime_;
    6462    };
    6563}
Note: See TracChangeset for help on using the changeset viewer.