diff options
Diffstat (limited to 'src/core/perf_stats.cpp')
| -rw-r--r-- | src/core/perf_stats.cpp | 17 |
1 files changed, 13 insertions, 4 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) { | |||
| 78 | // values increase the time needed to recover and limit framerate again after spikes. | 78 | // values increase the time needed to recover and limit framerate again after spikes. |
| 79 | constexpr microseconds MAX_LAG_TIME_US = 25000us; | 79 | constexpr microseconds MAX_LAG_TIME_US = 25000us; |
| 80 | 80 | ||
| 81 | if (!Settings::values.toggle_framelimit) { | 81 | if (!Settings::values.use_frame_limit) { |
| 82 | return; | 82 | return; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | auto now = Clock::now(); | 85 | auto now = Clock::now(); |
| 86 | 86 | ||
| 87 | frame_limiting_delta_err += current_system_time_us - previous_system_time_us; | 87 | const double sleep_scale = Settings::values.frame_limit / 100.0; |
| 88 | |||
| 89 | // Max lag caused by slow frames. Shouldn't be more than the length of a frame at the current | ||
| 90 | // speed percent or it will clamp too much and prevent this from properly limiting to that | ||
| 91 | // percent. High values means it'll take longer after a slow frame to recover and start | ||
| 92 | // limiting | ||
| 93 | const microseconds max_lag_time_us = duration_cast<microseconds>( | ||
| 94 | std::chrono::duration<double, std::chrono::microseconds::period>(25ms / sleep_scale)); | ||
| 95 | frame_limiting_delta_err += duration_cast<microseconds>( | ||
| 96 | std::chrono::duration<double, std::chrono::microseconds::period>( | ||
| 97 | (current_system_time_us - previous_system_time_us) / sleep_scale)); | ||
| 88 | frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime); | 98 | frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime); |
| 89 | frame_limiting_delta_err = | 99 | frame_limiting_delta_err = |
| 90 | std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); | 100 | std::clamp(frame_limiting_delta_err, -max_lag_time_us, max_lag_time_us); |
| 91 | 101 | ||
| 92 | if (frame_limiting_delta_err > microseconds::zero()) { | 102 | if (frame_limiting_delta_err > microseconds::zero()) { |
| 93 | std::this_thread::sleep_for(frame_limiting_delta_err); | 103 | std::this_thread::sleep_for(frame_limiting_delta_err); |
| 94 | |||
| 95 | auto now_after_sleep = Clock::now(); | 104 | auto now_after_sleep = Clock::now(); |
| 96 | frame_limiting_delta_err -= duration_cast<microseconds>(now_after_sleep - now); | 105 | frame_limiting_delta_err -= duration_cast<microseconds>(now_after_sleep - now); |
| 97 | now = now_after_sleep; | 106 | now = now_after_sleep; |