Apply usleep patch, so we don't busy-wait so much. cl_maxfps will

now release your CPU :)
This commit is contained in:
Adam Olsen 2001-05-16 08:59:10 +00:00
parent 3fc2675cb8
commit d97095fe87

View file

@ -1405,13 +1405,15 @@ Host_WriteConfiguration (void)
/* /*
Host_SimulationTime Host_SimulationTime
This determines if enough time has passed to run a simulation frame This determines if enough time has passed to run a simulation frame, or
returns the amount of time that has to be waited
*/ */
static inline qboolean static inline float
Host_SimulationTime (float time) Host_SimulationTime (float time)
{ {
float fps; float fps;
float timescale = 1.0; float timescale = 1.0;
float timedifference;
if (cls.demoplayback) { if (cls.demoplayback) {
timescale = max (0, cl_demospeed->value); timescale = max (0, cl_demospeed->value);
@ -1427,9 +1429,11 @@ Host_SimulationTime (float time)
else else
fps = bound (30, rate->value / 80.0, 72); fps = bound (30, rate->value / 80.0, 72);
if (!cls.timedemo && ((realtime - oldrealtime) < (timescale / fps))) timedifference = (timescale / fps) - (realtime - oldrealtime);
return false; // framerate is too high
return true; if (!cls.timedemo && (timedifference > 0))
return timedifference; // framerate is too high
return 0;
} }
/* /*
@ -1445,13 +1449,17 @@ Host_Frame (float time)
static double time2 = 0; static double time2 = 0;
static double time3 = 0; static double time3 = 0;
int pass1, pass2, pass3; int pass1, pass2, pass3;
float sleeptime;
if (setjmp (host_abort)) // something bad happened, or the server disconnected if (setjmp (host_abort)) // something bad happened, or the server disconnected
return; return;
// decide the simulation time // decide the simulation time
if (!Host_SimulationTime (time)) if ((sleeptime = Host_SimulationTime (time)) != 0) {
if (sleeptime > 0.01) // minimum sleep time
usleep((unsigned long)((sleeptime - 0.001) * 1000000));
return; // framerate is too high return; // framerate is too high
}
host_frametime = realtime - oldrealtime; host_frametime = realtime - oldrealtime;
oldrealtime = realtime; oldrealtime = realtime;