From ab0623597189652871c26e58f94a9810edfdded2 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 25 Aug 2020 15:06:29 +1000 Subject: [PATCH] - Duke: Demonstration of a re-timed game and associated interpolation improvements that come from it. # Conflicts: # source/games/duke/src/game.cpp --- source/games/duke/src/game.cpp | 2 +- source/games/duke/src/gameloop.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 4a333deb8..1ec0363ef 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -350,7 +350,7 @@ static void Startup(void) SetDispatcher(); S_InitSound(); - timerInit(TICRATE); + timerInit(GameTicRate); loadcons(); fi.initactorflags(); diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index d3b20585b..bbbe19b7a 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -308,6 +308,8 @@ static void checkTimerActive() // //--------------------------------------------------------------------------- +static int lastTic; + bool GameTicker() { if (ps[myconnectindex].gm == MODE_DEMO) @@ -327,9 +329,11 @@ bool GameTicker() gameupdatetime.Reset(); gameupdatetime.Clock(); - while (playrunning() && (int)(totalclock - ototalclock) >= TICSPERFRAME) + int currentTic = I_GetTime(); + + if (playrunning() && currentTic - lastTic >= 1) { - ototalclock += TICSPERFRAME; + lastTic = currentTic; GetInput(); auto const pPlayer = &ps[myconnectindex]; @@ -356,7 +360,7 @@ bool GameTicker() { ototalclock = totalclock - 1; } - double const smoothRatio = calc_smoothratio(totalclock, ototalclock); + double const smoothRatio = I_GetTimeFrac() * 65536.; gameupdatetime.Unclock();