mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
move time fetch to time_get_impl
This commit is contained in:
parent
081057d6b9
commit
e0b8ecabe4
|
@ -944,14 +944,9 @@ void set_new_tick()
|
|||
}
|
||||
|
||||
/* ----- time ----- */
|
||||
int64 time_get()
|
||||
int64 time_get_impl()
|
||||
{
|
||||
static int64 last = 0;
|
||||
if(new_tick == 0)
|
||||
return last;
|
||||
if(new_tick != -1)
|
||||
new_tick = 0;
|
||||
|
||||
{
|
||||
#if defined(CONF_PLATFORM_MACOSX)
|
||||
static int got_timebase = 0;
|
||||
|
@ -971,7 +966,7 @@ int64 time_get()
|
|||
#elif defined(CONF_FAMILY_UNIX)
|
||||
struct timespec spec;
|
||||
clock_gettime(CLOCK_MONOTONIC, &spec);
|
||||
last = (int64)spec.tv_sec*(int64)1000000+(int64)spec.tv_nsec/1000;
|
||||
last = (int64)spec.tv_sec*(int64)1000000 + (int64)spec.tv_nsec / 1000;
|
||||
return last;
|
||||
#elif defined(CONF_FAMILY_WINDOWS)
|
||||
int64 t;
|
||||
|
@ -986,6 +981,17 @@ int64 time_get()
|
|||
}
|
||||
}
|
||||
|
||||
int64 time_get()
|
||||
{
|
||||
static int64 last = 0;
|
||||
if(new_tick == 0)
|
||||
return last;
|
||||
if(new_tick != -1)
|
||||
new_tick = 0;
|
||||
|
||||
last = time_get_impl();
|
||||
}
|
||||
|
||||
int64 time_freq()
|
||||
{
|
||||
#if defined(CONF_PLATFORM_MACOSX)
|
||||
|
@ -1003,42 +1009,15 @@ int64 time_freq()
|
|||
|
||||
int64 time_get_microseconds()
|
||||
{
|
||||
static int64 last = 0;
|
||||
{
|
||||
#if defined(CONF_PLATFORM_MACOSX)
|
||||
static int got_timebase = 0;
|
||||
mach_timebase_info_data_t timebase;
|
||||
uint64_t time;
|
||||
uint64_t q;
|
||||
uint64_t r;
|
||||
if (!got_timebase)
|
||||
{
|
||||
mach_timebase_info(&timebase);
|
||||
}
|
||||
time = mach_absolute_time();
|
||||
q = time / timebase.denom;
|
||||
r = time % timebase.denom;
|
||||
last = q * timebase.numer + r * timebase.numer / timebase.denom;
|
||||
return last / (int64)1000;
|
||||
return time_get_impl() / (int64)1000;
|
||||
#elif defined(CONF_FAMILY_UNIX)
|
||||
struct timespec spec;
|
||||
clock_gettime(CLOCK_MONOTONIC, &spec);
|
||||
last = (int64)spec.tv_sec*(int64)1000000 + (int64)spec.tv_nsec / 1000;
|
||||
return last;
|
||||
return time_get_impl();
|
||||
#elif defined(CONF_FAMILY_WINDOWS)
|
||||
int64 t;
|
||||
QueryPerformanceCounter((PLARGE_INTEGER)&t);
|
||||
|
||||
int64 tf;
|
||||
QueryPerformanceFrequency((PLARGE_INTEGER)&tf);
|
||||
|
||||
t = (t * (int64)1000000) / tf;
|
||||
if(t < last) // for some reason, QPC can return values in the past
|
||||
return last;
|
||||
last = t;
|
||||
return t;
|
||||
return (time_get_impl() * (int64)1000000) / time_freq();
|
||||
#else
|
||||
#error not implemented
|
||||
#error not implemented
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -591,6 +591,18 @@ typedef unsigned long long uint64;
|
|||
|
||||
void set_new_tick();
|
||||
|
||||
/*
|
||||
Function: time_get_impl
|
||||
Fetches a sample from a high resolution timer.
|
||||
|
||||
Returns:
|
||||
Current value of the timer.
|
||||
|
||||
Remarks:
|
||||
To know how fast the timer is ticking, see <time_freq>.
|
||||
*/
|
||||
int64 time_get_impl();
|
||||
|
||||
/*
|
||||
Function: time_get
|
||||
Fetches a sample from a high resolution timer.
|
||||
|
@ -600,6 +612,7 @@ void set_new_tick();
|
|||
|
||||
Remarks:
|
||||
To know how fast the timer is ticking, see <time_freq>.
|
||||
Uses <time_get_impl> to fetch the sample.
|
||||
*/
|
||||
int64 time_get();
|
||||
|
||||
|
|
Loading…
Reference in a new issue