Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iOS virtual controller support #97530

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kisg
Copy link
Contributor

@kisg kisg commented Sep 27, 2024

Adds iOS virtual controller support to Godot.

The virtual controller may be configured in the project settings.

Apple reference: https://developer.apple.com/documentation/gamecontroller/gcvirtualcontroller?language=objc

Developed by Migeran, sponsored by Xibbon Inc.

@kisg kisg requested review from a team as code owners September 27, 2024 10:13
@bruvzg bruvzg self-requested a review September 27, 2024 10:21
@Chaosus Chaosus added this to the 4.4 milestone Sep 27, 2024
@kisg
Copy link
Contributor Author

kisg commented Sep 27, 2024

@bruvzg Thank you for your review. We have another idea that could work better:

  • We would add a new VirtualController abstract class (under core/input/), and the Input singleton would have a single get_virtual_controller() method that can be used to retrieve it. If it returns null, then it is not supported.
  • During startup the platform code can set a platform-specific implementation (IOSVirtualController on iOS for now), that will implement the same API.

What do you think?

@bruvzg
Copy link
Member

bruvzg commented Sep 27, 2024

What do you think?

That's probably OK as well.

@rolandvigh rolandvigh force-pushed the ios_virtual_controller branch 2 times, most recently from 4d04acd to 8f19e30 Compare October 1, 2024 12:28
@kisg
Copy link
Contributor Author

kisg commented Oct 1, 2024

We implemented the proposed changes, please take a look.

@Mickeon Mickeon modified the milestones: 4.4, 4.x Dec 3, 2024
@Mickeon Mickeon requested a review from bruvzg December 3, 2024 16:24
Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

Tested on iPad, seems to be working fine.

@akien-mga akien-mga changed the title Add ios virtual controller support Add iOS virtual controller support Jan 6, 2025
@akien-mga akien-mga removed this from the 4.x milestone Jan 6, 2025
@akien-mga akien-mga added this to the 4.4 milestone Jan 6, 2025
@rolandvigh rolandvigh force-pushed the ios_virtual_controller branch from 26764e4 to d55b9e8 Compare January 9, 2025 15:29
@akien-mga
Copy link
Member

Looks good! Could you squash the commits? See PR workflow for instructions.

@akien-mga
Copy link
Member

Since there's now an OS abstraction layer for virtual controllers, it would be good to assess what's the plan for other platforms. Is iOS the only one where this is supported at OS level, or can this be supported on other devices too (Android, Web on mobile, touchscreen laptop)?

@rolandvigh rolandvigh force-pushed the ios_virtual_controller branch 2 times, most recently from d007dbd to 495a618 Compare January 10, 2025 12:42
@bruvzg
Copy link
Member

bruvzg commented Jan 13, 2025

Is iOS the only one where this is supported at OS level, or can this be supported on other devices too (Android, Web on mobile, touchscreen laptop)?

I do not think there are direct equivalents on other platforms, but we probably can add some generic software implementation of touch controller overlay.

@hpvb
Copy link
Member

hpvb commented Jan 13, 2025

For a more useful API to implement on other platforms I'd prefer we follow the API described by the Apple documentation, with a way to enable elements by enum, and allow users to use all of the sticks, buttons, and triggers defined by the API.

I think then the only additional thing we might want is a way to query the virtual joystick implementation for what elements it support. Or we could just limit it to whatever Apple has, but that might change in the future, so I think a way to query the capabilities would be useful.

We can then later also add support for setting the position of elements, but that could be done as an addition to this PR later. I feel that changing the hardcoded button/stick name methods later would be harder to do in a compatible fashion.

I think then a way for the user to retrieve an array of elements, and a way to enable/disable elements by the enum would probably make this API way more future proof, and I think would be a pretty small change?

@akien-mga
Copy link
Member

akien-mga commented Jan 13, 2025

I agree with @hpvb's feedback, and generally I'd really like us to implement this in a cross-platform way. As @bruvzg pointed out only iOS seems to provide this natively, so it's fine that it's the only native implementation for the class. But we should be able to implement an engine API for the other platforms.

That's not necessarily something to be done in this PR or by this contributor. But before committing to an API we'd want to preserve compatibility with, we should do a bit of research on what would be the API we want to expose for such a cross-platform feature taking inspiration from Apple's native one. There's also a bunch of plugins users made over the year for virtual controllers for mobile input, which would be good to review for further inspiration.

So that means I was a bit too quick to set this on the 4.4 milestone last week. We're entering feature freeze and the beta phase for 4.4 today/tomorrow, and given the above I'd prefer we keep this for 4.5 and workshop the API a bit more (we can do that in the meantime so this gets merged early on for the 4.5 dev cycle).

I put this on the 4.5 merge queue so we keep track of it.

@akien-mga akien-mga modified the milestones: 4.4, 4.5 Jan 13, 2025
@dsnopek
Copy link
Contributor

dsnopek commented Jan 13, 2025

To me this kind of feels like something that should be done as a GDExtension.

That would allow you to either (1) only support iOS, and folks only download the extension if they are doing iOS, or (2) be more "experimental" with the generic implementation for other (non-iOS) platforms.

Particularly for nr 2: given that on-screen gamepads can be done in so many different ways, and they are sometimes tuned to the specific art style or gameplay of the app, it seems like it'd be tricky to agree on a generic (non-iOS) implementation for upstream Godot that everyone would be happy with.

@hpvb
Copy link
Member

hpvb commented Jan 13, 2025

Particularly for nr 2: given that on-screen gamepads can be done in so many different ways, and they are sometimes tuned to the specific art style or gameplay of the app, it seems like it'd be tricky to agree on a generic (non-iOS) implementation for upstream Godot that everyone would be happy with.

I think a "generic" implementation that largely mimicks Apple's would be useful. If only for testing/writing cross-platform (mobile) games. I think it would make the lives of developers a lot easier to have something "in the box" so to speak that works the same same across all mobile platforms.

Any developer that wants to do their own already has those tools, apparently Apple felt it was important enough to add to their platform, and I can see why! I think there's a really good case to have this as an engine feature, and one that will "just work" for all touch platforms. It'd be nice if an indie with a relatively small team/budget could just port their desktop game to ios/android/mobile web by just rejigging the ux a bit and enabling a virtual gamepad.

@rolandvigh rolandvigh force-pushed the ios_virtual_controller branch from 495a618 to 33f8965 Compare February 5, 2025 11:06
@rolandvigh rolandvigh force-pushed the ios_virtual_controller branch from 33f8965 to f2d701a Compare February 24, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants