From d3b506eb2be2eca96b983143828a7e369752a989 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 25 Aug 2020 20:48:42 +1000 Subject: [PATCH] - Duke (and Engine): Eliminate use of totalclock for game. * Breaks every other game except Duke unless/until they get migrated. Done for the purpose of demonstrating PR #244. # Conflicts: # source/build/src/timer.cpp # source/games/duke/src/game.cpp --- source/build/src/engine.cpp | 2 +- source/build/src/mdsprite.cpp | 4 ++-- source/build/src/timer.cpp | 2 -- source/core/inputstate.cpp | 16 +++++++++++++++- source/core/inputstate.h | 2 ++ source/games/duke/src/game.cpp | 1 - source/games/duke/src/gameloop.cpp | 1 - source/games/duke/src/premap.cpp | 1 - 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index d7b771e7c..59f6b9edf 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -1286,7 +1286,7 @@ int32_t renderDrawRoomsQ16(int32_t daposx, int32_t daposy, int32_t daposz, globalhoriz = fix16_to_int(qglobalhoriz); globalcursectnum = dacursectnum; - totalclocklock = totalclock; + totalclocklock = I_GetBuildTime(); if ((xyaspect != oxyaspect) || (xdimen != oxdimen) || (viewingrange != oviewingrange)) dosetaspect(); diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index c0b1ff5b1..4b34165f0 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -599,7 +599,7 @@ static void updateanimation(md2model_t *m, tspriteptr_t tspr, uint8_t lpal) fps = smooth->mdsmooth ? Blrintf((1.0f / ((float)tile2model[tile].smoothduration * (1.f / (float)UINT16_MAX))) * 66.f) : anim ? anim->fpssc : 1; - i = (mdtims - sprext->mdanimtims) * ((fps * timerGetClockRate()) / 120); + i = (mdtims - sprext->mdanimtims) * ((fps * 120) / 120); j = (smooth->mdsmooth || !anim) ? 65536 : ((anim->endframe + 1 - anim->startframe) << 16); @@ -607,7 +607,7 @@ static void updateanimation(md2model_t *m, tspriteptr_t tspr, uint8_t lpal) if (i < 0) { i = 0; sprext->mdanimtims = mdtims; } //compare with j*2 instead of j to ensure i stays > j-65536 for MDANIM_ONESHOT if (anim && (i >= j+j) && (fps) && !mdpause) //Keep mdanimtims close to mdtims to avoid the use of MOD - sprext->mdanimtims += j/((fps*timerGetClockRate())/120); + sprext->mdanimtims += j/((fps*120)/120); k = i; diff --git a/source/build/src/timer.cpp b/source/build/src/timer.cpp index 0e2bde063..14c82409c 100644 --- a/source/build/src/timer.cpp +++ b/source/build/src/timer.cpp @@ -48,6 +48,4 @@ void timerUpdateClock(void) totalclock += n; timerlastsample += n*nanoseconds(1000000000/timerticspersec); - } - diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 7e08d456f..f6abef928 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -113,6 +113,20 @@ void InputState::ClearAllInput() } +//========================================================================== +// +// +// +//========================================================================== + +TArray callbacks; + +void(*timerSetCallback(void(*callback)(void)))(void) +{ + callbacks.Push(callback); + return nullptr; +} + //========================================================================== // // @@ -145,7 +159,7 @@ int32_t handleevents(void) setsizeneeded = false; } - timerUpdateClock(); + for (auto cb : callbacks) cb(); I_StartFrame(); I_StartTic(); diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 22f0d5c24..a0e7f52a6 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -60,5 +60,7 @@ public: extern InputState inputState; +void (*timerSetCallback(void (*callback)(void)))(void); + void CONTROL_GetInput(ControlInfo* info); int32_t handleevents(void); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 4a333deb8..24798eed6 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -350,7 +350,6 @@ static void Startup(void) SetDispatcher(); S_InitSound(); - timerInit(TICRATE); loadcons(); fi.initactorflags(); diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index b7e8137fe..922228eec 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -413,7 +413,6 @@ void GameInterface::RunGameFrame() case GS_STARTUP: I_ResetTime(); lastTic = -1; - totalclock = 0; gameclock = 0; lockclock = 0; diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index e96330258..b91950822 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -758,7 +758,6 @@ void resettimevars(void) { I_ResetTime(); lastTic = -1; - totalclock = 0; gameclock = 0; cloudtotalclock = 0; levelTextTime = 85;