24 // =======================================================================
26 // =======================================================================
31 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
36 void Sys_Error (const char *error, ...)
41 // change stdin to non blocking
42 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
44 va_start (argptr,error);
45 vsprintf (string,error,argptr);
47 fprintf(stderr, "Error: %s\n", string);
54 void Sys_Warn (const char *warning, ...)
59 va_start (argptr,warning);
60 vsprintf (string,warning,argptr);
62 fprintf(stderr, "Warning: %s", string);
65 double Sys_DoubleTime (void)
67 static int first = true;
68 static double oldtime = 0.0, curtime = 0.0;
72 gettimeofday(&tp, NULL);
74 newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
82 if (newtime < oldtime)
84 // warn if it's significant
85 if (newtime - oldtime < -0.01)
86 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
89 curtime += newtime - oldtime;
95 // =======================================================================
96 // Sleeps for microseconds
97 // =======================================================================
99 static volatile int oktogo;
101 void alarm_handler(int x)
106 void floating_point_exception_handler(int whatever)
108 signal(SIGFPE, floating_point_exception_handler);
111 char *Sys_ConsoleInput(void)
113 static char text[256];
116 struct timeval timeout;
118 if (cls.state == ca_dedicated)
121 FD_SET(0, &fdset); // stdin
124 if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
127 len = read (0, text, sizeof(text));
130 text[len-1] = 0; // rip off the /n and terminate
142 int main (int argc, char **argv)
144 double frameoldtime, framenewtime;
146 signal(SIGFPE, SIG_IGN);
151 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
153 Sys_Shared_EarlyInit();
157 Sys_Shared_LateInit();
159 frameoldtime = Sys_DoubleTime () - 0.1;
162 // find time spent rendering last frame
163 framenewtime = Sys_DoubleTime ();
165 Host_Frame (framenewtime - frameoldtime);
167 frameoldtime = framenewtime;