From 22313868304e29471608a30effcf3d30387198fe Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 25 Aug 2020 17:14:27 +1000 Subject: [PATCH] - Duke: Create function to reset timer and apply in game where timer restarts are needed. --- source/common/utility/i_time.cpp | 5 +++++ source/common/utility/i_time.h | 3 +++ source/games/duke/src/gameloop.cpp | 4 ++-- source/games/duke/src/global.cpp | 1 + source/games/duke/src/global.h | 1 + source/games/duke/src/premap.cpp | 2 ++ 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/common/utility/i_time.cpp b/source/common/utility/i_time.cpp index 20c5ac831..2103c9830 100644 --- a/source/common/utility/i_time.cpp +++ b/source/common/utility/i_time.cpp @@ -170,6 +170,11 @@ int I_GetBuildTime() return NSToBuildTic(CurrentFrameStartTime - FirstFrameStartTime); } +void I_ResetTime() +{ + FirstFrameStartTime = CurrentFrameStartTime = 0; +} + double I_GetTimeFrac() { int currentTic = NSToTic(CurrentFrameStartTime - FirstFrameStartTime); diff --git a/source/common/utility/i_time.h b/source/common/utility/i_time.h index 1146cbd7d..230765053 100644 --- a/source/common/utility/i_time.h +++ b/source/common/utility/i_time.h @@ -15,6 +15,9 @@ uint64_t I_GetTimeNS(); // Called by Build games in liew of totalclock, returns current time in tics at ticrate of 120. int I_GetBuildTime(); +// Reset timer variables to zero when called. +void I_ResetTime(); + double I_GetTimeFrac(); // like I_GetTime, except it waits for a new tic before returning diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 261e3357f..5ecc6f244 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -308,8 +308,6 @@ static void checkTimerActive() // //--------------------------------------------------------------------------- -static int lastTic; - bool GameTicker() { if (ps[myconnectindex].gm == MODE_DEMO) @@ -413,6 +411,8 @@ void GameInterface::RunGameFrame() { default: case GS_STARTUP: + I_ResetTime(); + lastTic = -1; totalclock = 0; gameclock = 0; lockclock = 0; diff --git a/source/games/duke/src/global.cpp b/source/games/duke/src/global.cpp index be6e1a7d6..dea450a33 100644 --- a/source/games/duke/src/global.cpp +++ b/source/games/duke/src/global.cpp @@ -54,6 +54,7 @@ int max_armour_amount; int lasermode; int gameclock = 0, cameradist = 0, cameraclock = 0; +int lastTic = -1; int otherp; TileInfo tileinfo[MAXTILES]; // This is not from EDuke32. ActorInfo actorinfo[MAXTILES]; diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index 15125498a..e384461a3 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -38,6 +38,7 @@ extern int max_armour_amount; extern int lasermode; extern int gameclock; +extern int lastTic; extern int cameraclock; extern int cameradist; extern int otherp; // transient helper, MP only diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index b10f08d6b..e96330258 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -756,6 +756,8 @@ void prelevel_common(int g) void resettimevars(void) { + I_ResetTime(); + lastTic = -1; totalclock = 0; gameclock = 0; cloudtotalclock = 0;