From bfd4cec78cbcf6f82906955a9fe19803537265de Mon Sep 17 00:00:00 2001 From: keton Date: Sun, 3 Mar 2024 23:34:55 +0100 Subject: [PATCH] Add option to show FPS counter and performance statistics (#170) This commit adds to debug menu toggle to show Unreal Engine FPS counter and engine statistics. This provides non obnoxious way to have them on screen at all times. Stats appear in top left corner just outside of your normal field of vision. This allows you to turn them on and keep them on compared to Virtual Desktop overlay. Compared to OpenXR toolkit this way is much more compatible with UEVR. Current builds of OpenXR increase number of crashes. --- src/mods/VR.cpp | 20 +++++++++++++++++++- src/mods/VR.hpp | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/mods/VR.cpp b/src/mods/VR.cpp index 24f1e696..12ddc0b1 100644 --- a/src/mods/VR.cpp +++ b/src/mods/VR.cpp @@ -1378,6 +1378,8 @@ void VR::on_pre_engine_tick(sdk::UGameEngine* engine, float delta) { m_render_target_pool_hook->on_pre_engine_tick(engine, delta); + update_statistics_overlay(engine); + // Dont update action states on AFR frames // TODO: fix this for actual AFR, but we dont really care about pure AFR since synced beats it most of the time if (m_fake_stereo_hook != nullptr && !m_fake_stereo_hook->is_ignoring_next_viewport_draw()) { @@ -2559,6 +2561,8 @@ void VR::on_draw_sidebar_entry(std::string_view name) { ImGui::Checkbox("Wait for Present", &m_wait_for_present); m_controllers_allowed->draw("Controllers allowed"); ImGui::Checkbox("Controller test mode", &m_controller_test_mode); + m_show_fps->draw("Show FPS"); + m_show_statistics->draw("Show Engine Statistics"); const double min_ = 0.0; const double max_ = 25.0; @@ -3204,4 +3208,18 @@ void VR::process_snapturn() { } m_snapturn_on_frame = false; -} \ No newline at end of file +} + +void VR::update_statistics_overlay(sdk::UGameEngine* engine) { + if(!engine) return; + + if(m_show_fps_state != m_show_fps->value()) { + engine->exec(L"stat fps"); + m_show_fps_state = m_show_fps->value(); + } + + if(m_show_statistics_state != m_show_statistics->value()) { + engine->exec(L"stat unit"); + m_show_statistics_state = m_show_statistics->value(); + } +} diff --git a/src/mods/VR.hpp b/src/mods/VR.hpp index d15c1494..e2101115 100644 --- a/src/mods/VR.hpp +++ b/src/mods/VR.hpp @@ -926,6 +926,14 @@ class VR : public Mod { bool m_wait_for_present{true}; const ModToggle::Ptr m_controllers_allowed{ ModToggle::create(generate_name("ControllersAllowed"), true) }; bool m_controller_test_mode{false}; + + const ModToggle::Ptr m_show_fps{ ModToggle::create(generate_name("ShowFPSOverlay"), false) }; + bool m_show_fps_state{false}; + + const ModToggle::Ptr m_show_statistics{ ModToggle::create(generate_name("ShowStatsOverlay"), false) }; + bool m_show_statistics_state{false}; + + void update_statistics_overlay(sdk::UGameEngine* engine); ValueList m_options{ *m_rendering_method, @@ -983,6 +991,8 @@ class VR : public Mod { *m_keybind_disable_vr, *m_keybind_toggle_gui, *m_requested_runtime_name, + *m_show_fps, + *m_show_statistics, *m_controllers_allowed, };