From: havoc Date: Mon, 8 Jul 2002 00:12:22 +0000 (+0000) Subject: if the OS returns a very bogus time (or it wrapped), warn about it and keep ticking X-Git-Tag: RELEASE_0_2_0_RC1~444 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c3ae4b02e1563dd080afb4e5c52aedc8f90b3528;p=xonotic%2Fdarkplaces.git if the OS returns a very bogus time (or it wrapped), warn about it and keep ticking git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2015 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/sys_linux.c b/sys_linux.c index 297289f2..f006b276 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -167,11 +167,10 @@ double Sys_DoubleTime (void) static double oldtime = 0.0, curtime = 0.0; double newtime; struct timeval tp; - struct timezone tzp; - gettimeofday(&tp, &tzp); + gettimeofday(&tp, NULL); - newtime = (double) ((unsigned long) tp.tv_sec) + tp.tv_usec/1000000.0; + newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0; if (first) { @@ -180,7 +179,10 @@ double Sys_DoubleTime (void) } if (newtime < oldtime) - Con_Printf("Sys_DoubleTime: time running backwards??\n"); + { + if (newtime < oldtime - 0.001) + Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime); + } else curtime += newtime - oldtime; oldtime = newtime; @@ -237,7 +239,7 @@ void Sys_Sleep(void) int main (int c, char **v) { - double oldtime, newtime; + double frameoldtime, framenewtime; signal(SIGFPE, SIG_IGN); @@ -257,15 +259,15 @@ int main (int c, char **v) Sys_Shared_LateInit(); - oldtime = Sys_DoubleTime () - 0.1; + frameoldtime = Sys_DoubleTime () - 0.1; while (1) { // find time spent rendering last frame - newtime = Sys_DoubleTime (); + framenewtime = Sys_DoubleTime (); - Host_Frame (newtime - oldtime); + Host_Frame (framenewtime - frameoldtime); - oldtime = newtime; + frameoldtime = framenewtime; } return 0; } diff --git a/sys_win.c b/sys_win.c index 3a65ba78..cc3b58be 100644 --- a/sys_win.c +++ b/sys_win.c @@ -326,7 +326,7 @@ double Sys_DoubleTime (void) } if (newtime < oldtime) - Con_Printf("Sys_DoubleTime: time running backwards??\n"); + Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime); else curtime += newtime - oldtime; oldtime = newtime; @@ -465,7 +465,7 @@ static char *empty_string = ""; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - double oldtime, newtime; + double frameoldtime, framenewtime; MEMORYSTATUS lpBuffer; static char cwd[1024]; int t; @@ -568,7 +568,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin Sys_Shared_LateInit(); - oldtime = Sys_DoubleTime (); + frameoldtime = Sys_DoubleTime (); /* main window message loop */ while (1) @@ -585,9 +585,9 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin SleepUntilInput (NOT_FOCUS_SLEEP); } - newtime = Sys_DoubleTime (); - Host_Frame (newtime - oldtime); - oldtime = newtime; + framenewtime = Sys_DoubleTime (); + Host_Frame (framenewtime - frameoldtime); + frameoldtime = framenewtime; } /* return success of application */