From 045bb0fcec9ea44105ae118f8d958dc76fa1b4af Mon Sep 17 00:00:00 2001 From: QemmHD <290605352+QemmHD@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:40:06 -0500 Subject: gameinput_test: close_pad resets a missed press, pads keep their own, wider slow-reader margin Review follow-up for the kSlowReaderUs missed-press logic: - close_pad: a press missed by a slow reader, then an unplug/replug, must not come back on the first slow read after reconnecting. - two pads: a missed press on the Xbox pad and one on the DualSense are each reported only on their own pad, once. - the slow-reader sleeps are now 150 ms (3x kSlowReaderUs) for slow CI. Tested: ctest -R ^gameinput passes plain and with LEONIDA_VK_VALIDATION=1 (VS 2022, Ninja). Against the pre-fix shim the slow-reader and both two-pad checks fail (the close_pad check passes trivially there); with the fix minus close_pad's missed reset, the close_pad check fails. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf --- runtime/test/gameinput_test.cpp | 51 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index bb63e2df9..d34f0b7ce 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -2230,8 +2230,9 @@ int main(int argc, char** argv) { if (pair_ref) pair_ref->Release(); // A slow reader: a press that came and went between two reads of a pad is answered once, then the real state. + // Sleeps are 150 ms, three times kSlowReaderUs (50 ms), so a loaded CI machine cannot make the reader look fast. if (IGameInputReading* r = current(input, dev)) r->Release(); - Sleep(80); + Sleep(150); SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true); rt::gameinput::poll(); SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false); @@ -2245,6 +2246,35 @@ int main(int argc, char** argv) { if (second) second->Release(); } + // Two slow-read pads: each one's missed press comes back on its own pad only. + if (IGameInputReading* r = current(input, dev)) r->Release(); + if (IGameInputReading* r = current(input, dsdev)) r->Release(); + Sleep(150); + SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true); + rt::gameinput::poll(); + SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false); + rt::gameinput::poll(); + SDL_SetJoystickVirtualButton(ds.js, SDL_GAMEPAD_BUTTON_NORTH, true); + rt::gameinput::poll(); + SDL_SetJoystickVirtualButton(ds.js, SDL_GAMEPAD_BUTTON_NORTH, false); + rt::gameinput::poll(); + { + IGameInputReading* ds_first = current(input, dsdev); + IGameInputReading* x_first = current(input, dev); + IGameInputReading* ds_second = current(input, dsdev); + IGameInputReading* x_second = current(input, dev); + check(ds_first && device_of(ds_first) == dsdev && (buttons_of(ds_first) & GameInputGamepadY) && + !(buttons_of(ds_first) & GameInputGamepadX), + "two slow-read pads: the DualSense gets its own missed press, not the Xbox pad's"); + check(x_first && device_of(x_first) == dev && (buttons_of(x_first) & GameInputGamepadX) && + !(buttons_of(x_first) & GameInputGamepadY), + "two slow-read pads: the Xbox pad gets its own missed press, not the DualSense's"); + check(ds_second && x_second && !(buttons_of(ds_second) & GameInputGamepadY) && !(buttons_of(x_second) & GameInputGamepadX), + "two slow-read pads: each missed press comes once"); + for (IGameInputReading* r : {ds_first, x_first, ds_second, x_second}) + if (r) r->Release(); + } + // Ageing: a reading leaves the history once the reading after it is more than half a second old. IGameInputReading* aged = current(input, dev); SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, true); @@ -2294,6 +2324,25 @@ int main(int argc, char** argv) { check(idle && aged && fresh && idle->Release() == 0 && aged->Release() == 0 && fresh->Release() == 0, "history: dropped readings are freed once the title releases them"); + // Unplugging drops a pending missed press: the first slow read after replugging is the pad's real state. + if (IGameInputReading* r = current(input, dev)) r->Release(); + Sleep(150); + SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true); + rt::gameinput::poll(); + SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false); + rt::gameinput::poll(); + detach(xbox2); + rt::gameinput::poll(); + attach(xbox2, "Leonida virtual Xbox pad", 0x045E, 0x0B12, true); + rt::gameinput::poll(); + Sleep(150); + { + IGameInputReading* after = current(input, dev); + check(after && device_of(after) == dev && !(buttons_of(after) & GameInputGamepadX), + "close_pad drops a pending missed press: no stale press after replugging"); + if (after) after->Release(); + } + if (reading) reading->Release(); dev->Release(); detach(xbox2); -- cgit v1.2.3