From ff0b4e0583d7f0d1dd3b64fcfc273b8ea56b24d0 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 28 Sep 2014 17:57:14 +0200 Subject: [PATCH] Add debug window (F10), displays Bullet's profiler output --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwbase/windowmanager.hpp | 2 + apps/openmw/mwgui/debugwindow.cpp | 116 +++++++++++++++++++++++ apps/openmw/mwgui/debugwindow.hpp | 24 +++++ apps/openmw/mwgui/windowmanagerimp.cpp | 11 +++ apps/openmw/mwgui/windowmanagerimp.hpp | 4 + apps/openmw/mwinput/inputmanagerimp.cpp | 4 + apps/openmw/mwinput/inputmanagerimp.hpp | 2 + files/mygui/CMakeLists.txt | 2 + files/mygui/core.xml | 1 + files/mygui/openmw_debug_window.layout | 16 ++++ files/mygui/openmw_debug_window.skin.xml | 17 ++++ files/mygui/openmw_layers.xml | 1 + 13 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 apps/openmw/mwgui/debugwindow.cpp create mode 100644 apps/openmw/mwgui/debugwindow.hpp create mode 100644 files/mygui/openmw_debug_window.layout create mode 100644 files/mygui/openmw_debug_window.skin.xml diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 2417091f8..e37cd1391 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -40,7 +40,7 @@ add_openmw_dir (mwgui merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview tradeitemmodel companionitemmodel pickpocketitemmodel controllers savegamedialog - recharge mode videowidget backgroundimage itemwidget screenfader + recharge mode videowidget backgroundimage itemwidget screenfader debugwindow ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index e8286bdd1..bce3f516e 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -337,6 +337,8 @@ namespace MWBase virtual void fadeScreenTo(const int percent, const float time) = 0; /// Darken the screen by \a factor (1.0 = no darkening). Works independently from screen fading. virtual void setScreenFactor (float factor) = 0; + + virtual void toggleDebugWindow() = 0; }; } diff --git a/apps/openmw/mwgui/debugwindow.cpp b/apps/openmw/mwgui/debugwindow.cpp new file mode 100644 index 000000000..fab386bda --- /dev/null +++ b/apps/openmw/mwgui/debugwindow.cpp @@ -0,0 +1,116 @@ +#include "debugwindow.hpp" + + +#include + +namespace +{ + void bulletDumpRecursive(CProfileIterator* pit, int spacing, std::stringstream& os) + { + pit->First(); + if (pit->Is_Done()) + return; + + float accumulated_time=0,parent_time = pit->Is_Root() ? CProfileManager::Get_Time_Since_Reset() : pit->Get_Current_Parent_Total_Time(); + int i,j; + int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset(); + for (i=0;iGet_Current_Parent_Name())+" (total running time: "+MyGUI::utility::toString(parent_time,3)+" ms) ---\n"; + os << s; + //float totalTime = 0.f; + + int numChildren = 0; + + for (i = 0; !pit->Is_Done(); i++,pit->Next()) + { + numChildren++; + float current_total_time = pit->Get_Current_Total_Time(); + accumulated_time += current_total_time; + float fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f; + + for (j=0;jGet_Current_Name()+" ("+MyGUI::utility::toString(fraction,2)+" %) :: "+MyGUI::utility::toString(ms,3)+" ms / frame ("+MyGUI::utility::toString(pit->Get_Current_Total_Calls())+" calls)\n"; + os << s; + //totalTime += current_total_time; + //recurse into children + } + + if (parent_time < accumulated_time) + { + os << "what's wrong\n"; + } + for (i=0;i SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f; + s = "Unaccounted: ("+MyGUI::utility::toString(unaccounted,3)+" %) :: "+MyGUI::utility::toString(parent_time - accumulated_time,3)+" ms\n"; + os << s; + + for (i=0;iEnter_Child(i); + bulletDumpRecursive(pit, spacing+3, os); + pit->Enter_Parent(); + } + } + + void bulletDumpAll(std::stringstream& os) + { + CProfileIterator* profileIterator = 0; + profileIterator = CProfileManager::Get_Iterator(); + + bulletDumpRecursive(profileIterator, 0, os); + + CProfileManager::Release_Iterator(profileIterator); + } +} + + +namespace MWGui +{ + + DebugWindow::DebugWindow() + : WindowBase("openmw_debug_window.layout") + { + getWidget(mTabControl, "TabControl"); + + // Ideas for other tabs: + // - Texture / compositor texture viewer + // - Log viewer + // - Material editor + // - Shader editor + + MyGUI::TabItem* item = mTabControl->addItem("Physics Profiler"); + mBulletProfilerEdit = item->createWidgetReal + ("LogEdit", MyGUI::FloatCoord(0,0,1,1), MyGUI::Align::Stretch); + + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); + mMainWidget->setSize(viewSize); + } + + void DebugWindow::onFrame(float dt) + { + if (!isVisible()) + return; + + static float timer = 0; + timer -= dt; + + if (timer > 0) + return; + timer = 1; + + std::stringstream stream; + bulletDumpAll(stream); + + if (mBulletProfilerEdit->isTextSelection()) // pause updating while user is trying to copy text + return; + + size_t previousPos = mBulletProfilerEdit->getVScrollPosition(); + mBulletProfilerEdit->setCaption(stream.str()); + mBulletProfilerEdit->setVScrollPosition(std::min(previousPos, mBulletProfilerEdit->getVScrollRange()-1)); + } + +} diff --git a/apps/openmw/mwgui/debugwindow.hpp b/apps/openmw/mwgui/debugwindow.hpp new file mode 100644 index 000000000..af5b914ea --- /dev/null +++ b/apps/openmw/mwgui/debugwindow.hpp @@ -0,0 +1,24 @@ +#ifndef OPENMW_MWGUI_DEBUGWINDOW_H +#define OPENMW_MWGUI_DEBUGWINDOW_H + +#include "windowbase.hpp" + +namespace MWGui +{ + + class DebugWindow : public WindowBase + { + public: + DebugWindow(); + + void onFrame(float dt); + + private: + MyGUI::TabControl* mTabControl; + + MyGUI::EditBox* mBulletProfilerEdit; + }; + +} + +#endif diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index fabdf4dae..70f4b5a2f 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -72,6 +72,7 @@ #include "backgroundimage.hpp" #include "itemwidget.hpp" #include "screenfader.hpp" +#include "debugwindow.hpp" namespace MWGui { @@ -120,6 +121,7 @@ namespace MWGui , mVideoBackground(NULL) , mVideoWidget(NULL) , mScreenFader(NULL) + , mDebugWindow(NULL) , mTranslationDataStorage (translationDataStorage) , mCharGen(NULL) , mInputBlocker(NULL) @@ -266,6 +268,7 @@ namespace MWGui mCompanionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager); trackWindow(mCompanionWindow, "companion"); mScreenFader = new ScreenFader(); + mDebugWindow = new DebugWindow(); mInputBlocker = MyGUI::Gui::getInstance().createWidget("",0,0,w,h,MyGUI::Align::Stretch,"Overlay"); @@ -357,6 +360,7 @@ namespace MWGui delete mRecharge; delete mCompanionWindow; delete mScreenFader; + delete mDebugWindow; cleanupGarbage(); @@ -859,6 +863,8 @@ namespace MWGui mCompanionWindow->onFrame(); mScreenFader->update(frameDuration); + + mDebugWindow->onFrame(frameDuration); } void WindowManager::changeCell(MWWorld::CellStore* cell) @@ -1749,4 +1755,9 @@ namespace MWGui SDL_free(text); } + void WindowManager::toggleDebugWindow() + { + mDebugWindow->setVisible(!mDebugWindow->isVisible()); + } + } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index e7853b84f..29d40c2e7 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -89,6 +89,7 @@ namespace MWGui class VideoWidget; class WindowModal; class ScreenFader; + class DebugWindow; class WindowManager : public MWBase::WindowManager { @@ -333,6 +334,8 @@ namespace MWGui /// Darken the screen by \a factor (1.0 = no darkening). Works independently from screen fading. virtual void setScreenFactor (float factor); + virtual void toggleDebugWindow(); + private: bool mConsoleOnlyScripts; @@ -386,6 +389,7 @@ namespace MWGui MyGUI::ImageBox* mVideoBackground; VideoWidget* mVideoWidget; ScreenFader* mScreenFader; + DebugWindow* mDebugWindow; Translation::Storage& mTranslationDataStorage; Cursor* mSoftwareCursor; diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 86b01cdc4..3cd30819c 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -279,6 +279,9 @@ namespace MWInput case A_ToggleHUD: MWBase::Environment::get().getWindowManager()->toggleGui(); break; + case A_ToggleDebug: + MWBase::Environment::get().getWindowManager()->toggleDebugWindow(); + break; case A_QuickSave: quickSave(); break; @@ -902,6 +905,7 @@ namespace MWInput defaultKeyBindings[A_QuickKey10] = SDL_SCANCODE_0; defaultKeyBindings[A_Screenshot] = SDL_SCANCODE_F12; defaultKeyBindings[A_ToggleHUD] = SDL_SCANCODE_F11; + defaultKeyBindings[A_ToggleDebug] = SDL_SCANCODE_F10; defaultKeyBindings[A_AlwaysRun] = SDL_SCANCODE_CAPSLOCK; defaultKeyBindings[A_QuickSave] = SDL_SCANCODE_F5; defaultKeyBindings[A_QuickLoad] = SDL_SCANCODE_F9; diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index a94b61c8b..346e02ff9 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -259,6 +259,8 @@ namespace MWInput A_ToggleHUD, + A_ToggleDebug, + A_Last // Marker for the last item }; }; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 87e750cc9..651adf403 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -83,6 +83,8 @@ set(MYGUI_FILES openmw_recharge_dialog.layout openmw_screen_fader.layout openmw_edit_note.layout + openmw_debug_window.layout + openmw_debug_window.skin.xml DejaVuLGCSansMono.ttf ../launcher/images/openmw.png OpenMWResourcePlugin.xml diff --git a/files/mygui/core.xml b/files/mygui/core.xml index ea1627875..133109375 100644 --- a/files/mygui/core.xml +++ b/files/mygui/core.xml @@ -22,6 +22,7 @@ + diff --git a/files/mygui/openmw_debug_window.layout b/files/mygui/openmw_debug_window.layout new file mode 100644 index 000000000..9af646c6e --- /dev/null +++ b/files/mygui/openmw_debug_window.layout @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/files/mygui/openmw_debug_window.skin.xml b/files/mygui/openmw_debug_window.skin.xml new file mode 100644 index 000000000..587101b7f --- /dev/null +++ b/files/mygui/openmw_debug_window.skin.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/files/mygui/openmw_layers.xml b/files/mygui/openmw_layers.xml index 1df4841af..38a98d133 100644 --- a/files/mygui/openmw_layers.xml +++ b/files/mygui/openmw_layers.xml @@ -6,6 +6,7 @@ +