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, ...)
33 char string[MAX_INPUTLINE];
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);
44 Con_Printf ("Quake Error: %s\n", string);
50 void Sys_PrintToTerminal(const char *text)
53 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
54 int origflags = fcntl (1, F_GETFL, 0);
55 fcntl (1, F_SETFL, origflags & ~FNDELAY);
59 ssize_t written = write(1, text, strlen(text));
61 break; // sorry, I cannot do anything about this error - without an output
65 fcntl (1, F_SETFL, origflags);
67 //fprintf(stdout, "%s", text);
70 double Sys_DoubleTime (void)
72 static int first = true;
73 static double oldtime = 0.0, curtime = 0.0;
75 newtime = (double) SDL_GetTicks() / 1000.0;
84 if (newtime < oldtime)
86 // warn if it's significant
87 if (newtime - oldtime < -0.01)
88 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
91 curtime += newtime - oldtime;
97 char *Sys_ConsoleInput(void)
99 if (cls.state == ca_dedicated)
101 static char text[MAX_INPUTLINE];
132 if (len == sizeof (text))
137 struct timeval timeout;
139 FD_SET(0, &fdset); // stdin
142 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
144 len = read (0, text, sizeof(text));
147 // rip off the \n and terminate
157 void Sys_Sleep(int milliseconds)
159 if (milliseconds < 1)
161 SDL_Delay(milliseconds);
164 char *Sys_GetClipboardData (void)
170 if (OpenClipboard (NULL) != 0)
172 HANDLE hClipboardData;
174 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
176 if ((cliptext = GlobalLock (hClipboardData)) != 0)
178 data = malloc (GlobalSize(hClipboardData)+1);
179 strcpy (data, cliptext);
180 GlobalUnlock (hClipboardData);
191 void Sys_InitConsole (void)
195 void Sys_Init_Commands (void)
199 int main (int argc, char *argv[])
201 double frameoldtime, framenewtime;
203 signal(SIGFPE, SIG_IGN);
206 com_argv = (const char **)argv;
209 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
214 frameoldtime = Sys_DoubleTime () - 0.1;
217 // find time spent rendering last frame
218 framenewtime = Sys_DoubleTime ();
220 Host_Frame (framenewtime - frameoldtime);
222 frameoldtime = framenewtime;