diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/perf_stats.cpp | 17 | ||||
-rw-r--r-- | src/core/settings.h | 3 | ||||
-rw-r--r-- | src/core/telemetry_session.cpp | 5 |
3 files changed, 18 insertions, 7 deletions
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 4e5633edb..93d23de21 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -78,20 +78,29 @@ void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) { // values increase the time needed to recover and limit framerate again after spikes. constexpr microseconds MAX_LAG_TIME_US = 25000us; - if (!Settings::values.toggle_framelimit) { + if (!Settings::values.use_frame_limit) { return; } auto now = Clock::now(); - frame_limiting_delta_err += current_system_time_us - previous_system_time_us; + const double sleep_scale = Settings::values.frame_limit / 100.0; + + // Max lag caused by slow frames. Shouldn't be more than the length of a frame at the current + // speed percent or it will clamp too much and prevent this from properly limiting to that + // percent. High values means it'll take longer after a slow frame to recover and start + // limiting + const microseconds max_lag_time_us = duration_cast<microseconds>( + std::chrono::duration<double, std::chrono::microseconds::period>(25ms / sleep_scale)); + frame_limiting_delta_err += duration_cast<microseconds>( + std::chrono::duration<double, std::chrono::microseconds::period>( + (current_system_time_us - previous_system_time_us) / sleep_scale)); frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime); frame_limiting_delta_err = - std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); + std::clamp(frame_limiting_delta_err, -max_lag_time_us, max_lag_time_us); if (frame_limiting_delta_err > microseconds::zero()) { std::this_thread::sleep_for(frame_limiting_delta_err); - auto now_after_sleep = Clock::now(); frame_limiting_delta_err -= duration_cast<microseconds>(now_after_sleep - now); now = now_after_sleep; diff --git a/src/core/settings.h b/src/core/settings.h index 73dc3061f..ed6f42471 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -130,7 +130,8 @@ struct Values { // Renderer float resolution_factor; - bool toggle_framelimit; + bool use_frame_limit; + u16 frame_limit; bool use_accurate_framebuffers; float bg_red; diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 69383330f..827a1bbd0 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -106,8 +106,9 @@ TelemetrySession::TelemetrySession() { Settings::values.use_multi_core); AddField(Telemetry::FieldType::UserConfig, "Renderer_ResolutionFactor", Settings::values.resolution_factor); - AddField(Telemetry::FieldType::UserConfig, "Renderer_ToggleFramelimit", - Settings::values.toggle_framelimit); + AddField(Telemetry::FieldType::UserConfig, "Renderer_UseFrameLimit", + Settings::values.use_frame_limit); + AddField(Telemetry::FieldType::UserConfig, "Renderer_FrameLimit", Settings::values.frame_limit); AddField(Telemetry::FieldType::UserConfig, "Renderer_UseAccurateFramebuffers", Settings::values.use_accurate_framebuffers); AddField(Telemetry::FieldType::UserConfig, "System_UseDockedMode", |