]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
cbuf: prepend keybind commands instead of appending to skip waits
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 25 Sep 2023 09:32:26 +0000 (19:32 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 26 Sep 2023 04:40:26 +0000 (14:40 +1000)
This prevents user inputs being delayed by `wait` commands that other
sources may have added to the buffer.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
keys.c

diff --git a/keys.c b/keys.c
index 8049bb3b993ad7b637c4143d18fa8e9a69db1ecf..9ff4853311313e4104819f30b990c603370b3f18 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1972,14 +1972,12 @@ Key_Event (int key, int ascii, qbool down)
                        {
                                // button commands add keynum as a parm
                                if (bind[0] == '+')
-                                       Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
+                                       Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
                                else
-                               {
-                                       Cbuf_AddText (cmd, bind);
-                                       Cbuf_AddText (cmd, "\n");
-                               }
-                       } else if(bind[0] == '+' && !down && keydown[key] == 0)
-                               Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
+                                       Cbuf_InsertText(cmd, bind);
+                       }
+                       else if(bind[0] == '+' && !down && keydown[key] == 0)
+                               Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
                }
                return;
        }
@@ -2010,7 +2008,7 @@ Key_Event (int key, int ascii, qbool down)
        {
                if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
                {
-                       Cbuf_AddText(cmd, "toggleconsole\n");  // Deferred to next frame so we're not sending the text event to the console.
+                       Cbuf_InsertText(cmd, "toggleconsole\n");  // Deferred to next frame so we're not sending the text event to the console.
                        tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
                        return;
                }
@@ -2053,14 +2051,12 @@ Key_Event (int key, int ascii, qbool down)
                                {
                                        // button commands add keynum as a parm
                                        if (bind[0] == '+')
-                                               Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
+                                               Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
                                        else
-                                       {
-                                               Cbuf_AddText (cmd, bind);
-                                               Cbuf_AddText (cmd, "\n");
-                                       }
-                               } else if(bind[0] == '+' && !down && keydown[key] == 0)
-                                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
+                                               Cbuf_InsertText(cmd, bind);
+                               }
+                               else if(bind[0] == '+' && !down && keydown[key] == 0)
+                                       Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
                        }
                        break;
                default: