From c3b6daefc9e7e60a6c2bee1b907e250f32adb16d Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Sat, 2 Oct 2021 07:42:08 +0300 Subject: [PATCH] Added uncapped UPS option. Issue #18. --- SpaceCadetPinball/options.cpp | 2 ++ SpaceCadetPinball/options.h | 1 + SpaceCadetPinball/winmain.cpp | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index 4a9112c..3806b5b 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -74,6 +74,7 @@ void options::init() Options.UpdatesPerSecond = std::min(MaxUps, std::max(MinUps, get_int("Updates Per Second", DefUps))); Options.UpdatesPerSecond = std::max(Options.UpdatesPerSecond, Options.FramesPerSecond); Options.ShowMenu = get_int("ShowMenu", true); + Options.UncappedUpdatesPerSecond = get_int("Uncapped Updates Per Second", false); winmain::UpdateFrameRate(); @@ -104,6 +105,7 @@ void options::uninit() set_int("Frames Per Second", Options.FramesPerSecond); set_int("Updates Per Second", Options.UpdatesPerSecond); set_int("ShowMenu", Options.ShowMenu); + set_int("Uncapped Updates Per Second", Options.UncappedUpdatesPerSecond); } diff --git a/SpaceCadetPinball/options.h b/SpaceCadetPinball/options.h index 004ad11..87c86cb 100644 --- a/SpaceCadetPinball/options.h +++ b/SpaceCadetPinball/options.h @@ -53,6 +53,7 @@ struct optionsStruct int FramesPerSecond; int UpdatesPerSecond; bool ShowMenu; + bool UncappedUpdatesPerSecond; }; struct ControlRef diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 189724e..970aba9 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -269,7 +269,7 @@ int winmain::WinMain(LPCSTR lpCmdLine) auto targetTimeDelta = TargetFrameTime - DurationMs(updateEnd - frameStart) - sleepRemainder; TimePoint frameEnd; - if (targetTimeDelta > DurationMs::zero()) + if (targetTimeDelta > DurationMs::zero() && !options::Options.UncappedUpdatesPerSecond) { std::this_thread::sleep_for(targetTimeDelta); frameEnd = Clock::now(); @@ -459,6 +459,7 @@ void winmain::RenderUi() "%.2f", ImGuiSliderFlags_AlwaysClamp); ImGui::Separator(); + char buffer[80]{}; auto changed = false; if (ImGui::MenuItem("Set Default UPS/FPS")) { @@ -480,6 +481,12 @@ void winmain::RenderUi() options::Options.UpdatesPerSecond = std::max(options::Options.UpdatesPerSecond, options::Options.FramesPerSecond); } + snprintf(buffer, sizeof buffer - 1, "Uncapped UPS (FPS ratio %02.02f)", UpdateToFrameRatio); + if (ImGui::MenuItem(buffer, nullptr, options::Options.UncappedUpdatesPerSecond)) + { + options::Options.UncappedUpdatesPerSecond ^= true; + } + if (changed) { UpdateFrameRate();