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 2 commits 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
core/input/input.h Outdated Show resolved Hide resolved
core/input/input.cpp Outdated Show resolved Hide resolved
core/input/input.h Outdated Show resolved Hide resolved
doc/classes/ProjectSettings.xml Outdated Show resolved Hide resolved
@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.

@rolandvigh rolandvigh force-pushed the ios_virtual_controller branch 4 times, most recently from af06459 to 9090de7 Compare October 7, 2024 11:31
doc/classes/Input.xml Outdated Show resolved Hide resolved
@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.

/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#import "virtual_controller_ios.h"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#import "virtual_controller_ios.h"
#import "virtual_controller_ios.h"

void IOSVirtualController::controller_connected() {
if (@available(iOS 15.0, *)) {
if (gcv_controller != nil) {
BOOL hasPhysicalController = NO;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
BOOL hasPhysicalController = NO;
BOOL has_physical_controller = NO;

Please use snake_case

Comment on lines +7 to +9
Use a virtual controller to display software controls that you can customize over your game.
You create a virtual controller from a configuration where you choose the input elements to display.
When you connect the controller to the device, users interact with it similarly to a real controller.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Use a virtual controller to display software controls that you can customize over your game.
You create a virtual controller from a configuration where you choose the input elements to display.
When you connect the controller to the device, users interact with it similarly to a real controller.
Use a virtual controller to display software controls that you can customize over your game. You create a virtual controller from a configuration where you choose the input elements to display. When you connect the controller to the device, users interact with it similarly to a real controller.

Each new line is a separate paragraph, I think this should be one line

/**************************************************************************/

#import "core/input/virtual_controller.h"
#import <GameController/GameController.h>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#import <GameController/GameController.h>
#import <GameController/GameController.h>

Group includes

void connect_controller();
void disconnect_controller();
void initialize();
void elements_changed(GCInputElementName name, bool hidden);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
void elements_changed(GCInputElementName name, bool hidden);
void elements_changed(GCInputElementName p_name, bool p_hidden);

Prefix arguments with p_

enabled_button_y = GLOBAL_GET("input_devices/virtual_controller/ios/enable_button_y");
}

void IOSVirtualController::elements_changed(GCInputElementName name, bool hidden) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
void IOSVirtualController::elements_changed(GCInputElementName name, bool hidden) {
void IOSVirtualController::elements_changed(GCInputElementName p_name, bool p_hidden) {

@akien-mga akien-mga changed the title Add ios virtual controller support Add iOS virtual controller support Jan 6, 2025
@akien-mga akien-mga modified the milestones: 4.x, 4.4 Jan 6, 2025
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.

7 participants