upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/gameinput_test.cpp
diff options
context:
space:
mode:
authorMoonEyes <ducoinbenjamin@yahoo.fr>2026-11-28 21:18:21 +0100
committerGitHub <noreply@github.com>2026-11-28 21:18:21 +0100
commit9b7944b4e53c3cda899be3952248ab97e3f5e76f (patch)
tree70ee4c67ef61c1d0919a28f099ec9f73af21f495 /runtime/test/gameinput_test.cpp
parent90b39456a6f743fde1d02c38d53937436c787cf2 (diff)
parent045bb0fcec9ea44105ae118f8d958dc76fa1b4af (diff)
Merge pull request #1510 from ProjectLeonida/claude/gameinput-slow-reader
gameinput: report a missed press once to a slow reader (RT-GAMEINPUT-SLOW-READER)
Diffstat (limited to 'runtime/test/gameinput_test.cpp')
-rw-r--r--runtime/test/gameinput_test.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp
index 89d2537f5..ee91fd65e 100644
--- a/runtime/test/gameinput_test.cpp
+++ b/runtime/test/gameinput_test.cpp
@@ -2379,6 +2379,52 @@ int main(int argc, char** argv) {
2379 release_all(seen); 2379 release_all(seen);
2380 if (pair_ref) pair_ref->Release(); 2380 if (pair_ref) pair_ref->Release();
2381 2381
2382 // A slow reader: a press that came and went between two reads of a pad is answered once, then the real state.
2383 // Sleeps are 150 ms, three times kSlowReaderUs (50 ms), so a loaded CI machine cannot make the reader look fast.
2384 if (IGameInputReading* r = current(input, dev)) r->Release();
2385 Sleep(150);
2386 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true);
2387 rt::gameinput::poll();
2388 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false);
2389 rt::gameinput::poll();
2390 {
2391 IGameInputReading* first = current(input, dev);
2392 IGameInputReading* second = current(input, dev);
2393 check(first && second && (buttons_of(first) & GameInputGamepadX) && !(buttons_of(second) & GameInputGamepadX),
2394 "a slow reader sees a missed press once");
2395 if (first) first->Release();
2396 if (second) second->Release();
2397 }
2398
2399 // Two slow-read pads: each one's missed press comes back on its own pad only.
2400 if (IGameInputReading* r = current(input, dev)) r->Release();
2401 if (IGameInputReading* r = current(input, dsdev)) r->Release();
2402 Sleep(150);
2403 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true);
2404 rt::gameinput::poll();
2405 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false);
2406 rt::gameinput::poll();
2407 SDL_SetJoystickVirtualButton(ds.js, SDL_GAMEPAD_BUTTON_NORTH, true);
2408 rt::gameinput::poll();
2409 SDL_SetJoystickVirtualButton(ds.js, SDL_GAMEPAD_BUTTON_NORTH, false);
2410 rt::gameinput::poll();
2411 {
2412 IGameInputReading* ds_first = current(input, dsdev);
2413 IGameInputReading* x_first = current(input, dev);
2414 IGameInputReading* ds_second = current(input, dsdev);
2415 IGameInputReading* x_second = current(input, dev);
2416 check(ds_first && device_of(ds_first) == dsdev && (buttons_of(ds_first) & GameInputGamepadY) &&
2417 !(buttons_of(ds_first) & GameInputGamepadX),
2418 "two slow-read pads: the DualSense gets its own missed press, not the Xbox pad's");
2419 check(x_first && device_of(x_first) == dev && (buttons_of(x_first) & GameInputGamepadX) &&
2420 !(buttons_of(x_first) & GameInputGamepadY),
2421 "two slow-read pads: the Xbox pad gets its own missed press, not the DualSense's");
2422 check(ds_second && x_second && !(buttons_of(ds_second) & GameInputGamepadY) && !(buttons_of(x_second) & GameInputGamepadX),
2423 "two slow-read pads: each missed press comes once");
2424 for (IGameInputReading* r : {ds_first, x_first, ds_second, x_second})
2425 if (r) r->Release();
2426 }
2427
2382 // Ageing: a reading leaves the history once the reading after it is more than half a second old. 2428 // Ageing: a reading leaves the history once the reading after it is more than half a second old.
2383 IGameInputReading* aged = current(input, dev); 2429 IGameInputReading* aged = current(input, dev);
2384 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, true); 2430 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, true);
@@ -2428,6 +2474,25 @@ int main(int argc, char** argv) {
2428 check(idle && aged && fresh && idle->Release() == 0 && aged->Release() == 0 && fresh->Release() == 0, 2474 check(idle && aged && fresh && idle->Release() == 0 && aged->Release() == 0 && fresh->Release() == 0,
2429 "history: dropped readings are freed once the title releases them"); 2475 "history: dropped readings are freed once the title releases them");
2430 2476
2477 // Unplugging drops a pending missed press: the first slow read after replugging is the pad's real state.
2478 if (IGameInputReading* r = current(input, dev)) r->Release();
2479 Sleep(150);
2480 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, true);
2481 rt::gameinput::poll();
2482 SDL_SetJoystickVirtualButton(xbox2.js, SDL_GAMEPAD_BUTTON_WEST, false);
2483 rt::gameinput::poll();
2484 detach(xbox2);
2485 rt::gameinput::poll();
2486 attach(xbox2, "Leonida virtual Xbox pad", 0x045E, 0x0B12, true);
2487 rt::gameinput::poll();
2488 Sleep(150);
2489 {
2490 IGameInputReading* after = current(input, dev);
2491 check(after && device_of(after) == dev && !(buttons_of(after) & GameInputGamepadX),
2492 "close_pad drops a pending missed press: no stale press after replugging");
2493 if (after) after->Release();
2494 }
2495
2431 if (reading) reading->Release(); 2496 if (reading) reading->Release();
2432 dev->Release(); 2497 dev->Release();
2433 detach(xbox2); 2498 detach(xbox2);