gameinput: GetNext/PreviousReading match the reading's kind (RT-370) #39

Open
github-bot wants to merge 4 commits from github-bot/gh-39 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:05 UTC · original
ubiquitarianism:old-pr/5076 → main · +83 −9 · 3 files · 4 commits · draft

Carried over from old PR 5076 by ray3242 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/5076, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
ray3242: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claim: RT-370, https://github.com/ItsNotRexed/Leonida/issues/5032#issuecomment-7094906009 (found by tupacfan04).

Depends on: #5053

What and why

IGameInput::GetNextReading / GetPreviousReading go through find_reading in runtime/shims/gameinput.cpp, which picked the nearest reading in history by order alone. A device can advertise GameInputKindMotion or GameInputKindRawDeviceReport before its readings actually carry that kind (#5053), so a Motion/Raw query could walk onto a plain-pad reading that has no such data. #5053 fixed this for GetCurrentReading by adding reading_matches(); this PR applies the same filter to the Next/Previous history walk. No new helper — it builds on #5053's, hence the dependency.

Tests

Windows 11, MSVC 19.44 + Ninja, RelWithDebInfo; gameinput_test.exe on synthetic virtual pads — 350 checks, 0 failures (no game files, no GPU used).

Added the history-walk checks in test_motion (and tightened test_raw_hid): both traversal directions with a Motion filter, including the device-filtered backward walk, must return only Motion readings or READING_NOT_FOUND. This is a real negative control:

  • with this fix: GetPreviousReading returns GAMEINPUT_E_READING_NOT_FOUND (no earlier reading carries Motion) → PASS.

  • without the fix (reverting only gameinput.cpp and rebuilding): returns S_OK with a reading of kind 0x01040006 — no Motion bit → FAIL.

All pre-existing history tests (Next/Previous ordering, device filters, horizon, unplug/replug, aggregates) still pass. git diff --check clean.

No GPU or driver used (synthetic virtual gamepads). AI-assisted (OpenCode).

**@⁠Andretuta** on GitHub · 2026-11-24 02:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/39) `ubiquitarianism:old-pr/5076` → `main` · +83 −9 · 3 files · 4 commits · draft > Carried over from **old PR 5076** by `ray3242` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/5076`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `ray3242`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claim: RT-370, https://github.com/ItsNotRexed/Leonida/issues/5032#issuecomment-7094906009 (found by `tupacfan04`). Depends on: `#5053` ### What and why `IGameInput::GetNextReading` / `GetPreviousReading` go through `find_reading` in `runtime/shims/gameinput.cpp`, which picked the nearest reading in history by order alone. A device can advertise `GameInputKindMotion` or `GameInputKindRawDeviceReport` before its readings actually carry that kind (`#5053`), so a Motion/Raw query could walk onto a plain-pad reading that has no such data. `#5053` fixed this for `GetCurrentReading` by adding `reading_matches()`; this PR applies the same filter to the Next/Previous history walk. No new helper — it builds on `#5053`'s, hence the dependency. ### Tests Windows 11, MSVC 19.44 + Ninja, RelWithDebInfo; `gameinput_test.exe` on synthetic virtual pads — **350 checks, 0 failures** (no game files, no GPU used). Added the history-walk checks in `test_motion` (and tightened `test_raw_hid`): both traversal directions with a Motion filter, including the device-filtered backward walk, must return only Motion readings or `READING_NOT_FOUND`. This is a real negative control: - **with this fix**: `GetPreviousReading` returns `GAMEINPUT_E_READING_NOT_FOUND` (no earlier reading carries Motion) → PASS. - **without the fix** (reverting only `gameinput.cpp` and rebuilding): returns `S_OK` with a reading of kind `0x01040006` — no Motion bit → FAIL. All pre-existing history tests (Next/Previous ordering, device filters, horizon, unplug/replug, aggregates) still pass. `git diff --check` clean. **No GPU or driver used** (synthetic virtual gamepads). **AI-assisted (OpenCode).**
A device can advertise Motion before its first sample and RawDeviceReport before its first report, while its current reading carries neither. GetCurrentReading now requires the chosen reading's GetInputKind to intersect the requested kind in all three lookup branches. GameInputKindUnknown still matches anything. The docs now say when a Motion or Raw query starts answering.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:41:57 +00:00
Author
Owner

@⁠olegon85 on GitHub · 2026-11-24 08:30 UTC · original

Tested 12734e9b on Windows 11 (10.0.26100), VS 2022 BuildTools MSVC, cmake -DLEONIDA_SDL3_FETCH=ON, RelWithDebInfo: pass.

  • gameinput_test.exe: 350 checks, 0 failures, including every check this PR adds (pre-sample Motion queries with and without a device filter, the GetNext/GetPrevious history-walk controls, and the raw-report before-first-report pair).
  • Negative control: rebuilt the same test with shims/gameinput.cpp at the merge-base 561b65a8 — exactly the seven new checks fail (the five Motion-filter walks plus the two pre-first-query cases) and nothing else, so the tests pin precisely this bug.
  • Code read: reading_matches() is applied on every reading-selection path — the history walk in find_reading, the device-filtered latest pick, the no-device latest loop, and the final guard that turns an advertised-but-empty best into READING_NOT_FOUND; GameInputKindUnknown keeps its match-anything meaning. The docs changes (motion and raw-report paragraphs) describe exactly the tested behavior. Built clean under /W4 /permissive- /utf-8.

No findings. AI-assisted review.

**@⁠olegon85** on GitHub · 2026-11-24 08:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/39#issuecomment-7126228555) Tested `12734e9b` on Windows 11 (10.0.26100), VS 2022 BuildTools MSVC, `cmake -DLEONIDA_SDL3_FETCH=ON`, RelWithDebInfo: **pass**. - `gameinput_test.exe`: **350 checks, 0 failures**, including every check this PR adds (pre-sample Motion queries with and without a device filter, the GetNext/GetPrevious history-walk controls, and the raw-report before-first-report pair). - Negative control: rebuilt the same test with `shims/gameinput.cpp` at the merge-base `561b65a8` — exactly the seven new checks fail (the five Motion-filter walks plus the two pre-first-query cases) and nothing else, so the tests pin precisely this bug. - Code read: `reading_matches()` is applied on every reading-selection path — the history walk in `find_reading`, the device-filtered latest pick, the no-device latest loop, and the final guard that turns an advertised-but-empty best into READING_NOT_FOUND; `GameInputKindUnknown` keeps its match-anything meaning. The docs changes (motion and raw-report paragraphs) describe exactly the tested behavior. Built clean under `/W4 /permissive- /utf-8`. No findings. AI-assisted review.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/39/head:github-bot/gh-39'
git switch 'github-bot/gh-39'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-39'
git switch 'github-bot/gh-39'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-39'
git switch 'github-bot/gh-39'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-39'
git switch 'main'
git merge --squash 'github-bot/gh-39'
git switch 'main'
git merge --ff-only 'github-bot/gh-39'
git switch 'main'
git merge 'github-bot/gh-39'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.