From 1777de7aa1438b737ee71d20fb9fe6b8c32fafce Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Sun, 12 Nov 2023 22:33:10 +1000 Subject: [PATCH] Fix bug where +binds could get latched at low FPS 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 --- keys.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/keys.c b/keys.c index 9ff48533..739510ec 100644 --- 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: -- 2.39.2