From 523bb9eeb2126f8026b3427c3d03ef2819825638 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 17 Nov 2004 16:36:07 +0000 Subject: [PATCH] minimize cpu use when framerate limited git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4769 d7cf8633-e32d-0410-b094-e92efae38249 --- host.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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; -- 2.39.2