2022-04-30 21:33:23 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
2023-03-31 12:53:31 +00:00
|
|
|
// Copyright (C) 1999-2023 by Sonic Team Junior.
|
2022-04-30 21:33:23 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file i_time.c
|
|
|
|
/// \brief Timing for the system layer.
|
|
|
|
|
|
|
|
#include "i_time.h"
|
|
|
|
|
2022-05-01 05:32:46 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2022-04-30 21:33:23 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "doomtype.h"
|
2022-12-31 13:10:19 +00:00
|
|
|
#include "netcode/d_netcmd.h"
|
2022-04-30 21:33:23 +00:00
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
|
|
|
|
timestate_t g_time;
|
|
|
|
|
|
|
|
static CV_PossibleValue_t timescale_cons_t[] = {{FRACUNIT/20, "MIN"}, {20*FRACUNIT, "MAX"}, {0, NULL}};
|
|
|
|
consvar_t cv_timescale = CVAR_INIT ("timescale", "1.0", CV_NETVAR|CV_CHEAT|CV_FLOAT, timescale_cons_t, NULL);
|
|
|
|
|
|
|
|
static precise_t enterprecise, oldenterprecise;
|
|
|
|
static fixed_t entertic, oldentertics;
|
|
|
|
static double tictimer;
|
|
|
|
|
|
|
|
tic_t I_GetTime(void)
|
|
|
|
{
|
|
|
|
return g_time.time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_InitializeTime(void)
|
|
|
|
{
|
|
|
|
CV_RegisterVar(&cv_timescale);
|
|
|
|
|
|
|
|
// I_StartupTimer is preserved for potential subsystems that need to setup
|
|
|
|
// timing information for I_GetPreciseTime and sleeping
|
|
|
|
I_StartupTimer();
|
2023-03-19 13:44:18 +00:00
|
|
|
|
|
|
|
g_time.time = 0;
|
|
|
|
g_time.timefrac = 0;
|
|
|
|
|
|
|
|
enterprecise = I_GetPreciseTime();
|
|
|
|
oldenterprecise = enterprecise;
|
|
|
|
entertic = 0;
|
|
|
|
oldentertics = 0;
|
|
|
|
tictimer = 0.0;
|
2022-04-30 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void I_UpdateTime(fixed_t timescale)
|
|
|
|
{
|
|
|
|
double ticratescaled;
|
|
|
|
double elapsedseconds;
|
|
|
|
tic_t realtics;
|
|
|
|
|
|
|
|
// get real tics
|
|
|
|
ticratescaled = (double)TICRATE * FIXED_TO_FLOAT(timescale);
|
|
|
|
|
|
|
|
enterprecise = I_GetPreciseTime();
|
2022-05-01 05:32:46 +00:00
|
|
|
elapsedseconds = (double)(enterprecise - oldenterprecise) / I_GetPrecisePrecision();
|
2022-04-30 21:33:23 +00:00
|
|
|
tictimer += elapsedseconds;
|
|
|
|
while (tictimer > 1.0/ticratescaled)
|
|
|
|
{
|
|
|
|
entertic += 1;
|
|
|
|
tictimer -= 1.0/ticratescaled;
|
|
|
|
}
|
|
|
|
realtics = entertic - oldentertics;
|
|
|
|
oldentertics = entertic;
|
|
|
|
oldenterprecise = enterprecise;
|
|
|
|
|
|
|
|
// Update global time state
|
|
|
|
g_time.time += realtics;
|
|
|
|
{
|
|
|
|
double fractional, integral;
|
|
|
|
fractional = modf(tictimer * ticratescaled, &integral);
|
|
|
|
g_time.timefrac = FLOAT_TO_FIXED(fractional);
|
|
|
|
}
|
2022-05-01 05:32:46 +00:00
|
|
|
}
|