Skip to content

Commit

Permalink
- moved high level code out of i_time.cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Mar 27, 2020
1 parent 6049e80 commit fabe772
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
21 changes: 21 additions & 0 deletions src/d_main.cpp
Expand Up @@ -174,6 +174,26 @@ extern bool insave;
extern TDeletingArray<FLightDefaults *> LightDefaults;


CUSTOM_CVAR(Float, i_timescale, 1.0f, CVAR_NOINITCALL)
{
if (netgame)
{
Printf("Time scale cannot be changed in net games.\n");
self = 1.0f;
}
else if (self >= 0.05f)
{
I_FreezeTime(true);
TimeScale = self;
I_FreezeTime(false);
}
else
{
Printf("Time scale must be at least 0.05!\n");
}
}


// PUBLIC DATA DEFINITIONS -------------------------------------------------

CUSTOM_CVAR (Int, fraglimit, 0, CVAR_SERVERINFO)
Expand Down Expand Up @@ -2883,6 +2903,7 @@ static int D_DoomMain_Internal (void)
int D_DoomMain()
{
int ret = 0;
GameTicRate = TICRATE;
try
{
ret = D_DoomMain_Internal();
Expand Down
30 changes: 4 additions & 26 deletions src/utility/i_time.cpp
Expand Up @@ -36,10 +36,6 @@
#include <chrono>
#include <thread>
#include "i_time.h"
#include "doomdef.h"
#include "c_cvars.h"
#include "doomstat.h"
#include "doomtype.h"

//==========================================================================
//
Expand All @@ -50,27 +46,9 @@
static uint64_t FirstFrameStartTime;
static uint64_t CurrentFrameStartTime;
static uint64_t FreezeTime;
int GameTicRate;

static double TimeScale = 1.0;

CUSTOM_CVAR(Float, i_timescale, 1.0f, CVAR_NOINITCALL)
{
if (netgame)
{
Printf("Time scale cannot be changed in net games.\n");
self = 1.0f;
}
else if (self >= 0.05f)
{
I_FreezeTime(true);
TimeScale = self;
I_FreezeTime(false);
}
else
{
Printf("Time scale must be at least 0.05!\n");
}
}
double TimeScale = 1.0;

static uint64_t GetClockTimeNS()
{
Expand All @@ -90,12 +68,12 @@ static uint64_t NSToMS(uint64_t ns)

static int NSToTic(uint64_t ns)
{
return static_cast<int>(ns * TICRATE / 1'000'000'000);
return static_cast<int>(ns * GameTicRate / 1'000'000'000);
}

static uint64_t TicToNS(int tic)
{
return static_cast<uint64_t>(tic) * 1'000'000'000 / TICRATE;
return static_cast<uint64_t>(tic) * 1'000'000'000 / GameTicRate;
}

void I_SetFrameTime()
Expand Down
3 changes: 3 additions & 0 deletions src/utility/i_time.h
Expand Up @@ -2,6 +2,9 @@

#include <stdint.h>

extern int GameTicRate;
extern double TimeScale;

// Called by D_DoomLoop, sets the time for the current frame
void I_SetFrameTime();

Expand Down

0 comments on commit fabe772

Please sign in to comment.