mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-20 00:11:19 +00:00
Implement I_GetTimeMicros without affecting I_GetTime behaviour details
This commit is contained in:
parent
724e093ce8
commit
1b6e65b91c
1 changed files with 21 additions and 28 deletions
|
@ -2060,12 +2060,11 @@ static p_timeGetTime pfntimeGetTime = NULL;
|
||||||
// but lower precision on Windows NT
|
// but lower precision on Windows NT
|
||||||
// ---------
|
// ---------
|
||||||
|
|
||||||
DWORD TimeFunction(boolean microseconds)
|
DWORD TimeFunction(int requested_frequency)
|
||||||
{
|
{
|
||||||
DWORD newtics = 0;
|
DWORD newtics = 0;
|
||||||
int multiplier = 1;
|
// this var acts as a multiplier if sub-millisecond precision is asked but is not available
|
||||||
|
int excess_frequency = requested_frequency / 1000;
|
||||||
if (microseconds) multiplier = 1000;
|
|
||||||
|
|
||||||
if (!starttickcount) // high precision timer
|
if (!starttickcount) // high precision timer
|
||||||
{
|
{
|
||||||
|
@ -2085,7 +2084,7 @@ DWORD TimeFunction(boolean microseconds)
|
||||||
|
|
||||||
if (frequency.LowPart && QueryPerformanceCounter(&currtime))
|
if (frequency.LowPart && QueryPerformanceCounter(&currtime))
|
||||||
{
|
{
|
||||||
newtics = (INT32)((currtime.QuadPart - basetime.QuadPart) * 1000 * multiplier
|
newtics = (INT32)((currtime.QuadPart - basetime.QuadPart) * requested_frequency
|
||||||
/ frequency.QuadPart);
|
/ frequency.QuadPart);
|
||||||
}
|
}
|
||||||
else if (pfntimeGetTime)
|
else if (pfntimeGetTime)
|
||||||
|
@ -2093,11 +2092,19 @@ DWORD TimeFunction(boolean microseconds)
|
||||||
currtime.LowPart = pfntimeGetTime();
|
currtime.LowPart = pfntimeGetTime();
|
||||||
if (!basetime.LowPart)
|
if (!basetime.LowPart)
|
||||||
basetime.LowPart = currtime.LowPart;
|
basetime.LowPart = currtime.LowPart;
|
||||||
newtics = currtime.LowPart - basetime.LowPart;
|
if (requested_frequency > 1000)
|
||||||
|
newtics = currtime.LowPart - basetime.LowPart * excess_frequency;
|
||||||
|
else
|
||||||
|
newtics = (currtime.LowPart - basetime.LowPart)/(1000/requested_frequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
newtics = (GetTickCount() - starttickcount) * multiplier;
|
{
|
||||||
|
if (requested_frequency > 1000)
|
||||||
|
newtics = (GetTickCount() - starttickcount) * excess_frequency;
|
||||||
|
else
|
||||||
|
newtics = (GetTickCount() - starttickcount)/(1000/requested_frequency);
|
||||||
|
}
|
||||||
|
|
||||||
return newtics;
|
return newtics;
|
||||||
}
|
}
|
||||||
|
@ -2119,8 +2126,9 @@ static void I_ShutdownTimer(void)
|
||||||
// I_GetTime
|
// I_GetTime
|
||||||
// returns time in 1/TICRATE second tics
|
// returns time in 1/TICRATE second tics
|
||||||
//
|
//
|
||||||
/*
|
|
||||||
tic_t I_GetTime (void)
|
// millisecond precision only
|
||||||
|
int TimeFunction(int requested_frequency)
|
||||||
{
|
{
|
||||||
static Uint64 basetime = 0;
|
static Uint64 basetime = 0;
|
||||||
Uint64 ticks = SDL_GetTicks();
|
Uint64 ticks = SDL_GetTicks();
|
||||||
|
@ -2130,37 +2138,22 @@ tic_t I_GetTime (void)
|
||||||
|
|
||||||
ticks -= basetime;
|
ticks -= basetime;
|
||||||
|
|
||||||
ticks = (ticks*TICRATE);
|
ticks = (ticks*requested_frequency);
|
||||||
|
|
||||||
ticks = (ticks/1000);
|
ticks = (ticks/1000);
|
||||||
|
|
||||||
return (tic_t)ticks;
|
return ticks;
|
||||||
}
|
|
||||||
*/
|
|
||||||
int TimeFunction(boolean microseconds)// this cant actually do microseconds so it fakes it
|
|
||||||
{
|
|
||||||
static Uint64 basetime = 0;
|
|
||||||
Uint64 ticks = SDL_GetTicks();
|
|
||||||
|
|
||||||
if (!basetime)
|
|
||||||
basetime = ticks;
|
|
||||||
|
|
||||||
ticks -= basetime;
|
|
||||||
|
|
||||||
return microseconds ? ticks * 1000 : ticks;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tic_t I_GetTime(void)
|
tic_t I_GetTime(void)
|
||||||
{
|
{
|
||||||
//return TimeFunction(false) / (1000/NEWTICRATE);
|
return TimeFunction(NEWTICRATE);
|
||||||
// how about this
|
|
||||||
return (TimeFunction(false) * NEWTICRATE) / 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int I_GetTimeMicros(void)
|
int I_GetTimeMicros(void)
|
||||||
{
|
{
|
||||||
return TimeFunction(true);
|
return TimeFunction(1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue