-double Sys_DoubleTime (void)
-{
- static int first = true;
- static double oldtime = 0.0, curtime = 0.0;
- double newtime;
- if(sys_usenoclockbutbenchmark.integer)
- {
- benchmark_time += 1;
- return ((double) benchmark_time) / 1e6;
- }
- // use higher precision timers on some platforms
-#ifndef WIN32
-# ifndef MACOSX
- if (sys_useclockgettime.integer)
- {
- struct timespec ts;
-# ifdef SUNOS
- clock_gettime(CLOCK_HIGHRES, &ts);
-# else
- clock_gettime(CLOCK_MONOTONIC, &ts);
-# endif
- newtime = (double) ts.tv_sec + ts.tv_nsec / 1000000000.0;
- }
- else if (sys_usegettimeofday.integer)
-# endif
- {
- struct timeval tp;
- gettimeofday(&tp, NULL);
- newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
- }
- else
-#endif
- {
- newtime = (double) SDL_GetTicks() / 1000.0;
- }
-
-
- if (first)
- {
- first = false;
- oldtime = newtime;
- }
-
- if (newtime < oldtime)
- {
- // warn if it's significant
- if (newtime - oldtime < -0.01)
- Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
- }
- else if (newtime > oldtime + 1800)
- {
- Con_Printf("Sys_DoubleTime: time stepped forward (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
- }
- else
- curtime += newtime - oldtime;
- oldtime = newtime;
-
- return curtime;
-}
-