From 9bf7babb9a54307743e29954a5c922d30f438f79 Mon Sep 17 00:00:00 2001 From: gendlin <108626604+gendlin@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:19:32 -0400 Subject: [PATCH] Improve frame limiter behavior on older CPUs (#1723) --- src/i_video.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/i_video.c b/src/i_video.c index 8e448bb2..9256b56f 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -714,6 +714,17 @@ static unsigned int disk_to_draw, disk_to_restore; static void CreateUpscaledTexture(boolean force); static void I_ResetTargetRefresh(void); +// +// I_CpuPause +// Avoids a performance penalty on exit from busy-wait loops. This should be +// called on every iteration of the loop and positioned near the loop exit. +// +#if SDL_VERSION_ATLEAST(2, 24, 0) + #define I_CpuPause() SDL_CPUPauseInstruction() +#else + #define I_CpuPause() +#endif + void I_FinishUpdate(void) { if (noblit) @@ -787,6 +798,8 @@ void I_FinishUpdate(void) uint64_t elapsed_time = current_time - frametime_start; uint64_t remaining_time = 0; + I_CpuPause(); + if (elapsed_time >= target_time) { frametime_start = current_time;