Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7995


Ignore:
Timestamp:
Feb 28, 2011, 3:47:08 AM (13 years ago)
Author:
rgrieder
Message:

Changed call to frame rendering in GraphicsManager so that Ogre always receives exactly the delta times it expects.
Just to be sure.

Location:
code/branches/usability/src/libraries/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/core/GraphicsManager.cc

    r7993 r7995  
    106106        , renderWindow_(0)
    107107        , viewport_(0)
     108        , lastFrameStartTime_(0.0f)
     109        , lastFrameEndTime_(0.0f)
    108110    {
    109111        RegisterObject(GraphicsManager);
     
    364366    @note
    365367        A note about the Ogre::FrameListener: Even though we don't use them,
    366         they still get called. However, the delta times are not correct (except
    367         for timeSinceLastFrame, which is the most important). A little research
    368         as shown that there is probably only one FrameListener that doesn't even
    369         need the time. So we shouldn't run into problems.
     368        they still get called.
    370369    */
    371370    void GraphicsManager::postUpdate(const Clock& time)
    372371    {
     372        // Time before rendering
     373        uint64_t timeBeforeTick = time.getRealMicroseconds();
     374
     375        // Ogre's time keeping object
    373376        Ogre::FrameEvent evt;
    374         evt.timeSinceLastFrame = time.getDeltaTime();
    375         evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
    376 
    377         // don't forget to call _fireFrameStarted to OGRE to make sure
    378         // everything goes smoothly
     377
     378        // Translate to Ogre float times before the update
     379        float temp = lastFrameStartTime_;
     380        lastFrameStartTime_ = (float)(timeBeforeTick / 1000000);
     381        evt.timeSinceLastFrame = lastFrameStartTime_ - temp;
     382        evt.timeSinceLastEvent = lastFrameStartTime_ - lastFrameEndTime_;
     383
     384        // Ogre requires the time too
    379385        ogreRoot_->_fireFrameStarted(evt);
    380386
     
    382388        // This calls the WindowEventListener objects.
    383389        Ogre::WindowEventUtilities::messagePump();
    384         // make sure the window stays active even when not focused
     390        // Make sure the window stays active even when not focused
    385391        // (probably only necessary on windows)
    386392        this->renderWindow_->setActive(true);
    387 
    388         // Time before rendering
    389         uint64_t timeBeforeTick = time.getRealMicroseconds();
    390393
    391394        // Render frame
     
    396399        Game::getInstance().subtractTickTime((int32_t)(timeAfterTick - timeBeforeTick));
    397400
    398         // again, just to be sure OGRE works fine
    399         ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
     401        // Translate to Ogre float times after the update
     402        temp = lastFrameEndTime_;
     403        lastFrameEndTime_ = (float)(timeAfterTick / 1000000);
     404        evt.timeSinceLastFrame = lastFrameEndTime_ - temp;
     405        evt.timeSinceLastEvent = lastFrameEndTime_ - lastFrameStartTime_;
     406
     407        // Ogre also needs the time after the frame finished
     408        ogreRoot_->_fireFrameEnded(evt);
    400409    }
    401410
  • code/branches/usability/src/libraries/core/GraphicsManager.h

    r7993 r7995  
    109109        Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
    110110        Ogre::Viewport*     viewport_;                 //!< default full size viewport
     111        float               lastFrameStartTime_;       //!< Time stamp of the beginning of the last frame
     112        float               lastFrameEndTime_;         //!< Time stamp of the end of the last frame
    111113
    112114        // XML files for the resources and the debug overlay
Note: See TracChangeset for help on using the changeset viewer.