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);
90 double Sys_DoubleTime (void)
92 static int first = true;
93 static double oldtime = 0.0, curtime = 0.0;
96 // LordHavoc: note to people modifying this code, DWORD is specifically defined as an unsigned 32bit number, therefore the 65536.0 * 65536.0 is fine.
97 if (sys_usetimegettime.integer)
99 static int firsttimegettime = true;
102 // Windows 95/98/ME/NT/2000/XP
104 // reasonable accuracy (millisecond)
106 // wraps around every 47 days or so (but this is non-fatal to us, odd times are rejected, only causes a one frame stutter)
108 // make sure the timer is high precision, otherwise different versions of windows have varying accuracy
109 if (firsttimegettime)
112 firsttimegettime = false;
115 newtime = (double) timeGetTime () / 1000.0;
119 // QueryPerformanceCounter
121 // Windows 95/98/ME/NT/2000/XP
123 // very accurate (CPU cycles)
125 // does not necessarily match realtime too well (tends to get faster and faster in win98)
126 // wraps around occasionally on some platforms (depends on CPU speed and probably other unknown factors)
128 LARGE_INTEGER PerformanceFreq;
129 LARGE_INTEGER PerformanceCount;
131 if (!QueryPerformanceFrequency (&PerformanceFreq))
132 Sys_Error ("No hardware timer available");
133 QueryPerformanceCounter (&PerformanceCount);
136 timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
137 newtime = ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
139 timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
140 newtime = ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
145 gettimeofday(&tp, NULL);
146 newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
155 if (newtime < oldtime)
157 // warn if it's significant
158 if (newtime - oldtime < -0.01)
159 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
162 curtime += newtime - oldtime;
168 char *Sys_ConsoleInput(void)
170 if (cls.state == ca_dedicated)
172 static char text[256];
203 if (len == sizeof (text))
208 struct timeval timeout;
210 FD_SET(0, &fdset); // stdin
213 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
215 len = read (0, text, sizeof(text));
218 // rip off the \n and terminate
237 int main (int argc, const char **argv)
239 double frameoldtime, framenewtime;
241 signal(SIGFPE, SIG_IGN);
247 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
250 Sys_Shared_EarlyInit();
254 Sys_Shared_LateInit();
256 frameoldtime = Sys_DoubleTime () - 0.1;
259 // find time spent rendering last frame
260 framenewtime = Sys_DoubleTime ();
262 Host_Frame (framenewtime - frameoldtime);
264 frameoldtime = framenewtime;