From e5595431646c5b6f634a5a43b7cdd004e2b03bdb Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 25 Oct 2011 10:02:57 +0000 Subject: [PATCH] only lock the server mutex if executing commands git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11472 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_parse.c | 31 +++++++++++++++++++------------ cmd.c | 12 +++++++++++- cmd.h | 2 ++ host.c | 4 +--- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/cl_parse.c b/cl_parse.c index 7ff8ead9..334772d3 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -303,13 +303,12 @@ so the server doesn't disconnect. static unsigned char olddata[NET_MAXMESSAGE]; void CL_KeepaliveMessage (qboolean readmessages) { + static double lastdirtytime = 0; static qboolean recursive = false; - double time; - static double nextmsg = -1; - static double nextupdate = -1; -#if 0 - static double lasttime = -1; -#endif + double dirtytime; + double deltatime; + static double countdownmsg = 0; + static double countdownupdate = 0; sizebuf_t old; qboolean thisrecursive; @@ -317,21 +316,29 @@ void CL_KeepaliveMessage (qboolean readmessages) thisrecursive = recursive; recursive = true; - time = Sys_DirtyTime(); + dirtytime = Sys_DirtyTime(); + deltatime = dirtytime - lastdirtytime; + lastdirtytime = dirtytime; + if (deltatime <= 0 || deltatime >= 1800.0) + return; + + countdownmsg -= deltatime; + countdownupdate -= deltatime; + if(!thisrecursive) { if(cls.state != ca_dedicated) { - if(time >= nextupdate || time < nextupdate) // check if time stepped backwards + if(countdownupdate <= 0) // check if time stepped backwards { SCR_UpdateLoadingScreenIfShown(); - nextupdate = time + 2; + countdownupdate = 2; } } } // no need if server is local and definitely not if this is a demo - if (!cls.netcon || cls.protocol == PROTOCOL_QUAKEWORLD || cls.signon >= SIGNONS) + if (sv.active || !cls.netcon || cls.protocol == PROTOCOL_QUAKEWORLD || cls.signon >= SIGNONS) { recursive = thisrecursive; return; @@ -349,11 +356,11 @@ void CL_KeepaliveMessage (qboolean readmessages) memcpy(cl_message.data, olddata, cl_message.cursize); } - if (cls.netcon && (time >= nextmsg || time < nextmsg)) // check if time stepped backwards + if (cls.netcon && countdownmsg <= 0) // check if time stepped backwards { sizebuf_t msg; unsigned char buf[4]; - nextmsg = time + 5; + countdownmsg = 5; // write out a nop // LordHavoc: must use unreliable because reliable could kill the sigon message! Con_Print("--> client to server keepalive\n"); diff --git a/cmd.c b/cmd.c index 8efe3dc9..0a42ca4a 100644 --- a/cmd.c +++ b/cmd.c @@ -289,7 +289,6 @@ void Cbuf_Execute (void) // LordHavoc: making sure the tokenizebuffer doesn't get filled up by repeated crashes cmd_tokenizebufferpos = 0; - Cbuf_Execute_Deferred(); while (cmd_text.cursize) { // find a \n or ; line break @@ -378,6 +377,17 @@ void Cbuf_Execute (void) } } +void Cbuf_Frame(void) +{ + Cbuf_Execute_Deferred(); + if (cmd_text.cursize) + { + SV_LockThreadMutex(); + Cbuf_Execute(); + SV_UnlockThreadMutex(); + } +} + /* ============================================================================== diff --git a/cmd.h b/cmd.h index 826581d1..c8bf80ca 100644 --- a/cmd.h +++ b/cmd.h @@ -61,6 +61,8 @@ void Cbuf_InsertText (const char *text); * \note Do not call inside a command function! */ void Cbuf_Execute (void); +/*! Performs deferred commands and runs Cbuf_Execute, called by Host_Main */ +void Cbuf_Frame (void); //=========================================================================== diff --git a/host.c b/host.c index d316fcc4..85c07db6 100644 --- a/host.c +++ b/host.c @@ -755,13 +755,11 @@ void Host_Main(void) // otherwise we execute them on client frames if (sv.active ? sv_timer > 0 : cl_timer > 0) { - SV_LockThreadMutex(); // process console commands // R_TimeReport("preconsole"); CL_VM_PreventInformationLeaks(); - Cbuf_Execute(); + Cbuf_Frame(); // R_TimeReport("console"); - SV_UnlockThreadMutex(); } //Con_Printf("%6.0f %6.0f\n", cl_timer * 1000000.0, sv_timer * 1000000.0); -- 2.39.2