]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cmd.c
win32: add two includes to make sure the constants for file mode and sharing are...
[xonotic/darkplaces.git] / cmd.c
diff --git a/cmd.c b/cmd.c
index d2d688f8c16a571320fa9b544ee6dd5180f17056..0a42ca4a093d2ad9d59882ea45e6a78d52114efc 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -176,25 +176,9 @@ static void Cmd_Centerprint_f (void)
 static sizebuf_t       cmd_text;
 static unsigned char           cmd_text_buf[CMDBUFSIZE];
 void *cmd_text_mutex = NULL;
-qboolean cmd_text_mutex_locked = false;
 
-static void Cbuf_LockThreadMutex(void)
-{
-       if (cmd_text_mutex)
-       {
-               Thread_LockMutex(cmd_text_mutex);
-               cmd_text_mutex_locked = true;
-       }
-}
-
-static void Cbuf_UnlockThreadMutex(void)
-{
-       if (cmd_text_mutex)
-       {
-               cmd_text_mutex_locked = false;
-               Thread_UnlockMutex(cmd_text_mutex);
-       }
-}
+#define Cbuf_LockThreadMutex() (cmd_text_mutex ? Thread_LockMutex(cmd_text_mutex),1 : 0)
+#define Cbuf_UnlockThreadMutex() (cmd_text_mutex ? Thread_UnlockMutex(cmd_text_mutex),1 : 0)
 
 /*
 ============
@@ -213,7 +197,7 @@ void Cbuf_AddText (const char *text)
        if (cmd_text.cursize + l >= cmd_text.maxsize)
                Con_Print("Cbuf_AddText: overflow\n");
        else
-               SZ_Write(&cmd_text, (const unsigned char *)text, (int)strlen (text));
+               SZ_Write(&cmd_text, (const unsigned char *)text, l);
        Cbuf_UnlockThreadMutex();
 }
 
@@ -229,32 +213,18 @@ FIXME: actually change the command buffer to do less copying
 */
 void Cbuf_InsertText (const char *text)
 {
-       char    *temp;
-       int             templen;
-
+       size_t l = strlen(text);
        Cbuf_LockThreadMutex();
-
-       // copy off any commands still remaining in the exec buffer
-       templen = cmd_text.cursize;
-       if (templen)
-       {
-               temp = (char *)Mem_Alloc (tempmempool, templen);
-               memcpy (temp, cmd_text.data, templen);
-               SZ_Clear (&cmd_text);
-       }
+       // we need to memmove the existing text and stuff this in before it...
+       if (cmd_text.cursize + l >= (size_t)cmd_text.maxsize)
+               Con_Print("Cbuf_InsertText: overflow\n");
        else
-               temp = NULL;
-
-       // add the entire text of the file
-       Cbuf_AddText (text);
-
-       // add the copied off data
-       if (temp != NULL)
        {
-               SZ_Write (&cmd_text, (const unsigned char *)temp, templen);
-               Mem_Free (temp);
+               // we don't have a SZ_Prepend, so...
+               memmove(cmd_text.data + l, cmd_text.data, cmd_text.cursize);
+               cmd_text.cursize += l;
+               memcpy(cmd_text.data, text, l);
        }
-
        Cbuf_UnlockThreadMutex();
 }
 
@@ -316,13 +286,9 @@ void Cbuf_Execute (void)
        qboolean quotes;
        char *comment;
 
-       SV_LockThreadMutex();
-       Cbuf_LockThreadMutex();
-
        // 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
@@ -409,9 +375,17 @@ void Cbuf_Execute (void)
                        break;
                }
        }
+}
 
-       SV_UnlockThreadMutex();
-       Cbuf_UnlockThreadMutex();
+void Cbuf_Frame(void)
+{
+       Cbuf_Execute_Deferred();
+       if (cmd_text.cursize)
+       {
+               SV_LockThreadMutex();
+               Cbuf_Execute();
+               SV_UnlockThreadMutex();
+       }
 }
 
 /*
@@ -1701,8 +1675,6 @@ void Cmd_ExecuteString (const char *text, cmd_source_t src, qboolean lockmutex)
        cmd_function_t *cmd;
        cmdalias_t *a;
 
-       if (lockmutex)
-               Cbuf_LockThreadMutex();
        oldpos = cmd_tokenizebufferpos;
        cmd_source = src;
        found = false;
@@ -1778,8 +1750,6 @@ command_found:
 
 done:
        cmd_tokenizebufferpos = oldpos;
-       if (lockmutex)
-               Cbuf_UnlockThreadMutex();
 }