Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to show FPS counter and performance statistics #170

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading