Skip to content

Commit

Permalink
Add option to show FPS counter and performance statistics (#170)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
keton committed Mar 3, 2024
1 parent 1aa28fe commit bfd4cec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/mods/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3204,4 +3208,18 @@ void VR::process_snapturn() {
}

m_snapturn_on_frame = false;
}
}

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();
}
}
10 changes: 10 additions & 0 deletions src/mods/VR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
};

Expand Down

0 comments on commit bfd4cec

Please sign in to comment.