From: havoc Date: Wed, 17 Nov 2004 16:36:07 +0000 (+0000) Subject: minimize cpu use when framerate limited X-Git-Tag: xonotic-v0.1.0preview~5366 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=523bb9eeb2126f8026b3427c3d03ef2819825638;p=xonotic%2Fdarkplaces.git minimize cpu use when framerate limited git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4769 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/host.c b/host.c index 94d097f8..953f3943 100644 --- a/host.c +++ b/host.c @@ -597,12 +597,21 @@ qboolean Host_FilterTime (double time) timeleft = (oldrealtime - realtime) + timecap; if (timeleft > 0) { + int msleft; // don't totally hog the CPU - int msleft = (int)(timeleft * 1000); - // if not dedicated, try to hit exactly a steady framerate by by not - // sleeping the full amount - if (cls.state != ca_dedicated) - msleft -= 1; + 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;