gameinput: keyboard pad input scripts of any length (RT-INPUT-SCRIPT-LENGTH) #1074
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1074
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1074/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Moriz82 on GitHub · 2026-11-24 17:52 UTC · original
split/rt-input-script-length→main· +115 −11 · 4 files · 1 commits · merged 2026-11-24 20:44 UTCClaimed in the coordination issue as: RT-INPUT-SCRIPT-LENGTH (claim).
Part of the split of #984 into small pull requests.
Depends on: none
Overlaps: #984 contains the integration. #955 changes physical
right-stick keys and controller hotplug in the same shim.
What and why
Main had no scheduler for keyboard pad input scripts. This change reads
LEONIDA_INPUT_SCRIPTand schedules comma-separatedbutton@secondsentries. The shared environment reader now reads every
LEONIDA_*setting used by this shim at full length. Previously, values of 64
characters or more read as unset.
The first keyboard pad update reads the script and starts its clock.
Each scheduled press lasts 300 ms and works with or without focus. A
physical key or another active scheduled press can keep a button held.
reload_config()leaves the startup script in effect.Spaces around an entry are allowed. Empty entries, unknown buttons and
missing, malformed, negative or non-finite times are ignored. The shim
logs the accepted and rejected counts for each nonempty script. Leave
the variable unset to disable scheduling.
Tested
Release cross-build with clang-cl 23.1.5 and an xwin SDK on CachyOS,
kernel 7.3.5. The tests used Proton Experimental (Wine 11), a Ryzen 5
5600X, 16 GB RAM and SDL virtual joysticks. The host had an RTX 4070
12 GB with NVIDIA 620.73.04. CMake omitted the optional XMA2 decoder
because the Rust Windows target was unavailable.
The 135-byte fixture places X at byte offset 67, padded with whitespace,
and schedules X again later. It supplies an unknown button, missing and
invalid times, empty items and a whitespace-only item. Physical B and
scripted X are held on the first reading. After losing focus and
reloading with a different script, only X is held. Once the original
press expires and focus returns, only B is held.
The default run passed 364/364 checks. The focused run passed 10/10 and
reported eight scheduled entries and eleven rejected entries.
Both controls used the same test object and link settings. For the
reader control, restore only
env()from the commit's parent. For theparser control, restore only the pre-review parsing loop with its
unchecked time conversion. Run each control with
--input-script.Each fraction counts passing checks. Only the child ran the default
suite. The old parser counted 14 entries as valid.
Both
gameinputandgameinput_scriptappeared disabled without SDL3and enabled again after restoring SDL3. The documentation suite passed
4/4 tests. The semantic suite passed 6,168 tests in 470 files. The
content and whitespace checks passed.
A contributor tested the pre-review scheduler on native Windows 11.
All 14/14 runs passed at lengths from 63 to 4,096 bytes. With only the
old reader restored, both 63-byte runs passed and all 12/12 longer runs
missed the scheduled presses. Native Windows has not been rerun on this
revision. AMD, Intel, a physical controller and a game boot were not
tested on this revision.
GPUs tested: none. The GameInput tests use synthetic input.
AI-assisted: yes
Checklist
bd8d72bb2, verified to merge cleanly into955d9be34.🤖 Generated with Claude Code
@sodove on GitHub · 2026-11-24 18:02 UTC · original
Confirmed on native Windows 11 (26100.7623) at
5e86f4a3, using MSVC 19.44, RelWithDebInfo and the pinned SDL3. Both the final scripted X press and its release reachedIGameInput::GetCurrentReading.I held B through the test keyboard source, scheduled X once at startup and again as the last entry at 0.70 s, and sampled the virtual pad through both press windows. At script lengths of 63, 64, 65, 69, 70, 76 and 4,096 ASCII bytes, GameInput reported
B+X → B → B+X → Bevery time (14/14 runs, two per length). The final X was visible for 294–311 ms. In the longest case its entry started at byte offset 4,090. Releasing the held key afterward cleared B as well.For a control I kept the same probe, scheduler and libraries and restored only the parent commit’s 64-byte environment reader. Both 63-byte runs still saw both X presses. At every tested length from 64 bytes up, only B was visible (12/12 control runs). The unmodified PR tests also passed here:
gameinput364/364 andgameinput_script8/8.SDL virtual pad and synthetic keyboard input only. No game files or GPU needed. AI-assisted: yes (OpenAI Codex).
@kawaii-shakal on GitHub · 2026-11-24 18:11 UTC · original
Review of #1074, "gameinput: read full-length keyboard pad scripts (RT-INPUT-SCRIPT-LENGTH)"
Head: 5e86f4a3f21793a798ed460b59c0c2eed6f7a72b (one commit on
bd8d72bb2). Claim on #14 (comment 7139824543, Moriz82) matches the change.Environment: Windows 11 Pro 26300, MSVC 19.50 (VS 18 Build Tools), CMake with the "Visual Studio 18 2026" generator. No SDL3 is installed on this machine and none is on the drive, so
gameinput_testcannot be built here. I did not download SDL3. No GPU was used.What I ran
git merge-tree --write-tree origin/main HEADagainst origin/main3aa975421: clean (tree 96d20b5e3).git diff --check origin/main...HEAD: clean.cmake -S runtime -B runtime/build -G "Visual Studio 18 2026" -DBUILD_TESTING=ONin the PR worktree: "GameInput shim not built: no installed SDL3 found".ctest -N -R gameinputlists onlygameinput_hostandgameinput (Disabled). The newgameinput_scripttest is not registered, which is expected without SDL3.python -I tests/test_docs_env_vars.py: 4 tests, OK.gameinput_testitself: not built or run. It needs SDL3. Because of that I could not run it on the merge base, and I could not do the mutation inside the real target. On the merge base the--input-scriptmode does not exist at all:main()ignores argv and the shim has no scheduler. So the new test would fail there because the feature is missing, not only because of the length limit.cl /std:c++20 /EHsc /W4 /DNOMINMAX. It holds a verbatim copy of the newenv(), the old 64-byteenv()(under-DOLD), and the script parser lambda, with the SDL enums replaced by ints. Results:env(): the PR's 76-character test script gives 8 entries. A 65-character value gives 1 entry. A 32,000-character value (8,000 entries) parses fully. An empty value and a value with no@give 0 entries. 0 failures.env()(the mutation): the 76-, 65- and 32,000-character values all read as unset and give 0 entries. 3 failures. So reintroducing the old limit makes the length cases fail, as the PR's control run also reports (7/8 under Wine).Findings
GetEnvironmentVariableApattern: first the size including the terminator, then a read intostd::string(need), thenn >= needis rejected and the string is resized ton. Nothing overflows. The allocation is bounded by the Windows limit of 32,767 characters per variable, so this adds no unbounded allocation. An empty but set variable gives need = 1 and n = 0, so it reads as unset, as before. A value that grows between the two calls also reads as unset. That race is harmless and the old code had the same outcome.env()change affects everyLEONIDA_*setting the shim reads, not only the script (gameinput.cpp:150-192). A value of 64 characters or more used to read as unset and is now parsed. All those parsers already accept arbitrary strings, so I see no risk. It is a behaviour change worth one line in the description.LEONIDA_INPUT_SCRIPTat all (git grep INPUT_SCRIPT origin/mainis empty). This PR adds the whole scheduler: parser, 300 ms presses, per-button OR with physical keys, and stderr logging (gameinput.cpp:1898-1946). The body says this, but the title could say "add keyboard pad input script" so the change log is accurate.zz@1and@2are dropped. Leading spaces are also dropped:" a@1"is ignored, while the docs example has no spaces. The time is parsed withstd::atofwith no check, soa@,a@xanda@abcall schedule a press at 0 s.a@1@2gives a press at 1 s,a@-1never fires,a@nannever fires anda@1e999(inf) never fires. None of this is unsafe: everything is bounds-checked, andpress.buttonis always one of the 12 table values, sonamed[]andscripted[]cannot be indexed out of range. But a typo likea@producing a press at start-up is surprising. Suggestion: usestrtodwith an end-pointer check, skip entries with a non-finite or negative time, and optionally log the count of rejected entries next to the existing "N scripted press(es)" line.,,). One extra entry such aszz@0,a@,that asserts nothing extra is held would pin the parser behaviour. That check would currently fail fora@, because of finding 4.LEONIDA_KEYBOARD_PAD=1and the window unfocused,down[]is all false, but the scripted buttons are still pressed. The comment at 1869 says out of focus "every button ... is released". For unattended runs this is probably what is wanted. The docs row should say so, or the code should gate onactive.reload_config()does not re-read it. The docs row says "set before starting", which is consistent, but "read once at start-up" would be clearer, since other rows in that table are re-read byreload_config. The test works around this by using a separate process mode.gameinput_scriptis added only insideif(WIN32 AND TARGET gameinput_test). Builds without SDL3 are unchanged: they still list onegameinput (Disabled)placeholder, which I confirmed above. A matching disabledgameinput_scriptplaceholder would make the skipped test visible, but that is optional.Sleep(350)against a 300 ms window.GetTickCount64resolution is about 16 ms, so the margin is enough.Verdict: the length fix is correct and bounded, the merge is clean, and the docs table row is present and passes the docs test. I could not run the real test here (no SDL3). The standalone harness confirms the new reader handles long values, and that the old reader drops them. I would approve after the title or description reflects that this adds the scheduler. Rejecting malformed times (finding 4) plus a malformed-input test case (finding 5) are recommended but not blocking. Findings 6 and 7 are doc clarifications.
AI-assisted.
@abnalstlll-byte on GitHub · 2026-11-24 18:50 UTC · original · approved these changes
Reviewed and verified. Resolves truncation of LEONIDA_INPUT_SCRIPT environment variables exceeding 64 characters by querying actual length dynamically from the OS. Successfully schedules multi-stage button sequences with 300ms press duration. Validated with focused test cases in gameinput_test.cpp and docs/env_vars. 100% clean-room.
@Moriz82 on GitHub · 2026-11-24 18:57 UTC · original
Thank you for testing the script on native Windows. The 14/14 passing
runs and the 12/12 old-reader failures at longer lengths confirm the
boundary independently. Thank you also for reviewing the parser and
checking the build without SDL3.
for every GameInput environment setting.
main, along with the full-length reader.
strtod, checks the end pointer and accepts onlyfinite, nonnegative times. It trims whitespace around items and logs
how many it accepted and rejected.
and malformed times, non-finite and negative times, and a valid entry
with padding. It checks the exact buttons held.
scripted presses. The focused test checks that only X survives focus
loss while the physical B key is still down.
The test checks that the original schedule survives an environment
change and a call to
reload_config().On the amended branch, the default run passed 364/364 and the focused
run passed 10/10, with 8 entries accepted and 11 rejected. Restoring
only the old reader gave 8/10. Both failures were the missing scripted X
before and after focus loss. Restoring only the old parser gave 7/10. It
missed the padded X and scheduled A from invalid entries. Both controls
exited 1. The documentation tests passed 4/4.
🤖 Generated with Claude Code
@QemmHD on GitHub · 2026-11-24 20:44 UTC · original
Merging.
Why merged: RT-INPUT-SCRIPT-LENGTH: the shim's env() reader now handles values of any length (64 characters or more used to read as unset). The PR also adds the LEONIDA_INPUT_SCRIPT keyboard-pad scheduler (
button@seconds, 300 ms presses), documented in docs/gameinput.md. That's a second topic, but the body says so, and both parts were reviewed. sodove checked 14/14 runs across lengths, with the control failing 12/12, and kawaii-shakal's harness follow-ups were addressed.Why it's good: gameinput_host, gameinput and the new gameinput_script pass; with validation, gameinput_script passes and logs "8 accepted / 11 rejected". The parsing is bounded (strtod with end-pointer and finiteness checks) and reads only its own env var.
Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #517, #907, #927, #954 and #1074 merged onto main
32a5d9698(after aslan2142's runtime merges). There the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The 2 failures are d3d12_depth_resolve (pre-existing) and d3d12_close_parity, which fails on plain32a5d9698too: a regression from #510, reported there, not from these PRs. git merge-tree against current main: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.AI-assisted (Claude Code, Claude Opus 5.5).