make the start calculation a little more accurate

This commit is contained in:
Bill Currie 2001-04-01 03:30:17 +00:00
parent ec16ffaa65
commit 67368ffc5d

View file

@ -172,9 +172,9 @@ Sys_Printf (const char *fmt, ...)
double double
Sys_DoubleTime (void) Sys_DoubleTime (void)
{ {
static qboolean first = true;
#ifdef _WIN32 #ifdef _WIN32
static DWORD starttime; static DWORD starttime;
static qboolean first = true;
DWORD now; DWORD now;
now = timeGetTime (); now = timeGetTime ();
@ -195,15 +195,17 @@ Sys_DoubleTime (void)
#else #else
struct timeval tp; struct timeval tp;
struct timezone tzp; struct timezone tzp;
static int secbase; double now;
static double start_time;
gettimeofday (&tp, &tzp); gettimeofday (&tp, &tzp);
now = tp.tv_sec + tp.tv_usec / 1e6;
if (!secbase) { if (first) {
secbase = tp.tv_sec; first = false;
return tp.tv_usec / 1000000.0; start_time = now;
} }
return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0; return now - start_time;
#endif #endif
} }