26 char *cachedir = "/tmp";
29 // =======================================================================
31 // =======================================================================
33 void Sys_DebugNumber(int y, int val)
40 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
45 void Sys_Error (char *error, ...)
50 // change stdin to non blocking
51 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
53 va_start (argptr,error);
54 vsprintf (string,error,argptr);
56 fprintf(stderr, "Error: %s\n", string);
63 void Sys_Warn (char *warning, ...)
68 va_start (argptr,warning);
69 vsprintf (string,warning,argptr);
71 fprintf(stderr, "Warning: %s", string);
78 returns -1 if not present
81 int Sys_FileTime (char *path)
85 if (stat (path,&buf) == -1)
92 void Sys_mkdir (char *path)
97 int Sys_FileOpenRead (char *path, int *handle)
100 struct stat fileinfo;
102 h = open (path, O_RDONLY, 0666);
107 if (fstat (h,&fileinfo) == -1)
108 Sys_Error ("Error fstating %s", path);
110 return fileinfo.st_size;
113 int Sys_FileOpenWrite (char *path)
119 handle = open(path,O_RDWR | O_CREAT | O_TRUNC, 0666);
123 Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
130 int Sys_FileWrite (int handle, void *src, int count)
132 return write (handle, src, count);
135 void Sys_FileClose (int handle)
140 void Sys_FileSeek (int handle, int position)
142 lseek (handle, position, SEEK_SET);
145 int Sys_FileRead (int handle, void *dest, int count)
147 return read (handle, dest, count);
150 void Sys_DebugLog(char *file, char *fmt, ...)
153 static char data[1024];
156 va_start(argptr, fmt);
157 vsprintf(data, fmt, argptr);
159 fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
160 write(fd, data, strlen(data));
164 double Sys_DoubleTime (void)
166 static int first = true;
167 static double oldtime = 0.0, curtime = 0.0;
171 gettimeofday(&tp, NULL);
173 newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
181 if (newtime < oldtime)
183 if (newtime < oldtime - 0.001)
184 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
187 curtime += newtime - oldtime;
193 // =======================================================================
194 // Sleeps for microseconds
195 // =======================================================================
197 static volatile int oktogo;
199 void alarm_handler(int x)
204 void floating_point_exception_handler(int whatever)
206 signal(SIGFPE, floating_point_exception_handler);
209 char *Sys_ConsoleInput(void)
211 static char text[256];
214 struct timeval timeout;
216 if (cls.state == ca_dedicated)
219 FD_SET(0, &fdset); // stdin
222 if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
225 len = read (0, text, sizeof(text));
228 text[len-1] = 0; // rip off the /n and terminate
240 int main (int c, char **v)
242 double frameoldtime, framenewtime;
244 signal(SIGFPE, SIG_IGN);
246 memset(&host_parms, 0, sizeof(host_parms));
249 host_parms.argc = com_argc;
250 host_parms.argv = com_argv;
252 host_parms.basedir = basedir;
254 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
256 Sys_Shared_EarlyInit();
260 Sys_Shared_LateInit();
262 frameoldtime = Sys_DoubleTime () - 0.1;
265 // find time spent rendering last frame
266 framenewtime = Sys_DoubleTime ();
268 Host_Frame (framenewtime - frameoldtime);
270 frameoldtime = framenewtime;