mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-02-02 13:51:52 +00:00
- normalize the timer with the app start, not the epoch.
This ensures smaller values and less wraparounds with integer values in scripts.
This commit is contained in:
parent
b225a910a0
commit
94b249172a
3 changed files with 18 additions and 3 deletions
|
@ -44,6 +44,7 @@
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
|
static uint64_t StartupTimeNS;
|
||||||
static uint64_t FirstFrameStartTime;
|
static uint64_t FirstFrameStartTime;
|
||||||
static uint64_t CurrentFrameStartTime;
|
static uint64_t CurrentFrameStartTime;
|
||||||
static uint64_t FreezeTime;
|
static uint64_t FreezeTime;
|
||||||
|
@ -52,11 +53,22 @@ int GameTicRate = 35; // make sure it is not 0, even if the client doesn't set i
|
||||||
|
|
||||||
double TimeScale = 1.0;
|
double TimeScale = 1.0;
|
||||||
|
|
||||||
static uint64_t GetClockTimeNS()
|
static uint64_t GetTimePoint()
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
if (TimeScale == 1.0) return (uint64_t)(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count());
|
return (uint64_t)(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count());
|
||||||
else return (uint64_t)((duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count()) * (uint64_t)(TimeScale * 1000));
|
}
|
||||||
|
|
||||||
|
void I_InitTime()
|
||||||
|
{
|
||||||
|
StartupTimeNS = GetTimePoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t GetClockTimeNS()
|
||||||
|
{
|
||||||
|
auto tp = GetTimePoint() - StartupTimeNS;
|
||||||
|
if (TimeScale == 1.0) return tp;
|
||||||
|
else return tp / 1000 * TimeScale * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t MSToNS(unsigned int ms)
|
static uint64_t MSToNS(unsigned int ms)
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
extern int GameTicRate;
|
extern int GameTicRate;
|
||||||
extern double TimeScale;
|
extern double TimeScale;
|
||||||
|
|
||||||
|
void I_InitTime();
|
||||||
|
|
||||||
// Called by D_DoomLoop, sets the time for the current frame
|
// Called by D_DoomLoop, sets the time for the current frame
|
||||||
void I_SetFrameTime();
|
void I_SetFrameTime();
|
||||||
|
|
||||||
|
|
|
@ -3688,6 +3688,7 @@ int GameMain()
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
GameTicRate = TICRATE;
|
GameTicRate = TICRATE;
|
||||||
|
I_InitTime();
|
||||||
|
|
||||||
ConsoleCallbacks cb = {
|
ConsoleCallbacks cb = {
|
||||||
D_UserInfoChanged,
|
D_UserInfoChanged,
|
||||||
|
|
Loading…
Reference in a new issue