-/*
-===================
-Host_FilterTime
-
-Returns false if the time is too short to run a frame
-===================
-*/
-extern qboolean cl_capturevideo_active;
-extern double cl_capturevideo_framerate;
-qboolean Host_FilterTime (double time)
-{
- double timecap, timeleft;
- realtime += time;
-
- if (sys_ticrate.value < 0.01 || sys_ticrate.value > 0.10001)
- Cvar_SetValue("sys_ticrate", bound(0.01, sys_ticrate.value, 0.1));
- if (slowmo.value < 0)
- Cvar_SetValue("slowmo", 0);
- if (host_framerate.value < 0.00001 && host_framerate.value != 0)
- Cvar_SetValue("host_framerate", 0);
- if (cl_maxfps.value < 1)
- Cvar_SetValue("cl_maxfps", 1);
-
- if (cls.timedemo)
- {
- // disable time effects during timedemo
- cl.frametime = host_realframetime = host_frametime = realtime - oldrealtime;
- oldrealtime = realtime;
- return true;
- }
-
- // check if framerate is too high
- // default to sys_ticrate (server framerate - presumably low) unless we
- // have a good reason to run faster
- timecap = host_framerate.value;
- if (!timecap)
- timecap = sys_ticrate.value;
- if (cls.state != ca_dedicated)
- {
- if (cl_capturevideo_active)
- timecap = 1.0 / cl_capturevideo_framerate;
- else if (vid_activewindow)
- timecap = 1.0 / cl_maxfps.value;
- }
-
- timeleft = (oldrealtime - realtime) + timecap;
- if (timeleft > 0)
- {
- int msleft;
- // don't totally hog the CPU
- if (cls.state == ca_dedicated)
- {
- // if dedicated, try to use as little cpu as possible by waiting
- // just a little longer than necessary
- // (yes this means it doesn't quite keep up with the framerate)
- msleft = (int)ceil(timeleft * 1000);
- }
- else
- {
- // if not dedicated, try to hit exactly a steady framerate by not
- // sleeping the full amount
- msleft = (int)floor(timeleft * 1000);
- }
- if (msleft > 0)
- Sys_Sleep(msleft);
- return false;
- }
-
- // LordHavoc: copy into host_realframetime as well
- host_realframetime = host_frametime = realtime - oldrealtime;
- oldrealtime = realtime;
-
- // apply slowmo scaling
- host_frametime *= slowmo.value;
-
- // host_framerate overrides all else
- if (host_framerate.value)
- host_frametime = host_framerate.value;
-
- // never run a frame longer than 1 second
- if (host_frametime > 1)
- host_frametime = 1;
-
- cl.frametime = host_frametime;
-
- return true;
-}
-
-