From 77f733362c1c393f55e1c3faafed3051114ea17b Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 7 May 2015 21:57:02 +0200 Subject: [PATCH] Add stats graphs for Script, Mechanics and Physics timings --- apps/openmw/engine.cpp | 40 +++++++++++++++++++++-- apps/openmw/engine.hpp | 2 ++ apps/openmw/mwrender/objects.cpp | 5 --- apps/openmw/mwrender/objects.hpp | 3 -- apps/openmw/mwrender/renderingmanager.cpp | 1 - 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index d91d32a28..368af216f 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -76,6 +76,7 @@ void OMW::Engine::frame(float frametime) { try { + mStartTick = mViewer->getStartTick(); mEnvironment.setFrameDuration (frametime); // update input @@ -99,6 +100,7 @@ void OMW::Engine::frame(float frametime) // update game state MWBase::Environment::get().getStateManager()->update (frametime); + osg::Timer_t beforeScriptTick = osg::Timer::instance()->tick(); if (MWBase::Environment::get().getStateManager()->getState()== MWBase::StateManager::State_Running) { @@ -120,15 +122,17 @@ void OMW::Engine::frame(float frametime) MWBase::Environment::get().getWorld()->advanceTime( frametime*MWBase::Environment::get().getWorld()->getTimeScaleFactor()/3600); } - + osg::Timer_t afterScriptTick = osg::Timer::instance()->tick(); // update actors + osg::Timer_t beforeMechanicsTick = osg::Timer::instance()->tick(); if (MWBase::Environment::get().getStateManager()->getState()!= MWBase::StateManager::State_NoGame) { MWBase::Environment::get().getMechanicsManager()->update(frametime, guiActive); } + osg::Timer_t afterMechanicsTick = osg::Timer::instance()->tick(); if (MWBase::Environment::get().getStateManager()->getState()== MWBase::StateManager::State_Running) @@ -139,11 +143,13 @@ void OMW::Engine::frame(float frametime) } // update world + osg::Timer_t beforePhysicsTick = osg::Timer::instance()->tick();; if (MWBase::Environment::get().getStateManager()->getState()!= MWBase::StateManager::State_NoGame) { MWBase::Environment::get().getWorld()->update(frametime, guiActive); } + osg::Timer_t afterPhysicsTick = osg::Timer::instance()->tick(); // update GUI MWBase::Environment::get().getWindowManager()->onFrame(frametime); @@ -155,6 +161,21 @@ void OMW::Engine::frame(float frametime) #endif MWBase::Environment::get().getWindowManager()->update(); } + + int frameNumber = mViewer->getFrameStamp()->getFrameNumber(); + osg::Stats* stats = mViewer->getViewerStats(); + stats->setAttribute(frameNumber, "script_time_begin", osg::Timer::instance()->delta_s(mStartTick, beforeScriptTick)); + stats->setAttribute(frameNumber, "script_time_taken", osg::Timer::instance()->delta_s(beforeScriptTick, afterScriptTick)); + stats->setAttribute(frameNumber, "script_time_end", osg::Timer::instance()->delta_s(mStartTick, afterScriptTick)); + + stats->setAttribute(frameNumber, "mechanics_time_begin", osg::Timer::instance()->delta_s(mStartTick, beforeMechanicsTick)); + stats->setAttribute(frameNumber, "mechanics_time_taken", osg::Timer::instance()->delta_s(beforeMechanicsTick, afterMechanicsTick)); + stats->setAttribute(frameNumber, "mechanics_time_end", osg::Timer::instance()->delta_s(mStartTick, afterMechanicsTick)); + + stats->setAttribute(frameNumber, "physics_time_begin", osg::Timer::instance()->delta_s(mStartTick, beforePhysicsTick)); + stats->setAttribute(frameNumber, "physics_time_taken", osg::Timer::instance()->delta_s(beforePhysicsTick, afterPhysicsTick)); + stats->setAttribute(frameNumber, "physics_time_end", osg::Timer::instance()->delta_s(mStartTick, afterPhysicsTick)); + } catch (const std::exception& e) { @@ -194,6 +215,8 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager) throw std::runtime_error("Could not initialize SDL! " + std::string(SDL_GetError())); } } + + mStartTick = osg::Timer::instance()->tick(); } OMW::Engine::~Engine() @@ -430,7 +453,7 @@ void OMW::Engine::go() { MWBase::Environment::get().getStateManager()->loadGame(mSaveGameFile); } - else if (0)// !mSkipMenu) + else if (!mSkipMenu) { // start in main menu MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu); @@ -452,7 +475,18 @@ void OMW::Engine::go() // Start the main rendering loop mViewer->setCameraManipulator(new osgGA::TrackballManipulator); - mViewer->addEventHandler(new osgViewer::StatsHandler); + + osg::ref_ptr statshandler = new osgViewer::StatsHandler; + + statshandler->addUserStatsLine("Script", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), + "script_time_taken", 1000.0, true, false, "script_time_begin", "script_time_end", 10000); + statshandler->addUserStatsLine("Mechanics", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), + "mechanics_time_taken", 1000.0, true, false, "mechanics_time_begin", "mechanics_time_end", 10000); + statshandler->addUserStatsLine("Physics", osg::Vec4f(1.f, 1.f, 1.f, 1.f), osg::Vec4f(1.f, 1.f, 1.f, 1.f), + "physics_time_taken", 1000.0, true, false, "physics_time_begin", "physics_time_end", 10000); + + mViewer->addEventHandler(statshandler); + osg::Timer frameTimer; while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index b47a7bb76..e94b5e3ff 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -96,6 +96,8 @@ namespace OMW bool mScriptBlacklistUse; bool mNewGame; + osg::Timer_t mStartTick; + // not implemented Engine (const Engine&); Engine& operator= (const Engine&); diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 69311c111..17fbbe549 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -198,11 +198,6 @@ void Objects::removeCell(const MWWorld::CellStore* store) } } -void Objects::update(float dt) -{ - -} - void Objects::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur) { /* diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index fd6ceab54..e920869b9 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -63,9 +63,6 @@ public: Animation* getAnimation(const MWWorld::Ptr &ptr); - void update (float dt); - ///< per-frame update - //Ogre::AxisAlignedBox getDimensions(MWWorld::CellStore*); ///< get a bounding box that encloses all objects in the specified cell diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 853ba3834..c9bf22009 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -248,7 +248,6 @@ namespace MWRender void RenderingManager::update(float dt, bool paused) { - mObjects->update(dt); mEffectManager->update(dt); mSky->update(dt); }