Skip to content

GameInput: accept zero-valued motion samples after both sensors report (RT-348) - #4967

Open
Brandon-C-Wheeler wants to merge 1 commit into
ItsNotRexed:mainfrom
Brandon-C-Wheeler:fix/gameinput-zero-motion
Open

Brandon-C-Wheeler wants to merge 1 commit into
ItsNotRexed:mainfrom
Brandon-C-Wheeler:fix/gameinput-zero-motion

Conversation

@Brandon-C-Wheeler

Copy link
Copy Markdown

Claimed as RT-348. Related to #660.

What and why

SDL's sensor cache starts at zero. The GameInput shim used a nonzero accelerometer axis as evidence that the sensors were ready. This discarded a valid gyroscope reading at zero acceleration and exposed motion early if only the accelerometer had reported.

The shim now observes the first accelerometer and gyroscope update for each connected controller. Once every motion-capable pad has supplied both, it disables sensor events and continues polling SDL's cached values at the existing cadence. Reconnecting a pad starts it with fresh readiness even when GameInput reuses its device object.

Tested

  • Built the Windows x64 Release runtime with MSVC 19.44 and SDL 3.4.20. The tests used SDL virtual controllers. No physical controller, GPU or game data was involved.
  • With the new regression on upstream 3faac55, five checks failed. They cover the initial all-zero pair, a return to zero, a gyro-only change with zero acceleration at the normal polling cadence, an incomplete pair, and rotation after reconnect.
  • With the fix, all 338 GameInput checks passed. Both gameinput and active_input passed five consecutive CTest runs. All six documentation link checks passed.
  • A separate two-pad probe passed 31 checks, including samples arriving on different device IDs, a ready pad continuing to publish while another waits for its second sensor, and reconnecting one pad.
  • The patch also applied alongside GameInput: return the newest reading when controller timestamps tie #4924 at 0250734; the combined GameInput executable passed all 341 checks.

AI-assisted with Codex.

@tupacfan04

Copy link
Copy Markdown
Contributor

APPROVE, with a readiness caveat.

Verified at head 0fc46fa (clean merge vs origin/main): gameinput_test 338 checks / 0 failures; ctest gameinput 4/4 runs plus active_input; doc-link tests pass. Negative control on 3faac557 gives 337 checks / 5 failures, exactly as claimed. SDL 3.4.20 source confirms the path: SDL_UpdateGamepads -> SDL_UpdateJoysticks (SDL_gamepad.c:3412) pushes sensor events gated only by SDL_EventEnabled (SDL_joystick.c:3855), so there is no pump or GamepadEventsEnabled dependency.

Caveats:

  • Readiness still depends on the event queue: a title that pumps SDL (SDL_PollEvent) or disables that event type will starve it and get silent no-motion (gameinput.cpp:1341,1880,1895).
  • The shim consumes/disables those events process-wide, so it can affect other SDL consumers in the same process.
  • A pad that never delivers one sensor keeps the events on (drained per poll, minor CPU).

AI-assisted review, no game files, no GPU.

@Atomic258

Copy link
Copy Markdown

Independent check of df0db138 — pass on Windows.

Environment: Windows 11, MSVC 19.44 (RelWithDebInfo, Ninja), CPU only. Built gameinput_test with -DLEONIDA_SDL3_FETCH=ON (pinned SDL3 3.4.20, hash-checked, static) — the shim's SDL virtual-joystick path, no real controller or game files needed.

  • PR head → 338 checks, 0 failures (full run incl. raw-HID report cases)
  • Negative control: same test binary against main's gameinput.cpp → 337 checks, 5 failures — the zero-valued motion samples after both sensors report are rejected on the parent, accepted on the head, exactly per RT-348

AI-assisted (Devin).

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.

3 participants