17 cvar_t sys_usetimegettime = {CVAR_SAVE, "sys_usetimegettime", "1"};
20 // =======================================================================
22 // =======================================================================
24 void Sys_Shutdown (void)
27 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
34 void Sys_Error (const char *error, ...)
39 // change stdin to non blocking
41 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
44 va_start (argptr,error);
45 dpvsnprintf (string, sizeof (string), error, argptr);
47 fprintf(stderr, "Error: %s\n", string);
49 Con_Print ("Quake Error: ");
57 void Sys_PrintToTerminal(const char *text)
62 double Sys_DoubleTime (void)
64 static int first = true;
65 static double oldtime = 0.0, curtime = 0.0;
68 // LordHavoc: note to people modifying this code, DWORD is specifically defined as an unsigned 32bit number, therefore the 65536.0 * 65536.0 is fine.
69 if (!sys_usetimegettime.integer)
71 // QueryPerformanceCounter
73 // Windows 95/98/ME/NT/2000/XP
75 // very accurate (CPU cycles)
77 // does not necessarily match realtime too well (tends to get faster and faster in win98)
78 // wraps around occasionally on some platforms (depends on CPU speed and probably other unknown factors)
80 LARGE_INTEGER PerformanceFreq;
81 LARGE_INTEGER PerformanceCount;
83 if (!QueryPerformanceFrequency (&PerformanceFreq))
84 Sys_Error ("No hardware timer available");
85 QueryPerformanceCounter (&PerformanceCount);
88 timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
89 newtime = ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
91 timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
92 newtime = ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
96 newtime = (double) SDL_GetTicks() / 1000.0;
105 if (newtime < oldtime)
107 // warn if it's significant
108 if (newtime - oldtime < -0.01)
109 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
112 curtime += newtime - oldtime;
118 char *Sys_ConsoleInput(void)
120 if (cls.state == ca_dedicated)
122 static char text[256];
153 if (len == sizeof (text))
158 struct timeval timeout;
160 FD_SET(0, &fdset); // stdin
163 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
165 len = read (0, text, sizeof(text));
168 // rip off the \n and terminate
178 void Sys_Sleep(int milliseconds)
180 if (milliseconds < 1)
182 SDL_Delay(milliseconds);
185 char *Sys_GetClipboardData (void)
191 if (OpenClipboard (NULL) != 0)
193 HANDLE hClipboardData;
195 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
197 if ((cliptext = GlobalLock (hClipboardData)) != 0)
199 data = malloc (GlobalSize(hClipboardData)+1);
200 strcpy (data, cliptext);
201 GlobalUnlock (hClipboardData);
212 int main (int argc, char *argv[])
214 double frameoldtime, framenewtime;
216 signal(SIGFPE, SIG_IGN);
219 com_argv = (const char **)argv;
222 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
225 Sys_Shared_EarlyInit();
228 Cvar_RegisterVariable(&sys_usetimegettime);
233 Sys_Shared_LateInit();
235 frameoldtime = Sys_DoubleTime () - 0.1;
238 // find time spent rendering last frame
239 framenewtime = Sys_DoubleTime ();
241 Host_Frame (framenewtime - frameoldtime);
243 frameoldtime = framenewtime;