From 0f5209788323fc85c6c9edddfb51bc574370699b Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Fri, 4 May 2001 18:52:30 +0000 Subject: [PATCH] No more busy-waiting when framerate cap is reached (in both Linux and win versions) 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 | 21 +++++++++++++++++---- sv_phys.c | 1 + sys_linux.c | 5 +++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/host.c b/host.c index 92177df2..e32d0a75 100644 --- a/host.c +++ b/host.c @@ -520,8 +520,9 @@ Host_FilterTime 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) @@ -531,8 +532,16 @@ qboolean Host_FilterTime (float time) 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; @@ -638,7 +647,11 @@ void _Host_Frame (float 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 (); diff --git a/sv_phys.c b/sv_phys.c index 7c41965a..06ed1185 100644 --- 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_LinkEdict (ent, true); } break; case MOVETYPE_TOSS: diff --git a/sys_linux.c b/sys_linux.c index ebf170fd..4f611f98 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -393,6 +393,11 @@ char *Sys_ConsoleInput(void) return NULL; } +void Sys_Sleep(void) +{ + usleep(1); +} + int main (int c, char **v) { -- 2.39.2