27 ===============================================================================
31 ===============================================================================
34 dllhandle_t Sys_LoadLibrary (const char* name)
36 return dlopen (name, RTLD_LAZY);
39 void Sys_UnloadLibrary (dllhandle_t handle)
44 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
46 return (void *)dlsym (handle, name);
50 // =======================================================================
52 // =======================================================================
57 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
62 void Sys_Error (const char *error, ...)
67 // change stdin to non blocking
68 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
70 va_start (argptr,error);
71 vsprintf (string,error,argptr);
73 fprintf(stderr, "Error: %s\n", string);
80 void Sys_Warn (const char *warning, ...)
85 va_start (argptr,warning);
86 vsprintf (string,warning,argptr);
88 fprintf(stderr, "Warning: %s", string);
91 double Sys_DoubleTime (void)
93 static int first = true;
94 static double oldtime = 0.0, curtime = 0.0;
98 gettimeofday(&tp, NULL);
100 newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
108 if (newtime < oldtime)
110 // warn if it's significant
111 if (newtime - oldtime < -0.01)
112 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
115 curtime += newtime - oldtime;
121 // =======================================================================
122 // Sleeps for microseconds
123 // =======================================================================
125 static volatile int oktogo;
127 void alarm_handler(int x)
132 void floating_point_exception_handler(int whatever)
134 signal(SIGFPE, floating_point_exception_handler);
137 char *Sys_ConsoleInput(void)
139 static char text[256];
142 struct timeval timeout;
144 if (cls.state == ca_dedicated)
147 FD_SET(0, &fdset); // stdin
150 if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
153 len = read (0, text, sizeof(text));
156 text[len-1] = 0; // rip off the /n and terminate
168 int main (int argc, const char **argv)
170 double frameoldtime, framenewtime;
172 signal(SIGFPE, SIG_IGN);
177 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
179 Sys_Shared_EarlyInit();
183 Sys_Shared_LateInit();
185 frameoldtime = Sys_DoubleTime () - 0.1;
188 // find time spent rendering last frame
189 framenewtime = Sys_DoubleTime ();
191 Host_Frame (framenewtime - frameoldtime);
193 frameoldtime = framenewtime;