]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix bug where +binds could get latched at low FPS
authorbones_was_here <bones_was_here@xonotic.au>
Sun, 12 Nov 2023 12:33:10 +0000 (22:33 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sun, 12 Nov 2023 12:33:10 +0000 (22:33 +1000)
This was introduced in 6b21c467a83808e3becf61afe7b67a88f870b502 which
didn't ensure the -bind would be executed after the +bind when the
keydown and keyup events are processed in the same frame.

Fixes https://github.com/DarkPlacesEngine/darkplaces/issues/106

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

diff --git a/keys.c b/keys.c
index 9ff4853311313e4104819f30b990c603370b3f18..739510ec34ecc4f76d77bef246a1df6bb6c93a49 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1971,13 +1971,15 @@ Key_Event (int key, int ascii, qbool down)
                        if(keydown[key] == 1 && down)
                        {
                                // button commands add keynum as a parm
+                               // prepend to avoid delays from `wait` commands added by other sources
                                if (bind[0] == '+')
                                        Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
                                else
                                        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));
+                               // append -bind to ensure it's after the +bind in case they arrive in the same frame
+                               Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
                }
                return;
        }
@@ -2050,13 +2052,15 @@ Key_Event (int key, int ascii, qbool down)
                                if(keydown[key] == 1 && down)
                                {
                                        // button commands add keynum as a parm
+                                       // prepend to avoid delays from `wait` commands added by other sources
                                        if (bind[0] == '+')
                                                Cbuf_InsertText(cmd, va(vabuf, sizeof(vabuf), "%s %i\n", bind, key));
                                        else
                                                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));
+                                       // append -bind to ensure it's after the +bind in case they arrive in the same frame
+                                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "-%s %i\n", bind + 1, key));
                        }
                        break;
                default: