From 626fdac7f5d09deb3a56726c3621dfd4be88d04d Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 28 Sep 2024 01:00:38 +0200 Subject: [PATCH] console: fix first input sometimes being lost --- CHANGELOG.md | 1 + src/game/shell.c | 6 ------ src/specific/s_shell.c | 16 ++++++++++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aba9156a6..872e588c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - fixed toggling fullscreen not always saving (regression from 4.4) - fixed main menu music volume when exiting while underwater with certain music settings (#1540, regression from 4.4) - fixed `/kill` command unable to target a special object +- fixed really fast typing in console sometimes losing the first input (regression from 4.4) - improved object name matching in console commands to work like TR2X ## [4.4](https://github.com/LostArtefacts/TR1X/compare/4.3-102-g458cd96...4.4) - 2024-09-20 diff --git a/src/game/shell.c b/src/game/shell.c index 534f7e6b7..a98c145dc 100644 --- a/src/game/shell.c +++ b/src/game/shell.c @@ -299,12 +299,6 @@ void Shell_ExitSystemFmt(const char *fmt, ...) void Shell_ProcessInput(void) { - if (g_InputDB.enter_console) { - Console_Open(); - g_Input.any = 0; - g_InputDB.any = 0; - } - if (g_InputDB.toggle_bilinear_filter) { g_Config.rendering.texture_filter = (g_Config.rendering.texture_filter + 1) % GFX_TF_NUMBER_OF; diff --git a/src/specific/s_shell.c b/src/specific/s_shell.c index 0f47310fc..2275007ac 100644 --- a/src/specific/s_shell.c +++ b/src/specific/s_shell.c @@ -219,9 +219,21 @@ void S_Shell_SpinMessageLoop(void) } break; - case SDL_KEYDOWN: - UI_HandleKeyDown(event.key.keysym.sym); + case SDL_KEYDOWN: { + // NOTE: This normally would get handled by Input_Update, + // but by the time Input_Update gets ran, we may already have lost + // some keypresses if the player types really fast, so we need to + // react sooner. + const INPUT_SCANCODE open_console_scancode = + Input_GetAssignedScancode( + g_Config.input.layout, INPUT_ROLE_ENTER_CONSOLE); + if (event.key.keysym.scancode == open_console_scancode) { + Console_Open(); + } else { + UI_HandleKeyDown(event.key.keysym.sym); + } break; + } case SDL_TEXTEDITING: UI_HandleTextEdit(event.text.text);