]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
if the OS returns a very bogus time (or it wrapped), warn about it and keep ticking
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 8 Jul 2002 00:12:22 +0000 (00:12 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 8 Jul 2002 00:12:22 +0000 (00:12 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2015 d7cf8633-e32d-0410-b094-e92efae38249

sys_linux.c
sys_win.c

index 297289f28778cc348c6357ed177bdfd6be4c3f8a..f006b276cd01a383f932d4686ad6202282e061f2 100644 (file)
@@ -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;
 }
index 3a65ba787833a36d3a2ec3fef062c971678d72be..cc3b58be14335697be35ca22bf60a3001a854de9 100644 (file)
--- 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 */