16 // =======================================================================
18 // =======================================================================
20 void Sys_Shutdown (void)
23 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
30 void Sys_Error (const char *error, ...)
35 // change stdin to non blocking
37 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
40 va_start (argptr,error);
41 dpvsnprintf (string, sizeof (string), error, argptr);
43 fprintf(stderr, "Error: %s\n", string);
45 Con_Print ("Quake Error: ");
53 void Sys_PrintToTerminal(const char *text)
58 double Sys_DoubleTime (void)
60 static int first = true;
61 static double oldtime = 0.0, curtime = 0.0;
63 newtime = (double) SDL_GetTicks() / 1000.0;
72 if (newtime < oldtime)
74 // warn if it's significant
75 if (newtime - oldtime < -0.01)
76 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
79 curtime += newtime - oldtime;
85 char *Sys_ConsoleInput(void)
87 if (cls.state == ca_dedicated)
89 static char text[256];
120 if (len == sizeof (text))
125 struct timeval timeout;
127 FD_SET(0, &fdset); // stdin
130 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
132 len = read (0, text, sizeof(text));
135 // rip off the \n and terminate
145 void Sys_Sleep(int milliseconds)
147 if (milliseconds < 1)
149 SDL_Delay(milliseconds);
152 char *Sys_GetClipboardData (void)
158 if (OpenClipboard (NULL) != 0)
160 HANDLE hClipboardData;
162 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
164 if ((cliptext = GlobalLock (hClipboardData)) != 0)
166 data = malloc (GlobalSize(hClipboardData)+1);
167 strcpy (data, cliptext);
168 GlobalUnlock (hClipboardData);
179 void Sys_InitConsole (void)
183 void Sys_Init_Commands (void)
187 int main (int argc, char *argv[])
189 double frameoldtime, framenewtime;
191 signal(SIGFPE, SIG_IGN);
194 com_argv = (const char **)argv;
197 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
202 frameoldtime = Sys_DoubleTime () - 0.1;
205 // find time spent rendering last frame
206 framenewtime = Sys_DoubleTime ();
208 Host_Frame (framenewtime - frameoldtime);
210 frameoldtime = framenewtime;