windows-boot: input scripts are absolute-time, so a press lands in a different game state across runs (BOOT-INPUT-STATE-RELATIVE) #1900

Open
opened 2026-11-26 10:10:36 +00:00 by github-bot · 2 comments
Owner

@⁠BubsMcgee on GitHub · 2026-11-25 15:16 UTC · original

What

LEONIDA_INPUT_SCRIPT (-InputScript) schedules presses at absolute seconds since the keyboard pad's first update (a@45,a@60,a@75,a@90). The title reaches the same states at different times from run to run, so the same script lands presses in different game states. In A/B runs an A at 75/90 s can advance to gameplay in one build and back out to the menu (session d -> 0) in another, which changes the presents, PSO counts and even the game path being compared.

Evidence

Same 200 s boot, a@45,a@60,a@75,a@90, RTX 3080 Ti / Windows 11 / NVIDIA 616.64:

run session d session 0 presents
baseline so-statistics-on-1236 80 s never 6052
ports-only 65 s 85 s 1842
ports + #1759 80 s 100 s 2355
ports + live keys 80 s 160 s 3973

The state arrival differs by 15-20 s; the script does not.

Proposal

Add a state-relative form while keeping name@seconds:

  1. Harness side (preferred, no runtime change): boot.ps1 already parses the LEONIDA_PEEK states (0x7446510 game, low dword of 0x98f828c session; runtime/src/main.cpp prints them). Add an -InputScript form such as a@session=d+5 / a@game=3+5: the harness waits for the peek to match, then injects the key (SendInput) into the focused window with LEONIDA_KEYBOARD_PAD=1 (the focus mode from #1790).
  2. Runtime side: extend rt::gameinput::script (runtime/shims/gameinput_script.h) so a press can name a state (a@session=d+5) and update_keyboard_pad gates it on the same peek RVAs; the peek thread in runtime/src/main.cpp already reads them.

Either way the absolute form stays for compatibility.

Needs

A full test needs the retail package (the states come from the title). The parser/state matcher can be unit-tested without game files or a GPU (runtime/test/gameinput_test.cpp / a synthetic state watcher test).

Related: #1790 (focus mode; this is about timing, not the live-key leak), #1612 (first-run pad focus), scripts/windows-boot/README.md.

AI-assisted.

**@⁠BubsMcgee** on GitHub · 2026-11-25 15:16 UTC · [original](https://github.com/ubiquitarianism/leonida/issues/1900) ## What `LEONIDA_INPUT_SCRIPT` (`-InputScript`) schedules presses at **absolute seconds since the keyboard pad's first update** (`a@45,a@60,a@75,a@90`). The title reaches the same states at different times from run to run, so the same script lands presses in different game states. In A/B runs an A at 75/90 s can advance to gameplay in one build and back out to the menu (`session d -> 0`) in another, which changes the presents, PSO counts and even the game path being compared. ## Evidence Same 200 s boot, `a@45,a@60,a@75,a@90`, RTX 3080 Ti / Windows 11 / NVIDIA 616.64: | run | session `d` | session `0` | presents | |---|---|---|---| | baseline `so-statistics-on-1236` | 80 s | never | 6052 | | ports-only | 65 s | 85 s | 1842 | | ports + #1759 | 80 s | 100 s | 2355 | | ports + live keys | 80 s | 160 s | 3973 | The state arrival differs by 15-20 s; the script does not. ## Proposal Add a state-relative form while keeping `name@seconds`: 1. **Harness side (preferred, no runtime change):** `boot.ps1` already parses the `LEONIDA_PEEK` states (`0x7446510` game, low dword of `0x98f828c` session; `runtime/src/main.cpp` prints them). Add an `-InputScript` form such as `a@session=d+5` / `a@game=3+5`: the harness waits for the peek to match, then injects the key (`SendInput`) into the focused window with `LEONIDA_KEYBOARD_PAD=1` (the focus mode from #1790). 2. **Runtime side:** extend `rt::gameinput::script` (`runtime/shims/gameinput_script.h`) so a press can name a state (`a@session=d+5`) and `update_keyboard_pad` gates it on the same peek RVAs; the peek thread in `runtime/src/main.cpp` already reads them. Either way the absolute form stays for compatibility. ## Needs A full test needs the retail package (the states come from the title). The parser/state matcher can be unit-tested without game files or a GPU (`runtime/test/gameinput_test.cpp` / a synthetic state watcher test). Related: #1790 (focus mode; this is about timing, not the live-key leak), #1612 (first-run pad focus), `scripts/windows-boot/README.md`. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:10:36 +00:00
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-26 02:20 UTC · original

Data from a second machine for the design here: presses are not only landing in the wrong state, but most never reach the title at all once frames get slow. A state-relative form helps only if the press also lasts until the title reads it.

Setup: RTX 4070 SUPER, NVIDIA 621.01. A build without SDL3, so the script drives the scripted pad of runtime/shims/gameinput_no_sdl.cpp. Four 1,200 s boots of the same tree (with and without other PRs that do not touch input), a 21-press script from 150 s to 435 s, and a fresh save folder each run.

What happened: 3 of 21 presses were logged in each of the four runs, and which 3 differed:

run presses that reached the pad
A a@150, a@215, a@245
B a@150, down@265, down@285
C a@150, down@285, a@435
D a@150, a@215, down@285

All four runs went through the same states at the same times (peek: game 3 / session 3 from ~55 s, session d at 155 s, session 0 from 170 s to the end).

Why: the scripted pad takes a reading only when the title calls GetCurrentReading or GetNextReading (update(now_us()) at gameinput_no_sdl.cpp:505 and :548). held_at() (gameinput_script.h:102) holds a press only for kHoldSeconds = 0.3 from its scheduled time. So a press exists for the title only if the title polls inside that 0.3 s window. Presents per minute in the same runs:

from 0-60 s 60-180 s 180-240 s 240-300 s 300 s on
PresentX per minute ~700-900 ~2,000 ~260-310 ~65-70 0-30

From about 200 s the frame interval is several seconds. A 0.3 s window then catches a poll about one time in seven, which matches 3 of 21. (Line numbers are for main 3abb99cad. I did not check the SDL3 path on current main.) On this machine, the slow frames are the runtime's own (pipeline builds and stalls), not the title's.

Suggestion for the state-relative form: keep a press held until the title has read it at least once, or for at least N polls, as well as for 0.3 s. Otherwise a@session=d+5 still loses the press whenever the frame interval is longer than the hold. Testing the timing needs the retail package. The rule can be unit-tested on held_at() with a fake poll clock.

AI-assisted (Claude Code).

**@⁠Tyrannys** on GitHub · 2026-11-26 02:20 UTC · [original](https://github.com/ubiquitarianism/leonida/issues/1900#issuecomment-7180707841) Data from a second machine for the design here: presses are not only landing in the wrong state, but most never reach the title at all once frames get slow. A state-relative form helps only if the press also lasts until the title reads it. **Setup:** RTX 4070 SUPER, NVIDIA 621.01. A build without SDL3, so the script drives the scripted pad of `runtime/shims/gameinput_no_sdl.cpp`. Four 1,200 s boots of the same tree (with and without other PRs that do not touch input), a 21-press script from 150 s to 435 s, and a fresh save folder each run. **What happened:** 3 of 21 presses were logged in each of the four runs, and which 3 differed: | run | presses that reached the pad | |---|---| | A | a@150, a@215, a@245 | | B | a@150, down@265, down@285 | | C | a@150, down@285, a@435 | | D | a@150, a@215, down@285 | All four runs went through the same states at the same times (peek: game 3 / session 3 from ~55 s, session `d` at 155 s, session `0` from 170 s to the end). **Why:** the scripted pad takes a reading only when the title calls `GetCurrentReading` or `GetNextReading` (`update(now_us())` at `gameinput_no_sdl.cpp:505` and `:548`). `held_at()` (`gameinput_script.h:102`) holds a press only for `kHoldSeconds = 0.3` from its scheduled time. So a press exists for the title only if the title polls inside that 0.3 s window. Presents per minute in the same runs: | from | 0-60 s | 60-180 s | 180-240 s | 240-300 s | 300 s on | |---|---|---|---|---|---| | PresentX per minute | ~700-900 | ~2,000 | ~260-310 | ~65-70 | 0-30 | From about 200 s the frame interval is several seconds. A 0.3 s window then catches a poll about one time in seven, which matches 3 of 21. (Line numbers are for `main` 3abb99cad. I did not check the SDL3 path on current `main`.) On this machine, the slow frames are the runtime's own (pipeline builds and stalls), not the title's. **Suggestion for the state-relative form:** keep a press held until the title has read it at least once, or for at least N polls, as well as for 0.3 s. Otherwise `a@session=d+5` still loses the press whenever the frame interval is longer than the hold. Testing the timing needs the retail package. The rule can be unit-tested on `held_at()` with a fake poll clock. AI-assisted (Claude Code).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 23:44 UTC · original

The current shim already accepts a per-event hold that makes the missed-poll case testable without a title. I compiled the exact gameinput_script.h at d1dff7949be62b6609c3c2ca937df7f50fbf1305. With synthetic poll times 0.9, 2.3 and 3.6 s, a@1 is observed zero times and a@1:2.5 exactly once. Parser and hold logic. This extends Tyrannys's timing report on the current code.

For the state-relative patch, one useful acceptance test is to move those same polls across the state transition and verify the first eligible sparse poll still gets the input. KLBF's clock-by-world-frame version missed a one-frame event with zero polls, so changing the clock alone can leave an equivalent problem. The longer hold is a control, and could span more than one poll at higher frame rates. PortBridge · AI-assisted synthetic test report.

**@⁠akimfomin** on GitHub · 2026-11-26 23:44 UTC · [original](https://github.com/ubiquitarianism/leonida/issues/1900#issuecomment-7205804917) The current shim already accepts a per-event hold that makes the missed-poll case testable without a title. I compiled the exact `gameinput_script.h` at `d1dff7949be62b6609c3c2ca937df7f50fbf1305`. With synthetic poll times 0.9, 2.3 and 3.6 s, `a@1` is observed zero times and `a@1:2.5` exactly once. [Parser and hold logic](https://github.com/ubiquitarianism/leonida/blob/d1dff7949be62b6609c3c2ca937df7f50fbf1305/runtime/shims/gameinput_script.h#L63-L114). This extends Tyrannys's timing report on the current code. For the state-relative patch, one useful acceptance test is to move those same polls across the state transition and verify the first eligible sparse poll still gets the input. KLBF's clock-by-world-frame version [missed a one-frame event with zero polls](https://github.com/PastiiJay/klbf-lab/pull/78#issuecomment-7205556873), so changing the clock alone can leave an equivalent problem. The longer hold is a control, and could span more than one poll at higher frame rates. [PortBridge](https://github.com/akimfomin/PortBridge) · AI-assisted synthetic test report.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida#1900
No description provided.