From b13f6f4b7064421d4a1c69aa91ccf47fd980989d Mon Sep 17 00:00:00 2001 From: David Chavez Date: Wed, 1 Mar 2023 16:12:55 +0100 Subject: [PATCH] [Interpolation] Allow Matching & Limit Max FPS (#2466) --- soh/soh/GameMenuBar.cpp | 40 +++++++++++++++++----------------------- soh/soh/OTRGlobals.cpp | 10 +++++++++- soh/soh/OTRGlobals.h | 1 + 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/soh/soh/GameMenuBar.cpp b/soh/soh/GameMenuBar.cpp index a385d486d..d10071980 100644 --- a/soh/soh/GameMenuBar.cpp +++ b/soh/soh/GameMenuBar.cpp @@ -890,15 +890,10 @@ namespace GameMenuBar { const char* fps_cvar = "gInterpolationFPS"; { - #if defined(__SWITCH__) || defined(__WIIU__) int minFps = 20; - int maxFps = 60; - #else - int minFps = 20; - int maxFps = 360; - #endif + int maxFps = Ship::Window::GetInstance()->GetCurrentRefreshRate(); - int val = CVarGetInteger(fps_cvar, minFps); + int val = OTRGlobals::Instance->GetInterpolationFPS(); val = fmax(fmin(val, maxFps), 20); #ifdef __WIIU__ @@ -916,6 +911,11 @@ namespace GameMenuBar { { ImGui::Text("Frame interpolation: %d FPS", fps); } + + if (CVarGetInteger("gMatchRefreshRate", 0)) { + ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); + } std::string MinusBTNFPSI = " - ##FPSInterpolation"; std::string PlusBTNFPSI = " + ##FPSInterpolation"; @@ -976,24 +976,18 @@ namespace GameMenuBar { CVarSetInteger(fps_cvar, val); SohImGui::RequestCvarSaveOnNextTick(); } - } - - if (SohImGui::WindowBackend() == SohImGui::Backend::DX11) - { - UIWidgets::Spacer(0); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f, 4.0f)); - if (ImGui::Button("Match Refresh Rate")) - { - int hz = Ship::Window::GetInstance()->GetCurrentRefreshRate(); - if (hz >= 20 && hz <= 360) - { - CVarSetInteger(fps_cvar, hz); - SohImGui::RequestCvarSaveOnNextTick(); - } + + if (CVarGetInteger("gMatchRefreshRate", 0)) { + ImGui::PopItemFlag(); + ImGui::PopStyleVar(1); } - ImGui::PopStyleVar(1); - UIWidgets::Spacer(0); } + + UIWidgets::Spacer(0); + UIWidgets::EnhancementCheckbox("Match Refresh Rate", "gMatchRefreshRate"); + UIWidgets::Tooltip("Matches interpolation value to the current game's window refresh rate"); + UIWidgets::Spacer(0); + UIWidgets::EnhancementCheckbox("Disable LOD", "gDisableLOD"); UIWidgets::Tooltip("Turns off the Level of Detail setting, making models use their higher-poly variants at any distance"); if (UIWidgets::PaddedEnhancementCheckbox("Disable Draw Distance", "gDisableDrawDistance", true, false)) { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 7dd6ddcfd..865237094 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -313,6 +313,14 @@ bool OTRGlobals::HasOriginal() { return hasOriginal; } +uint32_t OTRGlobals::GetInterpolationFPS() { + if (CVarGetInteger("gMatchRefreshRate", 0)) { + return Ship::Window::GetInstance()->GetCurrentRefreshRate(); + } + + return std::min(Ship::Window::GetInstance()->GetCurrentRefreshRate(), CVarGetInteger("gInterpolationFPS", 20)); +} + std::shared_ptr> OTRGlobals::ListFiles(std::string path) { return context->GetResourceManager()->ListFiles(path); } @@ -731,7 +739,7 @@ extern "C" void Graph_ProcessGfxCommands(Gfx* commands) { audio.cv_to_thread.notify_one(); std::vector> mtx_replacements; - int target_fps = CVarGetInteger("gInterpolationFPS", 20); + int target_fps = OTRGlobals::Instance->GetInterpolationFPS(); static int last_fps; static int last_update_rate; static int time; diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index f79b232e0..cbe0cc4cf 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -28,6 +28,7 @@ public: bool HasMasterQuest(); bool HasOriginal(); + uint32_t GetInterpolationFPS(); std::shared_ptr> ListFiles(std::string path); private: