Repository navigation
Add support for iOS joystick - #3750
JasonLeon01 wants to merge 5 commits into
Conversation
|
I'm struggling to test this as I've updated to latest xcode/iOS which SFML doesn't support yet, but on first glance one thing that would certainly be useful is to enable the joystick example for iOS now - that requirres updating |
JonnyPtn
left a comment
There was a problem hiding this comment.
Testing with a dualshock controller and mostly seems fine, a few comments added on the code.
Is all the lock stuff necessary? as I understand it all of this should be running on the main thread so there should be no race conditions, and would be a lot tidier without it.
I also noticed many of the buttons trigger system behaviour (game center, screen recording, etc.) which we could disable with preferredSystemGestureState - I'd say that makes most sense as a default, as if users want to support these platform specific setttings then can build on top of SFML (whereas with it enabled, they can't use these buttons for their own purposes)
Getting the joystick example running locally I noticed some issues with the button mappings too, but as this is kind of part of a wider problem with SFML's (lack of) consistent controller button mapping I think it's fine to address later
Thanks for testing this! I’ll enable the joystick example on iOS, replace the per-update registry refreshes with initial enumeration and connection/disconnection notifications, and remove the unnecessary autorelease pool in open(). I’ll also request disabling system gestures for the exposed buttons where supported. The button-mapping cleanup can remain a separate follow-up, as you suggested. About locking, the notifications run on the main thread, but sf::Joystick::update() is also publicly callable. Is the intended contract that joystick updates on iOS must run on the main thread? |
|
Yeah I think various parts of this would fall apart if we didn't do joystick updating on the main thread so reasonable to assume it would be (but worth testing, I'd expect any issues to be quickly apparent) |
Hi, I've removed the locking, per-frame enumeration and unnecessary autorelease pools, added main-thread assertions, and enabled the joystick example on iOS. Generation checks remain to reject stale connections. I also fixed stale input after backgrounding and verified the backend on an iPhone with an Xbox controller. |
JonnyPtn
left a comment
There was a problem hiding this comment.
I don't think we need the asserts, we can expect the notifications to come on the main thread anyway, and the system will already warn if a user does try to do something on a thread they shouldn't.
I also don't think the generation counter is needed, we should be able to store the controller pointer in the slot in line with other platforms (and the equivalent implementation in your other PR for mac)
8cee218 to
fbe00a7
Compare

Description
This PR implements the previously unimplemented iOS joystick backend using Apple's GameController framework. Controllers exposing an extended gamepad profile can now be queried through
sf::Joystickand generate the existing joystick events.The implementation:
This PR implements the previously unimplemented iOS joystick backend using Apple's GameController framework for controllers exposing
GCExtendedGamepad.It tracks controllers through connection notifications and enumeration, rejects input from stale connections, and clears input while the application is inactive. Optional Options, Home, and Xbox Share buttons are read when available, subject to system gesture handling.
The iOS build now links GameController and compiles
JoystickImpl.mmwith ARC.Tasks
How to test this PR?
Build SFML for iOS and run the following example in an iOS application linked against
SFML::GraphicsandSFML::Main. Observe the event output in the Xcode debug console. The window turns green while button A on joystick 0 is held, exercising the real-time polling API as well as the event API.The existing
joystickexample is currently excluded from iOS builds, so enablingSFML_BUILD_EXAMPLESalone does not provide an iOS joystick test application.