Repository navigation
Add gamepad support - #1844
Add gamepad support#1844
Conversation
c81638f to
ef749a5
Compare
|
I can't get this thing to work. I plug in two different types of controllers (one a standard controller, the other an XInput controller) and neither of them do anything. I even forced on the Did you have to do anything special? |
pa-devbot
left a comment
There was a problem hiding this comment.
AI review: I reviewed the main-codebase changes (skipped the vendored SDL3 tree, but traced into it to verify API usage and version matching). Overall this is a solid integration: the tracker lifecycle mirrors KeyboardHidTracker, the button/dpad/axis mappings are correct, and all 6 CI configs build and pass the command-line tests with -DPA_GAMEPAD=ON.
Verified:
- Bundled
3rdParty/SDL3headers are 3.4.20 and match3rdPartyBinaries/SDL3.lib/SDL3.dll(x64, built from SDL3-3.4.20); mac/linux use system SDL >= 3.2 viafind_package(SDL3 3.2 REQUIRED CONFIG). stop()is idempotent and safe to call whenstart()was never called: CLI test mode callsstop()from theScopeExitinMain.cppwithout ever callingstart(), andglobal_input_stop()afterrun_programdouble-stops it. The empty-m_threadguard instop()covers both.PA_CORE_ONLYreturns before the gamepad CMake blocks, so the two options can't interact.- The SDL ->
DpadPositiontable inGamepadInput_SDL.hand the Joycondpad_buttons[]array both line up with theDpadPositionenum values (0=UP ... 8=NONE). - The Y flip in
gamepad_stick()matches the protocol layer (linear_float_to_u8(-y)). - Passing the full
ProControllerStatebutton mask to a single Joy-Con is safe: PABotBase2issue_full_controller_statemasks withm_valid_buttons. GamepadInputGatecorrectly blocks held buttons after focus/console switches (I traced the armed/disarm/re-arm states, including re-arming only on a neutral read).- The other
run_controller_inputlisteners (HID keyboard, LabelImages, SnapshotDumper) all ignoreStandardGamepadstates, andSysbotBase3Pro Controllers inherit the new ProController path. - The 1 s periodic resend matches the keyboard tracker's 1000 ms behavior and keeps the 2000 ms controller commands alive.
GamepadInputState'soperator==/dynamic_castand publiccontroller_statefollow existing conventions. Docs PR #116 covers the user-facing side.
Main observations:
- Scope limitation (inline): only
ProControllerandJoyconControllerhandleStandardGamepad; generic Switch controllers inherit the no-op base, so gamepad input is silently dropped in sessions whose controller is a generic wired controller. Related to the "always neutral" report in the discussion - a quick checklist for that: (a) is a console session focused? (with no listener the gate clears every read), (b) ispadnon-null, i.e. didSDL_OpenGamepadsucceed?, (c) is the session's controller a Pro Controller or Joy-Con? - Windows deploy bloat (inline):
SDL3.dllis copied into every Windows deploy, even withPA_GAMEPAD=OFF. - Polling cadence (inline): the 8 ms tick runs even when no pad is connected, while discovery only re-runs every 1 s.
- Guide/Capture passthrough: the physical Home/Capture buttons are forwarded to the Switch (HOME lands on the right Joy-Con, CAPTURE on the left). Some OSes reserve the guide button, so it may simply never fire on some devices - worth knowing, not a bug.
Minor nits already flagged by @Mysticial (red error logging) are agreed; the two inline comments below add the loop-cadence suggestion and the scope/deploy notes.
Notes on lines outside this PR's diff:
SerialPrograms/CMakeLists.txt:354: Minor:SDL3.dllends up in every Windows deployment, even withPA_GAMEPAD=OFF- thefile(GLOB THIRD_PARTY_DLLS "3rdPartyBinaries/*.dll")deploy step (~line 876) copies all DLLs in that folder unconditionally, andSDL3.dllnow lives there. Harmless (~2.8 MB), but if that matters the copy could be gated onPA_GAMEPAD.
|
Oh wait. It does actually work on my XInput controller. But not my regular one. hmm... not an ideal limitation. But it's still a start. |
|
Other issues:
Not sure if these can be fixed, but worth pointing out. |
|
pa-devbot
left a comment
There was a problem hiding this comment.
AI review: Follow-up on ece636046 ("Fix issues reported by Kuro") — the three changes since my last review are all correct and resolve the actionable points:
- Red init-failure log (
GlobalGamepadTracker.cpp): matches @Mysticial's suggested fix. - Adaptive sleep (
GlobalGamepadTracker.cppthread loop):wake = pad ? now + 8ms : discoveris exactly the right shape. With a pad connected the 8 ms tick is unchanged; with no pad the thread now sleeps until the next 1 s discovery tick (immediate re-wake ifdiscoveris in the past, e.g. right after a disconnect, which just costs one extra iteration).stop()/clear_state()still wake it early via the cv, and worst-case shutdown latency when idle is 1 s, bounded and fine. - SDL3.dll deploy gate (
CMakeLists.txt):list(REMOVE_ITEM THIRD_PARTY_DLLS "${REPO_ROOT_DIR}/3rdPartyBinaries/SDL3.dll")matches the glob's exact path expression, is a no-op if the file is absent, and is scoped to the WIN32 deploy block — soPA_GAMEPAD=OFFbuilds no longer ship the ~2.8 MB DLL. Good.
CI status on ece636046: 5 of 6 pass (Mac, Mac Intel, Ubuntu x2, Windows MSVC). The Windows Clang job hit the 6 h timeout, and I dug into the log: the last output is 23:04:47 with four tests never reporting PASSED, including Sockets (Qt) - Completion lifetime under event-thread stall — which is precisely the test that main's Sockets: fix the start/close races that hang the test runner (#1849, merged 2026-11-06 03:40 UTC) documents as the Clang-CI hang ("a hung test is what stalls the parallel runner until the job timeout"). This PR's branch is based on main at e2ae30190 (#1832), so it does not contain #1849. The gamepad code cannot be involved: in --command-line-test-mode the tracker is never started (no SDL init, no worker thread; only the idempotent stop() runs), and the PR touches none of the ListenerSet/socket/test-runner code. So I read this as the pre-existing test-infrastructure flake, not a regression from this PR.
Suggestion: merge main into the branch (picks up #1849 and the other recent socket fixes) and re-run the Windows Clang job.
Still open from the first review (no code change expected):
- Gamepad input only works when the session's controller is a Pro Controller or Joy-Con; generic wired controllers inherit the no-op
run_controller_input(). Worth a line in the docs PR (#116) so users don't hit the "does nothing" wall. - @Mysticial's "always neutral" report in the discussion is still unanswered — if it persists after the CI cleanup, the checklist in my first review (focused session?
padnon-null? controller type?) is the place to start.
|
Can you rebase master and split out a preceding PR to add just the SDL library? So basically, a new PR for:
But leave out any implementation of the gamepad support for now. I want to make sure we can take this dependency first both here and in Azure. Since the library is small, it's ok to include it now even if we don't immediately use it in the next or even near future releases. |
ea04bd0 to
07b21f2
Compare
Every controller properly detected by windows (meaning switch controller were funky) worked fine. For switch controller, it appears on windows but it's not showing any button press or anything. Not sure we can do much more, unless we go the steam way and that's a lot more work !
It works on my side, for example the screenshot button from a stadia controller |
fbde8ee to
65e2fdf
Compare
pa-devbot
left a comment
There was a problem hiding this comment.
AI review: Re-reviewed the rebased head 2c69967d1 (single commit on top of 9cb30a4c2, which brings in the SDL merge #1860, the socket fixes, and the PA_SDL naming). The refactor is clean and everything I verified earlier is preserved verbatim:
GamepadInput_Statesplit into .h/.cpp: the state/gate logic is byte-identical to the version I traced.GamepadInput_State.cppis now always compiled and lives inCORE_LIBRARY_SOURCES— correct, since it has no SDL dependency and includes only core headers (ControllerInput.h,NintendoSwitch_ProControllerState.h).GamepadInput_SDLmoved to aPA_SDL-guarded .cpp: deadzone rescaling, button mapping, dpad table, and the Y-flip are unchanged from what I verified.GlobalGamepadTrackeris unchanged apart from thePA_GAMEPAD→PA_SDLrename; the red init-failure log and the adaptive 8ms/1s sleep from the previous round are intact. Same forMain.cpp,ControllerInput.cpp,SourceFiles.cmake,ConsoleSystemSession.cpp, and the Joycon/ProController changes.PA_CORE_ONLY+PA_SDLstill can't interact (the SDL link blocks in main are after the core-only early return).
CI: all 6 configs pass on 2c69967d1, including Windows Clang, which hit the 6 h timeout on the previous head — consistent with the earlier diagnosis that that hang was the main-branch socket test issue, now pulled in by the rebase.
Correction to my first review: the "generic wired controllers inherit the no-op run_controller_input()" point was wrong — PABotBase2_WiredController derives from ProController, as do PABotBase2_ProController and ProController_SysbotBase3, and the PABotBase2 Joy-Cons derive from JoyconController. So every concrete Switch controller gets the StandardGamepad path; no controller type silently drops gamepad input. (Mysticial already flagged this in-thread — sorry for the noise.)
Remaining known limitation from the discussion: a Bluetooth-paired Switch Pro Controller/Joy-Con on Windows is visible but produces no button input through SDL (author's finding; fixing that would need HID-level handling, a la Steam). That's an SDL platform/gamepad-DB limitation, not a defect in this PR — worth a sentence in the docs PR (#116) so users don't open issues about it.
One small new nit (inline): the file-local helpers in GamepadInput_SDL.cpp have external linkage.
|
|
||
| // Rescale outside a radial deadzone so centered sticks are exactly neutral, | ||
| // while retaining the entire analog range. SDL's positive Y points down. | ||
| std::tuple<double, double> gamepad_stick(int x, int y){ |
There was a problem hiding this comment.
AI review: Minor: gamepad_stick() (and gamepad_trigger() below) are file-local helpers but have external linkage — they're free functions in namespace PokemonAutomation that the header doesn't declare. Make them static or put them in an anonymous namespace (the codebase's usual convention) so they can't collide with symbols from other translation units.
Allow a connected physical gamepad to control the active console through SDL, alongside keyboard input. Gamepad input is disabled by default; enable it with
-DPA_GAMEPAD=ON.Depends on #1860 (SDL library). Merge that dependency PR first; this PR then adds only the gamepad integration.
Will close #710
Documentation available in PokemonAutomation/pokemonautomation.github.io#116