From 5132531f73d6133606ab2a8058d392b4d3e57cb9 Mon Sep 17 00:00:00 2001 From: sergoz Date: Fri, 18 Feb 2011 17:46:24 +0300 Subject: [PATCH] added fps counter --- apps/openmw/engine.cpp | 10 ++++++++-- apps/openmw/engine.hpp | 4 ++++ apps/openmw/main.cpp | 4 ++++ apps/openmw/mwgui/layouts.cpp | 1 - apps/openmw/mwgui/layouts.hpp | 8 ++++++++ apps/openmw/mwgui/window_manager.cpp | 7 ++++++- apps/openmw/mwgui/window_manager.hpp | 7 ++++++- .../mygui_3.0.1/openmw_resources/openmw_hud_layout.xml | 6 ++++++ 8 files changed, 42 insertions(+), 5 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 3eaff2fe1..9590968b5 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -69,6 +69,11 @@ void OMW::Engine::executeLocalScripts() bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) { + if(mShowFPS) + { + mEnvironment.mWindowManager->wmSetFPS(mOgre.getFPS()); + } + if(mUseSound && !(mEnvironment.mSoundManager->isMusicPlaying())) { // Play some good 'ol tunes @@ -190,7 +195,8 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) } OMW::Engine::Engine() - : mDebug (false) + : mShowFPS (false) + , mDebug (false) , mVerboseScripts (false) , mNewGame (false) , mUseSound (true) @@ -348,7 +354,7 @@ void OMW::Engine::go() MWScript::registerExtensions (mExtensions); mEnvironment.mWindowManager = new MWGui::WindowManager(mGuiManager->getGui(), mEnvironment, - mExtensions, mNewGame); + mExtensions, mShowFPS, mNewGame); // Create sound system mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre.getRoot(), diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 5b636398c..3e0bd9450 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -61,6 +61,7 @@ namespace OMW OEngine::Render::OgreRenderer mOgre; std::string mCellName; std::string mMaster; + bool mShowFPS; bool mDebug; bool mVerboseScripts; bool mNewGame; @@ -119,6 +120,9 @@ namespace OMW /// - Currently OpenMW only supports one master at the same time. void addMaster (const std::string& master); + /// Enable fps counter + void showFPS() { mShowFPS = true; } + /// Enable debug mode: /// - non-exclusive input void enableDebugMode(); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 990e6b51c..f47273ee1 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -49,6 +49,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) "set initial cell") ("master", bpo::value()->default_value ("Morrowind"), "master file") + ( "showfps", "show fps counter") ( "debug", "debug mode" ) ( "nosound", "disable all sound" ) ( "script-verbose", "verbose script output" ) @@ -87,6 +88,9 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine) engine.setCell (variables["start"].as()); engine.addMaster (variables["master"].as()); + if (variables.count ("showfps")) + engine.showFPS(); + if (variables.count ("debug")) engine.enableDebugMode(); diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp index 06727b55c..f273f22c0 100644 --- a/apps/openmw/mwgui/layouts.cpp +++ b/apps/openmw/mwgui/layouts.cpp @@ -7,7 +7,6 @@ #include #include #include -#include using namespace MWGui; diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp index 097790163..c330afadb 100644 --- a/apps/openmw/mwgui/layouts.hpp +++ b/apps/openmw/mwgui/layouts.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -58,6 +59,7 @@ namespace MWGui getWidget(compass, "Compass"); getWidget(crosshair, "Crosshair"); + getWidget(fpscounter, "FPSCounter"); compass->setImageTexture("textures\\compass.dds"); crosshair->setImageTexture("textures\\target.dds"); @@ -71,6 +73,11 @@ namespace MWGui setEffect("icons\\s\\tx_s_chameleon.dds"); } + void setFPS(float fps) + { + fpscounter->setCaption(boost::lexical_cast((int)fps)); + } + void setStats(int h, int hmax, int m, int mmax, int s, int smax) { health->setProgressRange(hmax); @@ -146,6 +153,7 @@ namespace MWGui MyGUI::StaticImagePtr compass; MyGUI::StaticImagePtr crosshair; + MyGUI::StaticTextPtr fpscounter; }; class MapWindow : public OEngine::GUI::Layout diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index bbc266cb5..fa5200bf5 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -20,7 +20,7 @@ using namespace MWGui; WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, - const Compiler::Extensions& extensions, bool newGame) + const Compiler::Extensions& extensions, bool fpsSwitch, bool newGame) : environment(environment) , nameDialog(nullptr) , raceDialog(nullptr) @@ -44,6 +44,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment , shown(GW_ALL) , allowed(newGame ? GW_None : GW_ALL) { + showFPSCounter = fpsSwitch; //Register own widgets with MyGUI MyGUI::FactoryManager::getInstance().registerFactory("Widget"); @@ -127,6 +128,10 @@ void WindowManager::update() environment.mInputManager->setGuiMode(nextMode); nextMode = GM_Game; } + if (showFPSCounter) + { + hud->setFPS(mFPS); + } } void WindowManager::setNextMode(GuiMode newMode) diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index e39d9e6a6..2b030d08b 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -153,10 +153,13 @@ namespace MWGui void setGuiMode(GuiMode newMode); + bool showFPSCounter; + float mFPS; + public: /// The constructor needs the main Gui object WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, - const Compiler::Extensions& extensions, bool newGame); + const Compiler::Extensions& extensions, bool fpsSwitch, bool newGame); virtual ~WindowManager(); /** @@ -197,6 +200,8 @@ namespace MWGui MyGUI::Gui* getGui() const { return gui; } + void wmSetFPS(float fps) { mFPS = fps; } + void setValue (const std::string& id, const MWMechanics::Stat& value); ///< Set value for the given ID. diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_hud_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_hud_layout.xml index 22417b401..d2fb4f420 100644 --- a/extern/mygui_3.0.1/openmw_resources/openmw_hud_layout.xml +++ b/extern/mygui_3.0.1/openmw_resources/openmw_hud_layout.xml @@ -48,5 +48,11 @@ + + + + +