17 cvar_t sys_usetimegettime = {CVAR_SAVE, "sys_usetimegettime", "1"};
22 // =======================================================================
24 // =======================================================================
30 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
36 void Sys_Error (const char *error, ...)
41 // change stdin to non blocking
43 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
46 va_start (argptr,error);
47 vsnprintf (string, sizeof (string), error, argptr);
49 fprintf(stderr, "Error: %s\n", string);
55 void Sys_Print(const char *text)
60 double Sys_DoubleTime (void)
62 static int first = true;
63 static double oldtime = 0.0, curtime = 0.0;
66 // LordHavoc: note to people modifying this code, DWORD is specifically defined as an unsigned 32bit number, therefore the 65536.0 * 65536.0 is fine.
67 if (sys_usetimegettime.integer)
69 static int firsttimegettime = true;
72 // Windows 95/98/ME/NT/2000/XP
74 // reasonable accuracy (millisecond)
76 // wraps around every 47 days or so (but this is non-fatal to us, odd times are rejected, only causes a one frame stutter)
78 // make sure the timer is high precision, otherwise different versions of windows have varying accuracy
82 firsttimegettime = false;
85 newtime = (double) timeGetTime () / 1000.0;
89 // QueryPerformanceCounter
91 // Windows 95/98/ME/NT/2000/XP
93 // very accurate (CPU cycles)
95 // does not necessarily match realtime too well (tends to get faster and faster in win98)
96 // wraps around occasionally on some platforms (depends on CPU speed and probably other unknown factors)
98 LARGE_INTEGER PerformanceFreq;
99 LARGE_INTEGER PerformanceCount;
101 if (!QueryPerformanceFrequency (&PerformanceFreq))
102 Sys_Error ("No hardware timer available");
103 QueryPerformanceCounter (&PerformanceCount);
106 timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
107 newtime = ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
109 timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
110 newtime = ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
115 gettimeofday(&tp, NULL);
116 newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
125 if (newtime < oldtime)
127 // warn if it's significant
128 if (newtime - oldtime < -0.01)
129 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
132 curtime += newtime - oldtime;
138 char *Sys_ConsoleInput(void)
140 if (cls.state == ca_dedicated)
142 static char text[256];
173 if (len == sizeof (text))
178 struct timeval timeout;
180 FD_SET(0, &fdset); // stdin
183 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
185 len = read (0, text, sizeof(text));
188 // rip off the \n and terminate
207 int SDL_main (int argc, char *argv[])
209 double frameoldtime, framenewtime;
211 signal(SIGFPE, SIG_IGN);
217 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
220 Sys_Shared_EarlyInit();
224 Sys_Shared_LateInit();
226 frameoldtime = Sys_DoubleTime () - 0.1;
229 // find time spent rendering last frame
230 framenewtime = Sys_DoubleTime ();
232 Host_Frame (framenewtime - frameoldtime);
234 frameoldtime = framenewtime;