Skip to content

gameinput: track which kind of device the player used last - #3685

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
ICUMADETHIS:feat/active-input-tracker
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
ICUMADETHIS:feat/active-input-tracker

Conversation

@ICUMADETHIS

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: new RT item, claim.

What and why

The shim tells the game every pad is an Xbox One pad, so nothing in the port could tell what the player is actually holding. This adds that: rt::gameinput::active_input() returns the family of the device used last (Xbox, PlayStation 5/4/3, Nintendo, or the keyboard pad), a generation that counts changes, and whether LEONIDA_PROMPTS forced it. It's a single atomic read, so the runtime can check it every frame. It's groundwork for button prompts that follow the device in use (PlayStation / Xbox / keyboard glyphs), and nothing reads it yet.

Only deliberate input counts:

  • A button going down (any SDL button, the DualSense touchpad included), a trigger past 0.3, or a stick leaving a 0.35 radius. Held input, stick drift and noise don't.
  • A pad's first reading after it connects is its baseline, so plugging one in with a button held, or with a worn stick, switches nothing.
  • After a change, the next one waits LEONIDA_PROMPTS_SWITCH_MS (300 ms by default), so using two devices at once can't make it flicker.
  • The mouse counts through the keyboard pad's right stick, so a count or two of jitter doesn't.

The rules live in runtime/src/active_input.h, with no SDL or Windows headers (like frame_pacer.h). The family comes from SDL_GetGamepadType, the keyboard pad counts as keyboard, and anything SDL doesn't place counts as Xbox. Each change logs one line, for example input in use: PlayStation 5 (DualSense Wireless Controller, button press). The docs are in docs/gameinput.md: an Active input section, the two env vars, and a Steam Input note under VERIFY.

Tested

Windows 11 26300, MSVC 14.44, SDL3 3.4.20 through -DLEONIDA_SDL3_FETCH=ON, on main f847748c:

  • New active_input_test (CTest, no SDL, builds with or without SDL3): 7 cases on synthetic samples. To make sure it catches mistakes, I broke four rules one at a time: no baseline, <= instead of < on the window, level instead of edge, and the stick radius ignored. Each one made it fail.

  • gameinput_test: 303 checks, 0 failures (27 of them new), on virtual DualSense, DualShock 4 and Xbox pads plus the keyboard pad. It covers:

    • connecting and letting go changing nothing;
    • each family switching by a button, the touchpad, a trigger or a stick;
    • drift and mouse jitter ignored, and a real mouse movement counted;
    • the 300 ms window on the real clock;
    • LEONIDA_PROMPTS forcing, changing, ignoring an unknown value and clearing.

    I ran it 8 times with no flakes.

  • Full ctest -j 4: 134/134 with SDL3. Without SDL3, active_input still runs and gameinput shows as disabled, as before.

  • test_ctest_registration.py and the docs checks pass. Of the other stdlib tests, only test_report_paths.py, test_build_llvm_mc_batch.py and test_build_runtime_fallback.py fail here, the same as on main.

I haven't tried it with a physical controller, since there's no pad here. gameinput_probe prints the log line if someone wants to try a real DualSense.

Overlap

This touches the same files as the open GameInput PRs #2413, #2939 and #3172. I placed the additions so it merges cleanly with #2413 and #3172. With #2939 only the include lines at the top of gameinput.h meet, a one-line resolve whichever lands second.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A: no translator change.)

🤖 Generated with Claude Code

The shim tells the title every pad is an Xbox One pad, so nothing could
say what the player is really holding. rt::gameinput::active_input()
now returns the family of the device used last (Xbox, PlayStation 5,
PlayStation 4, PlayStation 3, Nintendo, or the keyboard pad), a
generation that counts changes, and whether LEONIDA_PROMPTS forced it.
It is groundwork for button prompts that follow the device in use.

Only deliberate input counts: a button going down, a trigger past 0.3
or a stick leaving a 0.35 radius. Held input, stick drift and noise do
not; a pad's first reading after it connects is its baseline; and
after a change the next one waits LEONIDA_PROMPTS_SWITCH_MS (300 ms).
The rules live in runtime/src/active_input.h with no SDL, tested by
active_input_test; gameinput_test drives them on SDL virtual pads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 1fc162f the tracker passed 7/7, and 400 family changes plus 200 repeats advanced generation exactly 400. One test-isolation concern: attaching the fake keyboard pad starts a RIDEV_INPUTSINK listener at gameinput.cpp:1512 even with a fake cursor. Skip listener startup when the synthetic input provider is installed. Integration passed 303 checks in a private build with that guard; no physical input capture. AI-assisted Windows CPU review.

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 1fc162f on Windows 11 Home 26200, MSVC 19.44 (VS 2022), Ninja, RelWithDebInfo, SDL 3.4.20 through main's own -DLEONIDA_SDL3_FETCH=ON (the PR's CMake change only adds the active_input test; the fetch is untouched); the machine has an RTX 4090 on 621.14, which these tests do not use: pass.

The branch is on main f847748, built the same way for comparison.

main f847748 1fc162f
active_input_test.exe (new) "active input: 7 of 7 cases pass"
gameinput_test.exe 276 checks, 0 failures 303 checks, 0 failures
ctest -R "^(gameinput|active_input)$" --repeat until-fail:20 both 20/20

No compiler warnings from the gameinput or active_input files. Not run: real controllers of different families (no pad attached here; the test's SDL virtual pads cover the rules), and nothing reads active_input() yet, as the PR says. No game files. AI-assisted check (Claude Code).

@requiemsnkrp

Copy link
Copy Markdown

Tested 1fc162f4 (merged onto main f847748c) on NVIDIA GeForce RTX 3060, driver 32.0.16.1714, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0: partial pass (the SDL-dependent part was not run).

  • active_input (with LEONIDA_VK_VALIDATION=1): Passed 0.03 sec; output start and baseline: ok, drift and thresholds: ok, minimum time between changes: ok, one family, held input: ok, reconnect: ok, forced family: ok, names: ok, active input: 7 of 7 cases pass.
  • gameinput was not run: this build has no SDL3 (Not Run (Disabled), "built without SDL3"), so the shim changes in shims/gameinput.cpp and the new cases in gameinput_test.cpp are unverified here; no controller test either.
  • Full ctest (-E "present|swapchain|frame_pacer"): 100% tests passed, 0 tests failed out of 128 (8 skipped/disabled, same set as main: shader_library_corpus, bink_decode, fsr_dispatch, bvh_builder, bink_audio, gameinput, d3d12_rgb9e5_rtv, d3d12_first_light).

AI-assisted (Claude). No game files.

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested 1fc162f (merged onto main f847748) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass, partial coverage (no SDL3 here)

  • Merges cleanly; no new compiler warnings against main.
  • ctest: 132 of 132 pass (main's 131 plus active_input; same 8 skips as main). Loader test passes; validation run: 52 tests clean (2 skipped, as on main).
  • active_input -V: "7 of 7 cases pass". It builds and runs with no SDL3 installed, so active_input.h really doesn't need SDL or Windows headers.
  • Not covered: this machine has no SDL3, so configure reports "GameInput shim not built: no installed SDL3 found". gameinput.cpp and gameinput_test weren't compiled, and the 27 new gameinput_test checks and the virtual-pad switching didn't run here. Someone with SDL3 (or -DLEONIDA_SDL3_FETCH=ON) should cover that part.
  • Main has moved since (aa2988c); git merge-tree merges this head with it cleanly. I didn't rebuild on it.

AI-assisted (Claude).

@ItsNotRexed
ItsNotRexed merged commit 793e35a into ItsNotRexed:main Nov 23, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants