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

Apple: Bug fixes and improvements for game controllers #94580

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion drivers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ if env["xaudio2"]:
print_error("Target platform '{}' does not support the XAudio2 audio driver".format(env["platform"]))
Exit(255)
SConscript("xaudio2/SCsub")

# Shared Apple platform drivers
if env["platform"] in ["macos", "ios"]:
SConscript("apple/SCsub")
# Midi drivers
SConscript("alsamidi/SCsub")
SConscript("coremidi/SCsub")
Expand Down
7 changes: 7 additions & 0 deletions drivers/apple/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

Import("env")

# Driver source files
env.add_source_files(env.drivers_sources, "*.mm")
43 changes: 32 additions & 11 deletions platform/ios/joypad_ios.h → drivers/apple/joypad_apple.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* joypad_ios.h */
/* joypad_apple.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -28,23 +28,44 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#include "core/input/input.h"

#define Key _QKey
#import <GameController/GameController.h>
#undef Key

@interface JoypadIOSObserver : NSObject
@class GCController;
class RumbleContext;

- (void)startObserving;
- (void)startProcessing;
- (void)finishObserving;
struct GameController {
int joy_id;
GCController *controller;
RumbleContext *rumble_context API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) = nil;
NSInteger ff_effect_timestamp = 0;
bool force_feedback = false;

@end
GameController(int p_joy_id, GCController *p_controller);
~GameController();
};

class JoypadIOS {
class JoypadApple {
private:
JoypadIOSObserver *observer;
id<NSObject> connect_observer = nil;
id<NSObject> disconnect_observer = nil;
HashMap<int, GameController *> joypads;
HashMap<GCController *, int> controller_to_joy_id;

GCControllerPlayerIndex get_free_player_index();

void add_joypad(GCController *p_controller);
void remove_joypad(GCController *p_controller);

public:
JoypadIOS();
~JoypadIOS();
JoypadApple();
~JoypadApple();

void joypad_vibration_start(GameController &p_joypad, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0));
void joypad_vibration_stop(GameController &p_joypad, uint64_t p_timestamp) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0));

void start_processing();
void process_joypads();
};
Loading