1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

Issue #19: Focus Reporting Improvements

- moved focus reporting code out of the framelistener
- made focus reporting optional (new --report-focus switch)
- report based on tiem passed instead of number of frames passed
- only report if focus has changed
This commit is contained in:
Marc Zinnschlag 2011-10-08 10:31:23 +02:00
parent fbcb5fe681
commit 8bf4abf53b
3 changed files with 53 additions and 25 deletions

View file

@ -73,6 +73,36 @@ void OMW::Engine::executeLocalScripts()
localScripts.setIgnore (MWWorld::Ptr()); 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) bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
{ {
try try
@ -176,24 +206,9 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game) if (mEnvironment.mWindowManager->getMode()==MWGui::GM_Game)
mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration); mEnvironment.mWorld->doPhysics (movement, mEnvironment.mFrameDuration);
if (focusFrameCounter++ == focusUpdateFrame) // report focus object (for debugging)
{ if (mReportFocus)
std::string handle = mEnvironment.mWorld->getFacedHandle(); updateFocusReport (mEnvironment.mFrameDuration);
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;
}
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
@ -211,6 +226,8 @@ OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager)
, mNewGame (false) , mNewGame (false)
, mUseSound (true) , mUseSound (true)
, mCompileAll (false) , mCompileAll (false)
, mReportFocus (false)
, mFocusTDiff (0)
, mScriptManager (0) , mScriptManager (0)
, mScriptContext (0) , mScriptContext (0)
, mGuiManager (0) , mGuiManager (0)
@ -320,6 +337,11 @@ void OMW::Engine::setNewGame(bool newGame)
mNewGame = newGame; mNewGame = newGame;
} }
void OMW::Engine::setReportFocus (bool report)
{
mReportFocus = report;
}
// Initialise and enter main loop. // Initialise and enter main loop.
void OMW::Engine::go() void OMW::Engine::go()
@ -416,8 +438,6 @@ void OMW::Engine::go()
*mEnvironment.mWindowManager, mDebug, *this); *mEnvironment.mWindowManager, mDebug, *this);
mEnvironment.mInputManager = &input; mEnvironment.mInputManager = &input;
focusFrameCounter = 0;
std::cout << "\nPress Q/ESC or close window to exit.\n"; std::cout << "\nPress Q/ESC or close window to exit.\n";
mOgre.getRoot()->addFrameListener (this); mOgre.getRoot()->addFrameListener (this);

View file

@ -68,6 +68,10 @@ namespace OMW
bool mNewGame; bool mNewGame;
bool mUseSound; bool mUseSound;
bool mCompileAll; bool mCompileAll;
bool mReportFocus;
float mFocusTDiff;
std::string mFocusName;
int total; int total;
MWWorld::Environment mEnvironment; MWWorld::Environment mEnvironment;
@ -78,9 +82,6 @@ namespace OMW
ESM::Region test; ESM::Region test;
boost::timer timer; boost::timer timer;
int focusFrameCounter;
static const int focusUpdateFrame = 10;
Files::Collections mFileCollections; Files::Collections mFileCollections;
bool mFSStrict; bool mFSStrict;
@ -98,9 +99,9 @@ namespace OMW
void executeLocalScripts(); void executeLocalScripts();
virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); void updateFocusReport (float duration);
/// Process pending commands virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt);
public: public:
Engine(Cfg::ConfigurationManager& configurationManager); Engine(Cfg::ConfigurationManager& configurationManager);
@ -142,6 +143,9 @@ namespace OMW
/// Start as a new game. /// Start as a new game.
void setNewGame(bool newGame); void setNewGame(bool newGame);
/// Write name of focussed object to cout
void setReportFocus (bool report);
/// Initialise and enter main loop. /// Initialise and enter main loop.
void go(); void go();

View file

@ -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\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\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n"
"\n\twin1252 - Western European (Latin) alphabet, used by default") "\n\twin1252 - Western European (Latin) alphabet, used by default")
("report-focus", boost::program_options::value<bool>()->implicit_value(true)
->default_value(false), "write name of focussed object to cout")
; ;
bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) 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<bool>()); engine.setSoundUsage(!variables["nosound"].as<bool>());
engine.setScriptsVerbosity(variables["script-verbose"].as<bool>()); engine.setScriptsVerbosity(variables["script-verbose"].as<bool>());
engine.setCompileAll(variables["script-all"].as<bool>()); engine.setCompileAll(variables["script-all"].as<bool>());
engine.setReportFocus(variables["report-focus"].as<bool>());
return true; return true;
} }