[Orxonox-commit 3306] r7995 - code/branches/usability/src/libraries/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Feb 28 03:47:09 CET 2011
Author: rgrieder
Date: 2011-02-28 03:47:08 +0100 (Mon, 28 Feb 2011)
New Revision: 7995
Modified:
code/branches/usability/src/libraries/core/GraphicsManager.cc
code/branches/usability/src/libraries/core/GraphicsManager.h
Log:
Changed call to frame rendering in GraphicsManager so that Ogre always receives exactly the delta times it expects.
Just to be sure.
Modified: code/branches/usability/src/libraries/core/GraphicsManager.cc
===================================================================
--- code/branches/usability/src/libraries/core/GraphicsManager.cc 2011-02-27 18:01:07 UTC (rev 7994)
+++ code/branches/usability/src/libraries/core/GraphicsManager.cc 2011-02-28 02:47:08 UTC (rev 7995)
@@ -105,6 +105,8 @@
#endif
, renderWindow_(0)
, viewport_(0)
+ , lastFrameStartTime_(0.0f)
+ , lastFrameEndTime_(0.0f)
{
RegisterObject(GraphicsManager);
@@ -363,31 +365,32 @@
/**
@note
A note about the Ogre::FrameListener: Even though we don't use them,
- they still get called. However, the delta times are not correct (except
- for timeSinceLastFrame, which is the most important). A little research
- as shown that there is probably only one FrameListener that doesn't even
- need the time. So we shouldn't run into problems.
+ they still get called.
*/
void GraphicsManager::postUpdate(const Clock& time)
{
+ // Time before rendering
+ uint64_t timeBeforeTick = time.getRealMicroseconds();
+
+ // Ogre's time keeping object
Ogre::FrameEvent evt;
- evt.timeSinceLastFrame = time.getDeltaTime();
- evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
- // don't forget to call _fireFrameStarted to OGRE to make sure
- // everything goes smoothly
+ // Translate to Ogre float times before the update
+ float temp = lastFrameStartTime_;
+ lastFrameStartTime_ = (float)(timeBeforeTick / 1000000);
+ evt.timeSinceLastFrame = lastFrameStartTime_ - temp;
+ evt.timeSinceLastEvent = lastFrameStartTime_ - lastFrameEndTime_;
+
+ // Ogre requires the time too
ogreRoot_->_fireFrameStarted(evt);
// Pump messages in all registered RenderWindows
// This calls the WindowEventListener objects.
Ogre::WindowEventUtilities::messagePump();
- // make sure the window stays active even when not focused
+ // Make sure the window stays active even when not focused
// (probably only necessary on windows)
this->renderWindow_->setActive(true);
- // Time before rendering
- uint64_t timeBeforeTick = time.getRealMicroseconds();
-
// Render frame
ogreRoot_->_updateAllRenderTargets();
@@ -395,8 +398,14 @@
// Subtract the time used for rendering from the tick time counter
Game::getInstance().subtractTickTime((int32_t)(timeAfterTick - timeBeforeTick));
- // again, just to be sure OGRE works fine
- ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+ // Translate to Ogre float times after the update
+ temp = lastFrameEndTime_;
+ lastFrameEndTime_ = (float)(timeAfterTick / 1000000);
+ evt.timeSinceLastFrame = lastFrameEndTime_ - temp;
+ evt.timeSinceLastEvent = lastFrameEndTime_ - lastFrameStartTime_;
+
+ // Ogre also needs the time after the frame finished
+ ogreRoot_->_fireFrameEnded(evt);
}
void GraphicsManager::setCamera(Ogre::Camera* camera)
Modified: code/branches/usability/src/libraries/core/GraphicsManager.h
===================================================================
--- code/branches/usability/src/libraries/core/GraphicsManager.h 2011-02-27 18:01:07 UTC (rev 7994)
+++ code/branches/usability/src/libraries/core/GraphicsManager.h 2011-02-28 02:47:08 UTC (rev 7995)
@@ -108,6 +108,8 @@
scoped_ptr<Ogre::Root> ogreRoot_; //!< Ogre's root
Ogre::RenderWindow* renderWindow_; //!< the one and only render window
Ogre::Viewport* viewport_; //!< default full size viewport
+ float lastFrameStartTime_; //!< Time stamp of the beginning of the last frame
+ float lastFrameEndTime_; //!< Time stamp of the end of the last frame
// XML files for the resources and the debug overlay
shared_ptr<XMLFile> resources_; //!< XML with resource locations
More information about the Orxonox-commit
mailing list