From fbb919c02fd08bba8488b64e99809b7506c14910 Mon Sep 17 00:00:00 2001
From: bunnei <bunneidev@gmail.com>
Date: Sun, 26 Jun 2022 13:58:06 -0700
Subject: [PATCH] hle: service: nvflinger: Factor speed limit into frame time
 calculation.

- This allows the %-based "Limit Speed Percent" setting to work with MC emulation.
- This is already supported for SC emulation.
---
 src/core/hle/service/nvflinger/nvflinger.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index 5f69c8c2c2..f92d6beb5d 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -289,7 +289,14 @@ s64 NVFlinger::GetNextTicks() const {
     const auto& settings = Settings::values;
     const bool unlocked_fps = settings.disable_fps_limit.GetValue();
     const s64 fps_cap = unlocked_fps ? static_cast<s64>(settings.fps_cap.GetValue()) : 1;
-    return (1000000000 * (1LL << swap_interval)) / (max_hertz * fps_cap);
+    auto speed_scale = 1.f;
+    if (settings.use_speed_limit.GetValue() && settings.use_multi_core.GetValue()) {
+        // Scales the speed based on speed_limit setting on MC. SC is handled by
+        // SpeedLimiter::DoSpeedLimiting.
+        speed_scale = 100.f / settings.speed_limit.GetValue();
+    }
+    return static_cast<s64>(((1000000000 * (1LL << swap_interval)) / (max_hertz * fps_cap)) *
+                            speed_scale);
 }
 
 } // namespace Service::NVFlinger