- gameclock abstraction

This may need more work to have a reliable timer
This commit is contained in:
Christoph Oelckers 2020-08-31 00:16:43 +02:00
parent 7684f9e3e6
commit 007c6e122d
5 changed files with 20 additions and 8 deletions

View file

@ -96,7 +96,8 @@ GameInterface* gi;
int myconnectindex, numplayers;
int connecthead, connectpoint2[MAXMULTIPLAYERS];
auto vsnprintfptr = vsnprintf; // This is an inline in Visual Studio but we need an address for it to satisfy the MinGW compiled libraries.
int gameclock, gameclockstart;
int gameclock;
uint64_t gameclockstart;
int lastTic;
int automapMode;

View file

@ -9,6 +9,7 @@
#include "name.h"
#include "memarena.h"
#include "stats.h"
#include "i_time.h"
extern FString currentGame;
extern FString LumpFilter;
@ -223,5 +224,16 @@ extern int automapMode;
extern bool automapFollow;
extern bool sendPause;
extern int gameclock;
extern int gameclockstart;
extern uint64_t gameclockstart;
extern int lastTic;
inline void setGameClockStart()
{
gameclockstart = I_GetTimeNS();
gameclock = 0;
}
inline void updateGameClock()
{
gameclock = static_cast<int>((I_GetTimeNS() - gameclockstart) * 120 / 1'000'000'000);
}

View file

@ -194,7 +194,7 @@ static void GameTicker()
case GS_LEVEL:
gameupdatetime.Reset();
gameupdatetime.Clock();
gameclock = I_GetBuildTime() - gameclockstart;
updateGameClock();
gi->Ticker();
gameupdatetime.Unclock();
break;
@ -248,7 +248,7 @@ void Display()
twod->Clear();
twod->SetSize(screen->GetWidth(), screen->GetHeight());
twodpsp.SetSize(screen->GetWidth(), screen->GetHeight());
gameclock = I_GetBuildTime() - gameclockstart;
updateGameClock();
gi->Render();
DrawFullscreenBlends();
}

View file

@ -119,8 +119,7 @@ void GameInterface::Ticker()
void resetGameClock()
{
I_SetFrameTime();
gameclockstart = I_GetBuildTime();
gameclock = 0;
setGameClockStart();
cloudclock = 0;
}

View file

@ -728,7 +728,7 @@ void GameTicker(void)
ready2send = 1;
int const currentTic = I_GetTime();
gameclock = I_GetBuildTime() - gameclockstart;
updateGameClock();
if (paused)
{
@ -775,7 +775,7 @@ void GameTicker(void)
void resetGameClock()
{
I_SetFrameTime();
gameclockstart = I_GetBuildTime();
setGameClockStart();
ogameclock = gameclock = 0;
}