diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 5e83a20056..474d8d78c3 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -73,6 +73,36 @@ void OMW::Engine::executeLocalScripts() localScripts.setIgnore (MWWorld::Ptr()); } +void OMW::Engine::updateFocusReport (float duration) +{ + if ((mFocusTDiff += duration)>0.25) + { + mFocusTDiff = 0; + + std::string name; + + std::string handle = mEnvironment.mWorld->getFacedHandle(); + + if (!handle.empty()) + { + MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); + + if (!ptr.isEmpty()) + name = MWWorld::Class::get (ptr).getName (ptr); + } + + if (name!=mFocusName) + { + mFocusName = name; + + if (mFocusName.empty()) + std::cout << "Unfocus" << std::endl; + else + std::cout << "Focus: " << name << std::endl; + } + } +} + bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) { try @@ -176,24 +206,9 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game) mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration); - if (focusFrameCounter++ == focusUpdateFrame) - { - std::string handle = mEnvironment.mWorld->getFacedHandle(); - - if (!handle.empty()) - { - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); - - if (!ptr.isEmpty()) - { - std::string name = MWWorld::Class::get (ptr).getName (ptr); - if (!name.empty()) - std::cout << "Object: " << name << std::endl; - } - } - - focusFrameCounter = 0; - } + // report focus object (for debugging) + if (mReportFocus) + updateFocusReport (mEnvironment.mFrameDuration); } catch (const std::exception& e) { @@ -211,6 +226,8 @@ OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager) , mNewGame (false) , mUseSound (true) , mCompileAll (false) + , mReportFocus (false) + , mFocusTDiff (0) , mScriptManager (0) , mScriptContext (0) , mGuiManager (0) @@ -320,6 +337,11 @@ void OMW::Engine::setNewGame(bool newGame) mNewGame = newGame; } +void OMW::Engine::setReportFocus (bool report) +{ + mReportFocus = report; +} + // Initialise and enter main loop. void OMW::Engine::go() @@ -416,8 +438,6 @@ void OMW::Engine::go() *mEnvironment.mWindowManager, mDebug, *this); mEnvironment.mInputManager = &input; - focusFrameCounter = 0; - std::cout << "\nPress Q/ESC or close window to exit.\n"; mOgre.getRoot()->addFrameListener (this); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 96b7cf52e1..8bf2dbbcf8 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -68,6 +68,10 @@ namespace OMW bool mNewGame; bool mUseSound; bool mCompileAll; + bool mReportFocus; + float mFocusTDiff; + std::string mFocusName; + int total; MWWorld::Environment mEnvironment; @@ -78,9 +82,6 @@ namespace OMW ESM::Region test; boost::timer timer; - int focusFrameCounter; - static const int focusUpdateFrame = 10; - Files::Collections mFileCollections; bool mFSStrict; @@ -98,9 +99,9 @@ namespace OMW void executeLocalScripts(); - virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); + void updateFocusReport (float duration); - /// Process pending commands + virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); public: Engine(Cfg::ConfigurationManager& configurationManager); @@ -142,6 +143,9 @@ namespace OMW /// Start as a new game. void setNewGame(bool newGame); + /// Write name of focussed object to cout + void setReportFocus (bool report); + /// Initialise and enter main loop. void go(); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index aa8b13b80d..933d1c48aa 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -102,6 +102,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" "\n\twin1252 - Western European (Latin) alphabet, used by default") + + ("report-focus", boost::program_options::value()->implicit_value(true) + ->default_value(false), "write name of focussed object to cout") ; bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) @@ -202,6 +205,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio engine.setSoundUsage(!variables["nosound"].as()); engine.setScriptsVerbosity(variables["script-verbose"].as()); engine.setCompileAll(variables["script-all"].as()); + engine.setReportFocus(variables["report-focus"].as()); return true; }