-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
macOS: Bug fixes for game controllers #94580
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments for reviewers.
print_verbose("Couldn't execute controller haptic pattern"); | ||
RumbleMotor(GCController *p_controller, GCHapticsLocality p_locality) { | ||
engine = [p_controller.haptics createEngineWithLocality:p_locality]; | ||
engine.autoShutdownEnabled = YES; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haptics was buggy, as the previous implementation was continually stopping and starting the haptic engine. When playing haptics rapidly, requiring the existing player to stop, would ultimately cause the engine to enter an inconsistent state an haptics would stop working. This PR utilises the autoShutdownEnabled
feature to let the OS handle it automatically.
if ([p_controller.haptics.supportedLocalities containsObject:p_locality]) { | ||
return memnew(RumbleMotor(p_controller, p_locality)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now only create the RumbleMotor
if it is supported by the game controller
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A); | ||
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::B); | ||
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::X); | ||
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::Y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to use the pressedChangedHandler
callback API for button-like controls, so that we reduce the number of unnecessary events sent to the Godot input system.
Using a valueChangedHandler
meant the buttons would receive continuous events as the pressure changed, whereas for most buttons, Godot only cares whether it is pressed or not.
Joypad *joypad = [[Joypad alloc] init:controller]; | ||
[self.joypadsQueue addObject:joypad]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug, as it was adding a Joypad *
to joypadsQueue
, which was expecting a GCController *
, per:
godot/platform/macos/joypad_macos.mm
Lines 255 to 257 in e25f3c0
for (GCController *controller in self.joypadsQueue) { | |
[self addMacOSJoypad:controller]; | |
} |
} | ||
|
||
- (NSArray<NSNumber *> *)getAllKeysForController:(GCController *)controller { | ||
NSArray *keys = [self.connectedJoypads allKeys]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling allKeys
always results in a new allocation.
NSArray *keys = [observer.connectedJoypads allKeys]; | ||
|
||
for (NSNumber *key in keys) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling allKeys
always returns a new NSArray
, even if it is empty. This function is called from the main loop, resulting in allocations every frame.
61170ea
to
68d7735
Compare
Probably, it makes sense to do it in one PR. |
Sounds good – any ideas where the code might live, given we should be able to use this on macOS and iOS. |
Probably in |
Excellent – that was my thought too. |
Now what to name it – |
68d7735
to
22739e0
Compare
Game Controller support was refactored to resolve some bugs and such that it can be shared across macOS, iOS and tvOS. The code still lives in
platform/macos
until the team can advise where shared platform code like this might live.Summary