]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
only lock the server mutex if executing commands
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 25 Oct 2011 10:02:57 +0000 (10:02 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 25 Oct 2011 10:02:57 +0000 (10:02 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11472 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
cmd.c
cmd.h
host.c

index 7ff8ead9a80783cf07ace98d9bf8c73f7e6df53f..334772d310e30b0c496548cea659bfb784be9765 100644 (file)
@@ -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 8efe3dc9a0e69290ebf36383366b94ed89130b1f..0a42ca4a093d2ad9d59882ea45e6a78d52114efc 100644 (file)
--- 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 826581d177259195a523f58bf842749bda98aec1..c8bf80ca4b6a1647040d8d716805c2b362b4b22d 100644 (file)
--- 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 d316fcc4e193201a6666b0e10765b4a1678e69f0..85c07db6d9d6ecfee81e26d8500f4351f1727fa0 100644 (file)
--- 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);