diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/core_timing.cpp | 4 | ||||
| -rw-r--r-- | src/core/core_timing.h | 3 | ||||
| -rw-r--r-- | src/core/perf_stats.cpp | 17 | ||||
| -rw-r--r-- | src/core/perf_stats.h | 8 |
4 files changed, 16 insertions, 16 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index b2e3a495a..d3bb6f818 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -226,8 +226,8 @@ void Idle() { | |||
| 226 | downcount = 0; | 226 | downcount = 0; |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | u64 GetGlobalTimeUs() { | 229 | std::chrono::microseconds GetGlobalTimeUs() { |
| 230 | return GetTicks() * 1000000 / BASE_CLOCK_RATE; | 230 | return std::chrono::microseconds{GetTicks() * 1000000 / BASE_CLOCK_RATE}; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | int GetDowncount() { | 233 | int GetDowncount() { |
diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 5bbde47f4..dfa161c0d 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | * ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever") | 17 | * ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever") |
| 18 | */ | 18 | */ |
| 19 | 19 | ||
| 20 | #include <chrono> | ||
| 20 | #include <functional> | 21 | #include <functional> |
| 21 | #include <string> | 22 | #include <string> |
| 22 | #include "common/common_types.h" | 23 | #include "common/common_types.h" |
| @@ -86,7 +87,7 @@ void ClearPendingEvents(); | |||
| 86 | 87 | ||
| 87 | void ForceExceptionCheck(s64 cycles); | 88 | void ForceExceptionCheck(s64 cycles); |
| 88 | 89 | ||
| 89 | u64 GetGlobalTimeUs(); | 90 | std::chrono::microseconds GetGlobalTimeUs(); |
| 90 | 91 | ||
| 91 | int GetDowncount(); | 92 | int GetDowncount(); |
| 92 | 93 | ||
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 5f53b16d3..8e09b9b63 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp | |||
| @@ -40,22 +40,21 @@ void PerfStats::EndGameFrame() { | |||
| 40 | game_frames += 1; | 40 | game_frames += 1; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { | 43 | PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_us) { |
| 44 | std::lock_guard<std::mutex> lock(object_mutex); | 44 | std::lock_guard<std::mutex> lock(object_mutex); |
| 45 | 45 | ||
| 46 | auto now = Clock::now(); | 46 | const auto now = Clock::now(); |
| 47 | // Walltime elapsed since stats were reset | 47 | // Walltime elapsed since stats were reset |
| 48 | auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); | 48 | const auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); |
| 49 | 49 | ||
| 50 | auto system_us_per_second = | 50 | const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval; |
| 51 | static_cast<double>(current_system_time_us - reset_point_system_us) / interval; | ||
| 52 | 51 | ||
| 53 | Results results{}; | 52 | Results results{}; |
| 54 | results.system_fps = static_cast<double>(system_frames) / interval; | 53 | results.system_fps = static_cast<double>(system_frames) / interval; |
| 55 | results.game_fps = static_cast<double>(game_frames) / interval; | 54 | results.game_fps = static_cast<double>(game_frames) / interval; |
| 56 | results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / | 55 | results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / |
| 57 | static_cast<double>(system_frames); | 56 | static_cast<double>(system_frames); |
| 58 | results.emulation_speed = system_us_per_second / 1'000'000.0; | 57 | results.emulation_speed = system_us_per_second.count() / 1'000'000.0; |
| 59 | 58 | ||
| 60 | // Reset counters | 59 | // Reset counters |
| 61 | reset_point = now; | 60 | reset_point = now; |
| @@ -74,10 +73,10 @@ double PerfStats::GetLastFrameTimeScale() { | |||
| 74 | return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; | 73 | return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; |
| 75 | } | 74 | } |
| 76 | 75 | ||
| 77 | void FrameLimiter::DoFrameLimiting(u64 current_system_time_us) { | 76 | void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) { |
| 78 | // Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher | 77 | // Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher |
| 79 | // 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. |
| 80 | constexpr microseconds MAX_LAG_TIME_US = 25ms; | 79 | constexpr microseconds MAX_LAG_TIME_US = 25us; |
| 81 | 80 | ||
| 82 | if (!Settings::values.toggle_framelimit) { | 81 | if (!Settings::values.toggle_framelimit) { |
| 83 | return; | 82 | return; |
| @@ -85,7 +84,7 @@ void FrameLimiter::DoFrameLimiting(u64 current_system_time_us) { | |||
| 85 | 84 | ||
| 86 | auto now = Clock::now(); | 85 | auto now = Clock::now(); |
| 87 | 86 | ||
| 88 | frame_limiting_delta_err += microseconds(current_system_time_us - previous_system_time_us); | 87 | frame_limiting_delta_err += current_system_time_us - previous_system_time_us; |
| 89 | frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime); | 88 | frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime); |
| 90 | frame_limiting_delta_err = | 89 | frame_limiting_delta_err = |
| 91 | std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); | 90 | std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); |
diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h index 362b205c8..6e4619701 100644 --- a/src/core/perf_stats.h +++ b/src/core/perf_stats.h | |||
| @@ -33,7 +33,7 @@ public: | |||
| 33 | void EndSystemFrame(); | 33 | void EndSystemFrame(); |
| 34 | void EndGameFrame(); | 34 | void EndGameFrame(); |
| 35 | 35 | ||
| 36 | Results GetAndResetStats(u64 current_system_time_us); | 36 | Results GetAndResetStats(std::chrono::microseconds current_system_time_us); |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | * Gets the ratio between walltime and the emulated time of the previous system frame. This is | 39 | * Gets the ratio between walltime and the emulated time of the previous system frame. This is |
| @@ -47,7 +47,7 @@ private: | |||
| 47 | /// Point when the cumulative counters were reset | 47 | /// Point when the cumulative counters were reset |
| 48 | Clock::time_point reset_point = Clock::now(); | 48 | Clock::time_point reset_point = Clock::now(); |
| 49 | /// System time when the cumulative counters were reset | 49 | /// System time when the cumulative counters were reset |
| 50 | u64 reset_point_system_us = 0; | 50 | std::chrono::microseconds reset_point_system_us{0}; |
| 51 | 51 | ||
| 52 | /// Cumulative duration (excluding v-sync/frame-limiting) of frames since last reset | 52 | /// Cumulative duration (excluding v-sync/frame-limiting) of frames since last reset |
| 53 | Clock::duration accumulated_frametime = Clock::duration::zero(); | 53 | Clock::duration accumulated_frametime = Clock::duration::zero(); |
| @@ -68,11 +68,11 @@ class FrameLimiter { | |||
| 68 | public: | 68 | public: |
| 69 | using Clock = std::chrono::high_resolution_clock; | 69 | using Clock = std::chrono::high_resolution_clock; |
| 70 | 70 | ||
| 71 | void DoFrameLimiting(u64 current_system_time_us); | 71 | void DoFrameLimiting(std::chrono::microseconds current_system_time_us); |
| 72 | 72 | ||
| 73 | private: | 73 | private: |
| 74 | /// Emulated system time (in microseconds) at the last limiter invocation | 74 | /// Emulated system time (in microseconds) at the last limiter invocation |
| 75 | u64 previous_system_time_us = 0; | 75 | std::chrono::microseconds previous_system_time_us{0}; |
| 76 | /// Walltime at the last limiter invocation | 76 | /// Walltime at the last limiter invocation |
| 77 | Clock::time_point previous_walltime = Clock::now(); | 77 | Clock::time_point previous_walltime = Clock::now(); |
| 78 | 78 | ||