From 9b4e485686bdd679ad7d1bf578ba87cac01c8e1a Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Wed, 27 Apr 2022 17:02:35 -0400 Subject: [PATCH] Fix frame pacing when game lags behind The frame timestamp should've been made at the start of the frame, not the end. --- src/d_main.c | 3 ++- src/sdl/i_system.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 6aeaf61e5..eb01edd9d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -755,6 +755,8 @@ void D_SRB2Loop(void) for (;;) { + frameEnd = I_GetFrameTime(); + if (lastwipetic) { oldentertics = lastwipetic; @@ -890,7 +892,6 @@ void D_SRB2Loop(void) LUA_Step(); // Fully completed frame made. - frameEnd = I_GetFrameTime(); if (!singletics && !dedicated) { I_FrameCapSleep(frameEnd); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 2e1bf0c17..05386e9b5 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2157,8 +2157,14 @@ static void UpdateElapsedTics(void) tic_t I_GetTime(void) { + float f = 0.0f; + UpdateElapsedTics(); - return (tic_t) floor(elapsed_tics); + + // This needs kept in a separate variable before converting + // to tic_t, due to stupid -Wbad-function-cast error. + f = floor(elapsed_tics); + return (tic_t)f; } float I_GetTimeFrac(void)