From 80145d6e6c0513149aa443d5d4f511b0377b2e87 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 18 Dec 2023 16:06:43 +0700 Subject: [PATCH] working DRS in capped mode, remove newsync uncapped hack (#1341) --- src/d_loop.c | 15 +------------ src/i_video.c | 60 ++++++++++++++++++++++++++++++--------------------- src/i_video.h | 1 + src/m_menu.c | 8 ++++--- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/d_loop.c b/src/d_loop.c index c7b24558..bd31db2d 100644 --- a/src/d_loop.c +++ b/src/d_loop.c @@ -755,20 +755,7 @@ void TryRunTics (void) if (new_sync) { - if (uncapped) - { - // decide how many tics to run - if (realtics < availabletics-1) - counts = realtics+1; - else if (realtics < availabletics) - counts = realtics; - else - counts = availabletics; - } - else - { - counts = availabletics; - } + counts = availabletics; // [AM] If we've uncapped the framerate and there are no tics // to run, return early instead of waiting around. diff --git a/src/i_video.c b/src/i_video.c index 0991bb44..9a3ea3b4 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -89,7 +89,7 @@ static int actualheight; static int native_width; static int native_height; static int native_height_adjusted; -static int refresh_rate; +static int native_refresh_rate; static boolean need_resize; @@ -477,6 +477,7 @@ static void UpdateRender(void) } static uint64_t frametime_withoutpresent; +static int targetrefresh; static void ResetResolution(int height); static void ResetLogicalSize(void); @@ -495,7 +496,7 @@ static void DynamicResolution(void) } // 1.25 milliseconds for SDL render present - double target = (1.0 / refresh_rate) - 0.00125; + double target = (1.0 / targetrefresh) - 0.00125; double actual = frametime_withoutpresent / 1000000.0; double actualpercent = actual / target; @@ -609,34 +610,32 @@ void I_FinishUpdate(void) need_resize = false; } - if (uncapped) + if (uncapped && fpslimit >= TICRATE) { - if (fpslimit >= TICRATE) + uint64_t target_time = 1000000ull / targetrefresh; + + while (true) { - uint64_t target_time = 1000000ull / fpslimit; - static uint64_t start_time; + uint64_t current_time = I_GetTimeUS(); + uint64_t elapsed_time = current_time - frametime_start; + uint64_t remaining_time = 0; - while (1) + if (elapsed_time >= target_time) { - uint64_t current_time = I_GetTimeUS(); - uint64_t elapsed_time = current_time - start_time; - uint64_t remaining_time = 0; - - if (elapsed_time >= target_time) - { - start_time = current_time; - break; - } - - remaining_time = target_time - elapsed_time; - - if (remaining_time > 1000) - I_Sleep((remaining_time - 1000) / 1000); + frametime_start = current_time; + break; } + + remaining_time = target_time - elapsed_time; + + if (remaining_time > 1000) + I_Sleep((remaining_time - 1000) / 1000); } } - - frametime_start = I_GetTimeUS(); + else + { + frametime_start = I_GetTimeUS(); + } } // @@ -1149,6 +1148,18 @@ static void ResetLogicalSize(void) } } +void I_ResetTargetRefresh(void) +{ + if (uncapped) + { + targetrefresh = (fpslimit >= TICRATE) ? fpslimit : native_refresh_rate; + } + else + { + targetrefresh = TICRATE; + } +} + // // killough 11/98: New routine, for setting hires and page flipping // @@ -1161,6 +1172,7 @@ static void I_InitVideoParms(void) resolution_mode = default_resolution_mode; uncapped = default_uncapped; grabmouse = default_grabmouse; + I_ResetTargetRefresh(); //! // @category video @@ -1359,7 +1371,7 @@ static void CreateSurfaces(void) native_width = mode.w; native_height = mode.h; - refresh_rate = mode.refresh_rate; + native_refresh_rate = mode.refresh_rate; w = native_width; h = use_aspect ? (int)(native_height / 1.2) : native_height; diff --git a/src/i_video.h b/src/i_video.h index 0040d34a..2b6b01d4 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -62,6 +62,7 @@ void I_FinishUpdate (void); void I_ReadScreen (byte* scr); void I_ResetScreen(void); // killough 10/98 +void I_ResetTargetRefresh(void); void I_ToggleVsync(void); // [JN] Calls native SDL vsync toggle extern boolean use_vsync; // killough 2/8/98: controls whether vsync is called diff --git a/src/m_menu.c b/src/m_menu.c index 00f9cfcc..6e128f6c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3773,9 +3773,10 @@ static void M_SetMidiPlayer(void) S_RestartMusic(); } -static void M_EnableDisableFPSLimit(void) +static void M_ToggleUncapped(void) { DISABLE_ITEM(!uncapped, gen_settings1[gen1_fpslimit]); + I_ResetTargetRefresh(); } static void M_ToggleFullScreen(void) @@ -3792,6 +3793,7 @@ static void M_CoerceFPSLimit(void) { if (fpslimit < TICRATE) fpslimit = 0; + I_ResetTargetRefresh(); } static void M_ResetScreen(void) @@ -3820,7 +3822,7 @@ setup_menu_t gen_settings1[] = { // General Settings screen1 {"", S_SKIP, m_null, M_X, M_Y + gen1_gap2*M_SPC}, {"Uncapped Frame Rate", S_YESNO, m_null, M_X, M_Y+ gen1_uncapped*M_SPC, - {"uncapped"}, 0, M_EnableDisableFPSLimit}, + {"uncapped"}, 0, M_ToggleUncapped}, {"Frame Rate Limit", S_NUM, m_null, M_X, M_Y + gen1_fpslimit*M_SPC, {"fpslimit"}, 0, M_CoerceFPSLimit}, @@ -6864,7 +6866,7 @@ void M_ResetSetupMenu(void) void M_ResetSetupMenuVideo(void) { - M_EnableDisableFPSLimit(); + M_ToggleUncapped(); } //