From 8b3db052e4068ef7097af39a07dfff70ca1cac42 Mon Sep 17 00:00:00 2001 From: alexandersato0830 <66799221+alexandersato0830@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:46:10 -0600 Subject: Keep virtual gamepad mouse deltas in range --- runtime/test/gameinput_test.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index b6658f51c..c4e2491eb 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -777,6 +778,27 @@ void test_keyboard_pad_sticks(IGameInput* input, IGameInputDevice* kb) { check(rt::gameinput::config().mouse_sensitivity == 1.0f && rt::gameinput::config().ds_trigger_gain == 1.0f, "keyboard pad: mouse sensitivity defaults to 1 and leaves the trigger gain alone"); + g_cursor_x += 3'000'000; + rt::gameinput::poll(); + check(approx(pad_state(input, kb).rightThumbstickX, 1), + "keyboard pad: a positive jump beyond LONG_MAX axis units stays full right"); + g_cursor_x -= 3'000'000; + rt::gameinput::poll(); + check(approx(pad_state(input, kb).rightThumbstickX, -1), + "keyboard pad: a negative jump beyond LONG_MIN axis units stays full left"); + + const int prior_x = g_cursor_x; + g_cursor_x = std::numeric_limits::max() - 1; + rt::gameinput::poll(); + settle(); + g_cursor_x = std::numeric_limits::min() + 2; + rt::gameinput::poll(); + check(approx(pad_state(input, kb).rightThumbstickX, 4096 / 32767.0f), + "keyboard pad: the raw cursor counter wrap moves four counts right"); + g_cursor_x = prior_x; + rt::gameinput::poll(); + settle(); + g_keys[VK_RBUTTON] = true; rt::gameinput::poll(); st = pad_state(input, kb); -- cgit v1.2.3 From 9ea22eaf446b50f03d600bc2f5f1e6c4afb09788 Mon Sep 17 00:00:00 2001 From: quartz-heron-58 <245169279+quartz-heron-58@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:28:59 +0800 Subject: gameinput test: read the pad before expecting a scripted press to end (TEST-GAMEINPUT-SCRIPT-READS) Since #2098 a scripted press lasts its 300 ms and then until the title has made six GetCurrentReading calls since it began. gameinput_test --input-script still expected the press to be over after 350 ms and three reads, so ctest gameinput_script failed on main in every build with SDL3 (it is disabled without SDL3, so CI did not show it). The test now checks that the press is still held at that point, reads the pad six more times and then expects the release. Test only. Co-Authored-By: Claude Fable 5.2 --- runtime/test/gameinput_test.cpp | 9 ++++++++- 1 file changed, 8 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 b6658f51c..be9dc5398 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -1742,8 +1742,15 @@ int main(int argc, char** argv) { Sleep(350); g_focus = true; rt::gameinput::poll(); + // A scripted press lasts its 300 ms and then until the title has read the pads six times since it began + // (update_keyboard_pad: kReads, at most kMaxHold seconds), so a title that polls slowly still sees it. Each + // pad_state() is one GetCurrentReading, and this is the third since the X began. + check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB), + "long script: past its 300 ms the press is still held while the title has read the pads fewer than six times"); + for (int i = 0; i < 6; ++i) pad_state(input, nullptr); + rt::gameinput::poll(); check(pad_state(input, nullptr).buttons == GameInputGamepadB, - "long script: the timed press ends while the physical key stays held"); + "long script: the timed press ends once the title has read it, while the physical key stays held"); input->Release(); std::printf("%d checks, %d failures\n", g_checks, g_failures); return g_failures ? 1 : 0; -- cgit v1.2.3 From f0e79141a41b63e737560fbd4a051e3ab34dad7d Mon Sep 17 00:00:00 2001 From: klikso <204526810+klikso@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:32:55 +0000 Subject: gameinput: a scripted press can be held longer (button@seconds:hold) At world-start frame rates the retail title reads its pad every few seconds, so a 0.3 s scripted press falls between two reads and never arrives. An entry may now give its own hold time; without one the press stays 0.3 s. Holds of 0 or less, over 600 s or that are not a number reject the entry. Co-Authored-By: Claude Opus 5.5 --- docs/gameinput.md | 5 +++-- runtime/shims/gameinput_script.h | 27 ++++++++++++++++++--------- runtime/test/gameinput_no_sdl_test.cpp | 10 ++++++++-- runtime/test/gameinput_test.cpp | 27 +++++++++++++-------------- 4 files changed, 42 insertions(+), 27 deletions(-) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/docs/gameinput.md b/docs/gameinput.md index 1301a4a49..9b263a7aa 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md @@ -58,7 +58,8 @@ scripted pad, driven by the script alone: controller axis and controller button state. A reading is taken when the title asks for one and the script's state has changed since the last, so no thread polls; the history keeps the last 64 readings. - **The timeline:** the same as with SDL3 (`runtime/shims/gameinput_script.h` holds the parser, the timeline and the - log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms, then released. + log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms (or its own `:hold`, see + `LEONIDA_INPUT_SCRIPT` below), then released. - **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL` and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3. @@ -335,7 +336,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | -| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons and invalid times (including negative or non-finite values) are counted and ignored. | +| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to diff --git a/runtime/shims/gameinput_script.h b/runtime/shims/gameinput_script.h index 759506750..f9042a2ae 100644 --- a/runtime/shims/gameinput_script.h +++ b/runtime/shims/gameinput_script.h @@ -5,10 +5,12 @@ // // LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120" // -// Each entry is button@seconds, the seconds counted from the shim's first update. A press is held for kHoldSeconds, -// then released. Buttons: a b x y start back lb rb up down left right; rsup and rsdown throw the right stick fully up +// Each entry is button@seconds[:hold], the seconds counted from the shim's first update. A press is held for `hold` +// seconds (kHoldSeconds when the entry has none), then released: a longer hold reaches a title that reads its pad +// only every few seconds, as the retail title does at world-start frame rates. Buttons: a b x y start back lb rb up down left right; rsup and rsdown throw the right stick fully up // or down for the same time (they replay the stick throws the press log writes). Spaces around an entry are allowed; -// empty entries, unknown buttons and invalid times (negative, non-finite, trailing text) are counted as rejected. +// empty entries, unknown buttons, invalid times (negative, non-finite, trailing text) and invalid holds (zero, +// negative, non-finite, more than kMaxHoldSeconds) are counted as rejected. #pragma once #include #include @@ -24,6 +26,7 @@ namespace rt::gameinput::script { constexpr double kHoldSeconds = 0.3; +constexpr double kMaxHoldSeconds = 600; // a typo such as b@10:1100 should not hold B for the whole run // One scriptable button: its name in the script and the press log, its GameInput gamepad bit, and its SDL3 // SDL_GamepadButton number, which the "scripted press of button " line has always carried (tools/stage_timeline.py @@ -46,6 +49,7 @@ struct Press { uint32_t button = 0; // a GameInput gamepad bit, or 0 for a stick throw int stick = 0; // +1 rsup, -1 rsdown (GameInput's +Y is up) double at = 0; // seconds + double hold = kHoldSeconds; }; struct Script { @@ -72,17 +76,22 @@ inline Script parse(std::string text) { const char* time = item.c_str() + sep + 1; char* tail; const double seconds = std::strtod(time, &tail); - if (tail == time || !std::isfinite(seconds) || seconds < 0 || - item.find_first_not_of(whitespace, static_cast(tail - item.c_str())) != std::string::npos) - continue; + if (tail == time || !std::isfinite(seconds) || seconds < 0) continue; + double hold = kHoldSeconds; + if (*tail == ':') { + const char* hold_text = tail + 1; + hold = std::strtod(hold_text, &tail); + if (tail == hold_text || !std::isfinite(hold) || hold <= 0 || hold > kMaxHoldSeconds) continue; + } + if (item.find_first_not_of(whitespace, static_cast(tail - item.c_str())) != std::string::npos) continue; const auto is = [&](const char* name) { return item.compare(first, sep - first, name) == 0; }; if (is("rsup") || is("rsdown")) { - out.presses.push_back({0, is("rsup") ? 1 : -1, seconds}); + out.presses.push_back({0, is("rsup") ? 1 : -1, seconds, hold}); continue; } for (const Button& b : kButtons) { if (is(b.name)) { - out.presses.push_back({b.bit, 0, seconds}); + out.presses.push_back({b.bit, 0, seconds, hold}); out.named |= b.bit; break; } @@ -102,7 +111,7 @@ struct Held { inline Held held_at(const Script& script, double seconds) { Held h; for (const Press& p : script.presses) { - if (seconds < p.at || seconds >= p.at + kHoldSeconds) continue; + if (seconds < p.at || seconds >= p.at + p.hold) continue; if (p.stick) h.stick = p.stick; else h.buttons |= p.button; } diff --git a/runtime/test/gameinput_no_sdl_test.cpp b/runtime/test/gameinput_no_sdl_test.cpp index a131dc7c9..24a29f2a6 100644 --- a/runtime/test/gameinput_no_sdl_test.cpp +++ b/runtime/test/gameinput_no_sdl_test.cpp @@ -98,8 +98,10 @@ Pad read_at(IGameInput* input, IGameInputDevice* device, double seconds) { } int scripted_pad(CreateFn create) { - // Four presses (two overlapping A presses, Menu, a right-stick throw) and three rejected entries. - SetEnvironmentVariableA("LEONIDA_INPUT_SCRIPT", "a@1, START@2.5 ,a@1.2,rsup@4,bogus@1,a@-1,"); + // Five presses (two overlapping A presses, Menu, B held 0.8 s, a right-stick throw) and seven rejected entries + // (four of them holds that are zero, negative, missing or too long). + SetEnvironmentVariableA("LEONIDA_INPUT_SCRIPT", + "a@1, START@2.5 ,a@1.2,b@3:0.8 ,rsup@4,bogus@1,a@-1,,x@3:0,x@3:-1,x@3:,x@3:601"); rt::gameinput_no_sdl::set_clock(fake_clock); at(0); @@ -201,6 +203,10 @@ int scripted_pad(CreateFn create) { check(menu.buttons == GameInputGamepadMenu && menu.ui == GameInputUiNavigationMenu, "script: START (any case) holds Menu at 2.6 s"); check(read_at(input, device, 2.85).buttons == 0, "script: Menu is released at 2.85 s"); + check(read_at(input, device, 3.05).buttons == GameInputGamepadB, "script: b@3:0.8 holds B at 3.05 s"); + check(read_at(input, device, 3.7).buttons == GameInputGamepadB, + "script: B is still held at 3.7 s, past the 0.3 s default"); + check(read_at(input, device, 3.85).buttons == 0, "script: B is released after its 0.8 s hold"); const Pad up = read_at(input, device, 4.1); check(up.buttons == 0 && up.right_y == 1.0f && up.ui == GameInputUiNavigationScrollUp, "script: rsup throws the right stick up at 4.1 s"); diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index be9dc5398..42a59e764 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -1718,10 +1718,12 @@ int main(int argc, char** argv) { check(create(&input) == S_OK && input, "GameInputCreate returns an instance"); if (argc == 2 && std::strcmp(argv[1], "--input-script") == 0) { if (!input) return 1; - // Only the X after byte 63 is due now. Its later entry must not cancel it. + // Only the X after byte 63 and the Y held 0.6 s are due now. X's later entry must not cancel it; the + // malformed holds at the end hold nothing. set_env("LEONIDA_INPUT_SCRIPT", "start@3600,start@3600,start@3600,start@3600,start@3600,start@3600, X@0 \t,x@3600," - "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,"); + "unknown@0,a@,a@x,,a@-0.1,a@nan,a@inf,a@1e999,a@0tail, ,y@0:0.6," + "a@0:0,a@0:-1,a@0:,a@0:x,a@0:inf,a@0:601,a@0:1tail"); set_env("LEONIDA_KEYBOARD_PAD", "1"); rt::gameinput::set_keyboard_source(fake_key_down, fake_focus); rt::gameinput::set_cursor_source(fake_cursor); @@ -1730,27 +1732,24 @@ int main(int argc, char** argv) { rt::gameinput::reload_config(); rt::gameinput::poll(); const auto buttons = pad_state(input, nullptr).buttons; - const auto expected = GameInputGamepadX | GameInputGamepadB; - check((buttons & expected) == expected, "long script: the spaced X after byte 63 and the physical B are held"); + const auto expected = GameInputGamepadX | GameInputGamepadB | GameInputGamepadY; + check((buttons & expected) == expected, + "long script: the spaced X after byte 63, the held Y and the physical B are held"); check((buttons & ~expected) == 0, "malformed script entries hold no extra buttons"); g_focus = false; set_env("LEONIDA_INPUT_SCRIPT", "y@0"); rt::gameinput::reload_config(); rt::gameinput::poll(); - check(pad_state(input, nullptr).buttons == GameInputGamepadX, - "scripted X survives focus loss; reload does not replace it with Y"); + check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadY), + "scripted X and Y survive focus loss; reload does not replace the script with y@0"); Sleep(350); g_focus = true; rt::gameinput::poll(); - // A scripted press lasts its 300 ms and then until the title has read the pads six times since it began - // (update_keyboard_pad: kReads, at most kMaxHold seconds), so a title that polls slowly still sees it. Each - // pad_state() is one GetCurrentReading, and this is the third since the X began. - check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB), - "long script: past its 300 ms the press is still held while the title has read the pads fewer than six times"); - for (int i = 0; i < 6; ++i) pad_state(input, nullptr); + check(pad_state(input, nullptr).buttons == (GameInputGamepadB | GameInputGamepadY), + "long script: X's 0.3 s press ends, y@0:0.6 is still held, the physical key stays held"); + Sleep(400); rt::gameinput::poll(); - check(pad_state(input, nullptr).buttons == GameInputGamepadB, - "long script: the timed press ends once the title has read it, while the physical key stays held"); + check(pad_state(input, nullptr).buttons == GameInputGamepadB, "long script: Y is released after its 0.6 s hold"); input->Release(); std::printf("%d checks, %d failures\n", g_checks, g_failures); return g_failures ? 1 : 0; -- cgit v1.2.3 From 1ce60558c72770e881a4ef458e125f587b66022e Mon Sep 17 00:00:00 2001 From: klikso <204526810+klikso@users.noreply.github.com> Date: Thu, 26 Nov 2026 01:00:51 +0000 Subject: gameinput: the SDL keyboard pad honours a scripted hold too #2098 gave the SDL path its own loop (held 300 ms, then until the title has read the pads six times, at most 5 s), which ignored button@seconds:hold. A press now lasts its own hold, then the read latch, and never past 5 s or its hold if longer. The long-script test checks both: X kept past 300 ms until six reads, Y kept for its 0.6 s after them. It fails on the old loop. Found by AndreiKocherzhinskiiA on #1608. Co-Authored-By: Claude Opus 5.5 --- docs/gameinput.md | 2 +- runtime/README.md | 2 +- runtime/shims/gameinput.cpp | 8 +++++--- runtime/test/gameinput_test.cpp | 12 ++++++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) (limited to 'runtime/test/gameinput_test.cpp') diff --git a/docs/gameinput.md b/docs/gameinput.md index 9b263a7aa..6f39b459e 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md @@ -336,7 +336,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | -| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. | +| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to diff --git a/runtime/README.md b/runtime/README.md index 23a7811ab..033997c1a 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -353,7 +353,7 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w | `LEONIDA_POOL_DIAG_AT` | unset | *Diagnostic.* `+0x` of the title's transient-pool assert, as the trace prints it (measured locally): the trace dumps the pool's resource list when that int3 is hit (`shims/startup_trace.h`). | | `LEONIDA_PEEK` | unset | *Diagnostic.* `[:n],,...` (hex): a thread prints the 8-byte values at these RVAs of the title's image (`:n` = n consecutive values) every `LEONIDA_PEEK_SECONDS` (`src/main.cpp`). The RVAs are measured locally and not kept in the repository. `scripts/windows-boot/boot.ps1` no longer sets the game-state and session-state RVAs by default: it sets `LEONIDA_PEEK` only from `LEONIDA_GAME_STATE_RVA` and `LEONIDA_SESSION_STATE_RVA`, and without them its RESULT states read `?` ([scripts/windows-boot/README.md](../scripts/windows-boot/README.md)). | | `LEONIDA_PEEK_SECONDS` | `10` | *Diagnostic.* The period of the `LEONIDA_PEEK` thread (`src/main.cpp`), which prints 8-byte values of the title's image. | -| `LEONIDA_INPUT_SCRIPT` | unset | Timed pad presses, `button@seconds` separated by commas (`a@70,a@85,start@120`), each held 300 ms; the clock starts with the shim. Works with and without SDL3: with SDL3 it drives the keyboard pad (`LEONIDA_KEYBOARD_PAD=always`), without SDL3 one scripted pad that is the only device. Controllers and the keyboard pad still need SDL3. Format and buttons in [docs/gameinput.md](../docs/gameinput.md#environment-variables). | +| `LEONIDA_INPUT_SCRIPT` | unset | Timed pad presses, `button@seconds` separated by commas (`a@70,a@85,start@120`), each held 300 ms or its own `button@seconds:hold`; the clock starts with the shim. Works with and without SDL3: with SDL3 it drives the keyboard pad (`LEONIDA_KEYBOARD_PAD=always`), without SDL3 one scripted pad that is the only device. Controllers and the keyboard pad still need SDL3. Format and buttons in [docs/gameinput.md](../docs/gameinput.md#environment-variables). | | `LEONIDA_INPUT_LOG` | on | The GameInput shim logs every press in `LEONIDA_INPUT_SCRIPT`'s form (`name@seconds`), so a session played by hand can be replayed. `0` turns the lines off. | | `LEONIDA_LOG_ALLOCINFO` | unset | *Diagnostic.* `1` logs every device slot 25 call (`GetResourceAllocationInfo`) with its thread, description and sizes (`shims/d3d12_xs_device.cpp`). | | `LEONIDA_LOG_EXE_PIPELINES` | unset | *Diagnostic.* When set, one line per distinct graphics pipeline that uses a program translated from the executable's inline containers. | diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index fa5889d6a..3a66fd2fa 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp @@ -1887,7 +1887,9 @@ void update_keyboard_pad() { clip_cursor(active && g_raw_ready && g_cursor_pos.load() == system_cursor_pos && foreground_is_ours()); for (const auto& b : kKeyBindings) SDL_SetJoystickVirtualButton(g_keyboard.js, b.sdl_button, down[b.sdl_button]); // LEONIDA_INPUT_SCRIPT="a@70,a@85,start@120" (with LEONIDA_KEYBOARD_PAD=always): timed presses on the keyboard - // pad, in seconds since the pad's first update, each held 300 ms. For unattended boots: the title's first prompt + // pad, in seconds since the pad's first update, each held 300 ms or its own button@seconds:hold, and then until the + // title has read the pads kReads times since it began (never past kMaxHold seconds, or the hold if it is longer, so + // a title that stops reading does not keep the button). For unattended boots: the title's first prompt // waits for a button with no timeout (docs/re/notes/firstframe.md, step 5). The parser, the timeline and the // button names are gameinput_script.h's, shared with the scripted pad of a build without SDL3. namespace script = rt::gameinput::script; @@ -1911,12 +1913,12 @@ void update_keyboard_pad() { for (std::size_t i = 0; i < scripted.presses.size(); ++i) { const auto& press = scripted.presses[i]; bool active = false; - if (now >= press.at && now < press.at + kMaxHold) { + if (now >= press.at && now < press.at + std::max(press.hold, kMaxHold)) { if (!started[i]) { started[i] = 1; began[i] = calls; } - active = now < press.at + 0.3 || calls - began[i] < kReads; + active = now < press.at + press.hold || calls - began[i] < kReads; } if (!active) continue; if (press.stick) held.stick = press.stick; diff --git a/runtime/test/gameinput_test.cpp b/runtime/test/gameinput_test.cpp index 42a59e764..09d959f34 100644 --- a/runtime/test/gameinput_test.cpp +++ b/runtime/test/gameinput_test.cpp @@ -1745,11 +1745,19 @@ int main(int argc, char** argv) { Sleep(350); g_focus = true; rt::gameinput::poll(); + // A scripted press lasts its hold (300 ms, or button@seconds:hold) and then until the title has read the pads + // six times since it began (update_keyboard_pad: kReads), so a title that polls slowly still sees it. Each + // pad_state() is one GetCurrentReading, and this is the third since X and Y began. + check(pad_state(input, nullptr).buttons == (GameInputGamepadX | GameInputGamepadB | GameInputGamepadY), + "long script: past its 300 ms X is still held while the title has read the pads fewer than six times"); + for (int i = 0; i < 6; ++i) pad_state(input, nullptr); + rt::gameinput::poll(); check(pad_state(input, nullptr).buttons == (GameInputGamepadB | GameInputGamepadY), - "long script: X's 0.3 s press ends, y@0:0.6 is still held, the physical key stays held"); + "long script: X ends once the title has read it, y@0:0.6 is still held for its time, the key stays held"); Sleep(400); rt::gameinput::poll(); - check(pad_state(input, nullptr).buttons == GameInputGamepadB, "long script: Y is released after its 0.6 s hold"); + check(pad_state(input, nullptr).buttons == GameInputGamepadB, + "long script: Y is released after its 0.6 s hold, the title having read it six times"); input->Release(); std::printf("%d checks, %d failures\n", g_checks, g_failures); return g_failures ? 1 : 0; -- cgit v1.2.3