17 cvar_t sys_usetimegettime = {CVAR_SAVE, "sys_usetimegettime", "1"};
21 ===============================================================================
25 ===============================================================================
28 dllhandle_t Sys_LoadLibrary (const char* name)
31 return LoadLibrary (name);
33 return dlopen (name, RTLD_LAZY);
37 void Sys_UnloadLibrary (dllhandle_t handle)
46 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
49 return (void *)GetProcAddress (handle, name);
51 return (void *)dlsym (handle, name);
56 // =======================================================================
58 // =======================================================================
64 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
70 void Sys_Error (const char *error, ...)
75 // change stdin to non blocking
77 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
80 va_start (argptr,error);
81 vsprintf (string,error,argptr);
83 fprintf(stderr, "Error: %s\n", string);
89 void Sys_Print(const char *text)
94 double Sys_DoubleTime (void)
96 static int first = true;
97 static double oldtime = 0.0, curtime = 0.0;
100 // LordHavoc: note to people modifying this code, DWORD is specifically defined as an unsigned 32bit number, therefore the 65536.0 * 65536.0 is fine.
101 if (sys_usetimegettime.integer)
103 static int firsttimegettime = true;
106 // Windows 95/98/ME/NT/2000/XP
108 // reasonable accuracy (millisecond)
110 // wraps around every 47 days or so (but this is non-fatal to us, odd times are rejected, only causes a one frame stutter)
112 // make sure the timer is high precision, otherwise different versions of windows have varying accuracy
113 if (firsttimegettime)
116 firsttimegettime = false;
119 newtime = (double) timeGetTime () / 1000.0;
123 // QueryPerformanceCounter
125 // Windows 95/98/ME/NT/2000/XP
127 // very accurate (CPU cycles)
129 // does not necessarily match realtime too well (tends to get faster and faster in win98)
130 // wraps around occasionally on some platforms (depends on CPU speed and probably other unknown factors)
132 LARGE_INTEGER PerformanceFreq;
133 LARGE_INTEGER PerformanceCount;
135 if (!QueryPerformanceFrequency (&PerformanceFreq))
136 Sys_Error ("No hardware timer available");
137 QueryPerformanceCounter (&PerformanceCount);
140 timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
141 newtime = ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
143 timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
144 newtime = ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
149 gettimeofday(&tp, NULL);
150 newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
159 if (newtime < oldtime)
161 // warn if it's significant
162 if (newtime - oldtime < -0.01)
163 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
166 curtime += newtime - oldtime;
172 char *Sys_ConsoleInput(void)
174 if (cls.state == ca_dedicated)
176 static char text[256];
207 if (len == sizeof (text))
212 struct timeval timeout;
214 FD_SET(0, &fdset); // stdin
217 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
219 len = read (0, text, sizeof(text));
222 // rip off the \n and terminate
241 int main (int argc, const char **argv)
243 double frameoldtime, framenewtime;
245 signal(SIGFPE, SIG_IGN);
251 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
254 Sys_Shared_EarlyInit();
258 Sys_Shared_LateInit();
260 frameoldtime = Sys_DoubleTime () - 0.1;
263 // find time spent rendering last frame
264 framenewtime = Sys_DoubleTime ();
266 Host_Frame (framenewtime - frameoldtime);
268 frameoldtime = framenewtime;