]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cmd.c
sv_user: Remove commented out dead code.
[xonotic/darkplaces.git] / cmd.c
diff --git a/cmd.c b/cmd.c
index d0ef77505a872430ac6b9721444c16db46593fed..08da25ac2c4aed10fa221c14c9bdcc93f3ff1e1a 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -41,6 +41,7 @@ static cmd_iter_t cmd_iter_all[] = {
        {NULL},
 };
 
+mempool_t *cbuf_mempool;
 
 // we only run the +whatever commandline arguments once
 qbool host_stuffcmdsrun = false;
@@ -108,14 +109,19 @@ static void Cmd_Defer_f (cmd_state_t *cmd)
        {
                const char *text = Cmd_Argv(cmd, 2);
                current = Cbuf_LinkGet(cbuf, NULL);
-               current->size = strlen(text);
+               current->length = strlen(text);
                current->source = cmd;
                current->delay = atof(Cmd_Argv(cmd, 1));
 
-               memcpy(current->text, text, current->size + 1);
+               if(current->size < current->length)
+               {
+                       current->text = (char *)Mem_Realloc(cbuf_mempool, current->text, current->length + 1);
+                       current->size = current->length;
+               }
 
-               List_Move_Tail(&current->list, &cbuf->deferred);
+               strlcpy(current->text, text, current->length + 1);
 
+               List_Move_Tail(&current->list, &cbuf->deferred);
        }
        else
        {
@@ -192,7 +198,7 @@ static cmd_input_t *Cbuf_LinkGet(cmd_buf_t *cbuf, cmd_input_t *existing)
 
 static cmd_input_t *Cmd_AllocInputNode(void)
 {
-       cmd_input_t *node = (cmd_input_t *)Z_Malloc(sizeof(cmd_input_t));
+       cmd_input_t *node = (cmd_input_t *)Mem_Alloc(cbuf_mempool, sizeof(cmd_input_t));
        node->list.prev = node->list.next = &node->list;
        node->size = node->length = node->pending = 0;
        return node;
@@ -289,10 +295,10 @@ static size_t Cmd_ParseInput (cmd_input_t **output, char **input)
 
                (*output)->length += cmdsize;
 
-               if((*output)->size < (*output)->length + 1)
+               if((*output)->size < (*output)->length)
                {
-                       (*output)->text = (char *)Mem_Realloc(tempmempool, (*output)->text, (*output)->size + cmdsize + 1);
-                       (*output)->size = (*output)->length + 1;
+                       (*output)->text = (char *)Mem_Realloc(cbuf_mempool, (*output)->text, (*output)->length + 1);
+                       (*output)->size = (*output)->length;
                }
 
                strlcpy(&(*output)->text[offset], &(*input)[start], cmdsize + 1);
@@ -381,7 +387,7 @@ void Cbuf_InsertText (cmd_state_t *cmd, const char *text)
        Cbuf_Lock(cbuf);
 
        // we need to memmove the existing text and stuff this in before it...
-       if (cbuf->size + l >= (size_t)cbuf->maxsize)
+       if (cbuf->size + l >= cbuf->maxsize)
                Con_Print("Cbuf_InsertText: overflow\n");
        else
        {
@@ -417,7 +423,7 @@ static void Cbuf_Execute_Deferred (cmd_buf_t *cbuf)
                current->delay -= eat;
                if(current->delay <= 0)
                {
-                       cbuf->size += current->size;
+                       cbuf->size += current->length;
                        List_Move(pos, &cbuf->start);
                        // We must return and come back next frame or the engine will freeze. Fragile... like glass :3
                        return;
@@ -448,7 +454,10 @@ void Cbuf_Execute (cmd_buf_t *cbuf)
                 * can insert data at the beginning of the text buffer
                 */
                current = List_Container(*cbuf->start.next, cmd_input_t, list);
-
+               
+               // Recycle memory so using WASD doesn't cause a malloc and free
+               List_Move_Tail(&current->list, &cbuf->free);
+               
                /*
                 * Assume we're rolling with the current command-line and
                 * always set this false because alias expansion or cbuf insertion
@@ -473,9 +482,6 @@ void Cbuf_Execute (cmd_buf_t *cbuf)
                        Cmd_ExecuteString (current->source, current->text, src_local, false);
                }
 
-               // Recycle memory so using WASD doesn't cause a malloc and free
-               List_Move_Tail(&current->list, &cbuf->free);
-
                current = NULL;
 
                if (cbuf->wait)
@@ -1604,7 +1610,9 @@ Cmd_Init
 void Cmd_Init(void)
 {
        cmd_iter_t *cmd_iter;
-       cmd_buf_t *cbuf = (cmd_buf_t *)Z_Malloc(sizeof(cmd_buf_t));
+       cmd_buf_t *cbuf;
+       cbuf_mempool = Mem_AllocPool("Command buffer", 0, NULL);
+       cbuf = (cmd_buf_t *)Mem_Alloc(cbuf_mempool, sizeof(cmd_buf_t));
        cbuf->maxsize = 655360;
        cbuf->lock = Thread_CreateMutex();
        cbuf->wait = false;