]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
minimize cpu use when framerate limited
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Nov 2004 16:36:07 +0000 (16:36 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Nov 2004 16:36:07 +0000 (16:36 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4769 d7cf8633-e32d-0410-b094-e92efae38249

host.c

diff --git a/host.c b/host.c
index 94d097f83f14582dc2e8af26198f9d15ecbdb4ef..953f394360a2d1ee313eed13eadbba3acf175456 100644 (file)
--- 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;