Port Saturn timestuff branch
Should be better then I_UpdateTime spam https://github.com/Indev450/SRB2Kart-Saturn/commits/timestuff/
This commit is contained in:
parent
0444108088
commit
c1d16124e5
4 changed files with 47 additions and 5 deletions
|
|
@ -1081,9 +1081,7 @@ void D_SRB2Loop(void)
|
|||
|
||||
const boolean lagging = ((deltatics >= 1.0) || hu_stopped);
|
||||
|
||||
I_UpdateTime(cv_timescale.value);
|
||||
|
||||
R_SetTimeFrac(lagging ? FRACUNIT : g_time.timefrac);
|
||||
R_SetTimeFrac(lagging ? FRACUNIT : I_GetTimeFrac());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
32
src/i_time.c
32
src/i_time.c
|
|
@ -29,6 +29,25 @@ consvar_t cv_timescale = CVAR_INIT ("timescale", "1.0", CV_NETVAR|CV_CHEAT|CV_FL
|
|||
static precise_t enterprecise, oldenterprecise;
|
||||
static fixed_t entertic, oldentertics;
|
||||
static double tictimer;
|
||||
static double ticratescaled;
|
||||
|
||||
// experiment to prevent timing issues
|
||||
// this returns the global time state accounted with how much time has passed
|
||||
// since it was last updated
|
||||
static void I_GetTimeAndFrac(tic_t *outtics, fixed_t *outfrac)
|
||||
{
|
||||
double elapsedseconds;
|
||||
|
||||
elapsedseconds = (double)(I_GetPreciseTime() - oldenterprecise) / I_GetPrecisePrecision();
|
||||
|
||||
double fractional, integral;
|
||||
fractional = modf((tictimer + elapsedseconds) * ticratescaled, &integral);
|
||||
|
||||
if (outtics)
|
||||
*outtics = g_time.time + (tic_t)integral;
|
||||
if (outfrac)
|
||||
*outfrac = DoubleToFixed(fractional);
|
||||
}
|
||||
|
||||
// A little more than the minimum sleep duration on Windows.
|
||||
// May be incorrect for other platforms, but we don't currently have a way to
|
||||
|
|
@ -42,7 +61,16 @@ static double tictimer;
|
|||
|
||||
tic_t I_GetTime(void)
|
||||
{
|
||||
return g_time.time;
|
||||
tic_t tic;
|
||||
I_GetTimeAndFrac(&tic, NULL);
|
||||
return tic;
|
||||
}
|
||||
|
||||
fixed_t I_GetTimeFrac(void)
|
||||
{
|
||||
fixed_t frac;
|
||||
I_GetTimeAndFrac(NULL, &frac);
|
||||
return frac;
|
||||
}
|
||||
|
||||
void I_InitializeTime(void)
|
||||
|
|
@ -53,6 +81,7 @@ void I_InitializeTime(void)
|
|||
enterprecise = 0;
|
||||
oldenterprecise = 0;
|
||||
tictimer = 0.0;
|
||||
ticratescaled = 1.0;
|
||||
|
||||
CV_RegisterVar(&cv_timescale);
|
||||
|
||||
|
|
@ -63,7 +92,6 @@ void I_InitializeTime(void)
|
|||
|
||||
void I_UpdateTime(fixed_t timescale)
|
||||
{
|
||||
double ticratescaled;
|
||||
double elapsedseconds;
|
||||
tic_t realtics;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ extern consvar_t cv_timescale;
|
|||
*/
|
||||
tic_t I_GetTime(void);
|
||||
|
||||
fixed_t I_GetTimeFrac(void);
|
||||
|
||||
/** \brief Initializes timing system.
|
||||
*/
|
||||
void I_InitializeTime(void);
|
||||
|
|
|
|||
|
|
@ -70,6 +70,20 @@ FUNCMATH FUNCINLINE static ATTRINLINE INT64 FloatToFixed64(float f)
|
|||
return (INT64)(f * FRACUNIT);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief convert fixed_t into double-precision floating number
|
||||
*/
|
||||
|
||||
FUNCMATH FUNCINLINE static ATTRINLINE double FixedToDouble(fixed_t x)
|
||||
{
|
||||
return x / (double)FRACUNIT;
|
||||
}
|
||||
|
||||
FUNCMATH FUNCINLINE static ATTRINLINE fixed_t DoubleToFixed(double f)
|
||||
{
|
||||
return (fixed_t)(f * FRACUNIT);
|
||||
}
|
||||
|
||||
// for backwards compat
|
||||
#define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT))
|
||||
#define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT))
|
||||
|
|
|
|||
Loading…
Reference in a new issue