]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
No more busy-waiting when framerate cap is reached (in both Linux and win versions)
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 4 May 2001 18:52:30 +0000 (18:52 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 4 May 2001 18:52:30 +0000 (18:52 +0000)
MOVETYPE_WALK on non-clients now links the edict like it should (major bugfix)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@195 d7cf8633-e32d-0410-b094-e92efae38249

host.c
sv_phys.c
sys_linux.c

diff --git a/host.c b/host.c
index 92177df244b45274d034cee4867bd66a11eb2cda..e32d0a751951dfdeac7cd593e0d912e3e94222ef 100644 (file)
--- a/host.c
+++ b/host.c
@@ -520,8 +520,9 @@ Host_FilterTime
 Returns false if the time is too short to run a frame
 ===================
 */
 Returns false if the time is too short to run a frame
 ===================
 */
-qboolean Host_FilterTime (float time)
+qboolean Host_FilterTime (double time)
 {
 {
+       double timecap;
        realtime += time;
 
        if (slowmo.value < 0.0f)
        realtime += time;
 
        if (slowmo.value < 0.0f)
@@ -531,8 +532,16 @@ qboolean Host_FilterTime (float time)
        if (host_maxfps.value < host_minfps.value)
                Cvar_SetValue("host_maxfps", host_minfps.value);
 
        if (host_maxfps.value < host_minfps.value)
                Cvar_SetValue("host_maxfps", host_minfps.value);
 
-       if ((!cls.timedemo) && ((realtime - oldrealtime) < (1.0 / host_maxfps.value)))
-               return false;           // framerate is too high
+        // check if framerate is too high
+       if (!cls.timedemo)
+       {
+               timecap = sys_ticrate.value;
+               if (cls.state == ca_connected)
+                       timecap = 1.0 / host_maxfps.value;
+
+               if ((realtime - oldrealtime) < timecap)
+                       return false;
+       }
 
        host_realframetime = host_frametime = realtime - oldrealtime; // LordHavoc: copy into host_realframetime as well
        oldrealtime = realtime;
 
        host_realframetime = host_frametime = realtime - oldrealtime; // LordHavoc: copy into host_realframetime as well
        oldrealtime = realtime;
@@ -638,7 +647,11 @@ void _Host_Frame (float time)
        
 // decide the simulation time
        if (!Host_FilterTime (time))
        
 // decide the simulation time
        if (!Host_FilterTime (time))
-               return;                 // don't run too fast, or packets will flood out
+       {
+               // if time was rejected, don't totally hog the CPU
+               Sys_Sleep();
+               return;
+       }
                
 // get new key events
        Sys_SendKeyEvents ();
                
 // get new key events
        Sys_SendKeyEvents ();
index 7c41965a1a270343654804039ba749d6f9720fec..06ed1185f8e47c97aeb2549b545c35929b843f92 100644 (file)
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -1450,6 +1450,7 @@ void SV_Physics (void)
                                        SV_AddGravity (ent);
                                SV_CheckStuck (ent);
                                SV_WalkMove (ent);
                                        SV_AddGravity (ent);
                                SV_CheckStuck (ent);
                                SV_WalkMove (ent);
+                               SV_LinkEdict (ent, true);
                        }
                        break;
                case MOVETYPE_TOSS:
                        }
                        break;
                case MOVETYPE_TOSS:
index ebf170fd3ae7be2c9761c875fe929172c609032e..4f611f98f4f41fe2290bb0f865f4c94e975a4cd7 100644 (file)
@@ -393,6 +393,11 @@ char *Sys_ConsoleInput(void)
        return NULL;
 }
 
        return NULL;
 }
 
+void Sys_Sleep(void)
+{
+       usleep(1);
+}
+
 int main (int c, char **v)
 {
 
 int main (int c, char **v)
 {