From 807818d4c6a6ae78d211a8a0c2f5187d84b80ac4 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Tue, 30 Sep 2014 15:44:40 +0200 Subject: [PATCH] (Apple) Reimplement input - get rid of g_current_input_data global and instead initialize driver.input_data --- apple/OSX/platform.m | 17 ++-- apple/common/apple_gamecontroller.m | 75 ++++++++-------- apple/iOS/platform.m | 9 +- gfx/gl.c | 3 + input/apple_input.c | 133 ++++++++++++++++++---------- input/apple_input.h | 5 +- input/apple_joypad.c | 16 ++-- input/apple_joypad_ps3.c | 7 +- input/apple_joypad_ps4.c | 5 +- input/apple_joypad_wii.c | 8 +- input/hid/apple_input_hid.c | 13 +-- 11 files changed, 168 insertions(+), 123 deletions(-) diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index 6757f33b89..d31bce839c 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -34,6 +34,7 @@ static void* const associated_core_key = (void*)&associated_core_key; { int i; NSEventType event_type; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; [super sendEvent:event]; @@ -67,23 +68,23 @@ static void* const associated_core_key = (void*)&associated_core_key; { NSPoint pos; // Relative - g_current_input_data.mouse_delta[0] += event.deltaX; - g_current_input_data.mouse_delta[1] += event.deltaY; + apple->mouse_delta[0] += event.deltaX; + apple->mouse_delta[1] += event.deltaY; // Absolute pos = [[RAGameView get] convertPoint:[event locationInWindow] fromView:nil]; - g_current_input_data.touches[0].screen_x = pos.x; - g_current_input_data.touches[0].screen_y = pos.y; + apple->touches[0].screen_x = pos.x; + apple->touches[0].screen_y = pos.y; } else if (event_type == NSLeftMouseDown || event_type == NSRightMouseDown || event_type == NSOtherMouseDown) { - g_current_input_data.mouse_buttons |= 1 << event.buttonNumber; - g_current_input_data.touch_count = 1; + apple->mouse_buttons |= 1 << event.buttonNumber; + apple->touch_count = 1; } else if (event_type == NSLeftMouseUp || event_type == NSRightMouseUp || event_type == NSOtherMouseUp) { - g_current_input_data.mouse_buttons &= ~(1 << event.buttonNumber); - g_current_input_data.touch_count = 0; + apple->mouse_buttons &= ~(1 << event.buttonNumber); + apple->touch_count = 0; } } diff --git a/apple/common/apple_gamecontroller.m b/apple/common/apple_gamecontroller.m index 34e65ec7d6..7fc72c6c5b 100644 --- a/apple/common/apple_gamecontroller.m +++ b/apple/common/apple_gamecontroller.m @@ -29,53 +29,53 @@ static BOOL apple_gamecontroller_available(void) static void apple_gamecontroller_poll(GCController *controller) { - if (!controller || controller.playerIndex == MAX_PLAYERS) - return; - - uint32_t slot = (uint32_t)controller.playerIndex; + uint32_t slot, pause; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; + if (!apple || !controller || controller.playerIndex == MAX_PLAYERS) + return; + slot = (uint32_t)controller.playerIndex; /* retain the start (pause) value */ - uint32_t pause = g_current_input_data.buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START); + pause = apple->buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START); - g_current_input_data.buttons[slot] = 0; - memset(g_current_input_data.axes[slot], 0, sizeof(g_current_input_data.axes[0])); + apple->buttons[slot] = 0; + memset(apple->axes[slot], 0, sizeof(apple->axes[0])); - g_current_input_data.buttons[slot] |= pause; + apple->buttons[slot] |= pause; if (controller.extendedGamepad) { GCExtendedGamepad *gp = (GCExtendedGamepad *)controller.extendedGamepad; - g_current_input_data.buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - g_current_input_data.buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - g_current_input_data.buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - g_current_input_data.buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - g_current_input_data.buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - g_current_input_data.buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - g_current_input_data.buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - g_current_input_data.buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - g_current_input_data.buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - g_current_input_data.buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; - - g_current_input_data.buttons[slot] |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; - g_current_input_data.buttons[slot] |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; - g_current_input_data.axes[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f; - g_current_input_data.axes[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f; - g_current_input_data.axes[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f; - g_current_input_data.axes[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f; + apple->buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + apple->buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + apple->buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + apple->buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + apple->buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; + apple->buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; + apple->buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + apple->buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; + apple->buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; + apple->buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; + apple->buttons[slot] |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; + apple->buttons[slot] |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; + apple->axes[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f; + apple->axes[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f; + apple->axes[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f; + apple->axes[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f; } else if (controller.gamepad) { GCGamepad *gp = (GCGamepad *)controller.gamepad; - g_current_input_data.buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - g_current_input_data.buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - g_current_input_data.buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - g_current_input_data.buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - g_current_input_data.buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - g_current_input_data.buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - g_current_input_data.buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - g_current_input_data.buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - g_current_input_data.buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - g_current_input_data.buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; + apple->buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + apple->buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + apple->buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + apple->buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + apple->buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; + apple->buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; + apple->buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + apple->buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; + apple->buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; + apple->buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; } } @@ -90,6 +90,7 @@ void apple_gamecontroller_poll_all(void) static void apple_gamecontroller_register(GCGamepad *gamepad) { + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; gamepad.valueChangedHandler = ^(GCGamepad *updateGamepad, GCControllerElement *element) { apple_gamecontroller_poll(updateGamepad.controller); }; @@ -98,10 +99,10 @@ static void apple_gamecontroller_register(GCGamepad *gamepad) uint32_t slot = (uint32_t)controller.playerIndex; - g_current_input_data.buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START); + apple->buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - g_current_input_data.buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START); + apple->buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START); }); }; diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index 334f46cec1..ca78677e05 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -74,11 +74,12 @@ const void* apple_get_frontend_settings(void) static void handle_touch_event(NSArray* touches) { NSUInteger i; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; const float scale = [[UIScreen mainScreen] scale]; - g_current_input_data.touch_count = 0; + apple->touch_count = 0; - for(i = 0; i < touches.count && g_current_input_data.touch_count < MAX_TOUCHES; i ++) + for(i = 0; i < touches.count && (apple->touch_count < MAX_TOUCHES); i ++) { UITouch* touch = [touches objectAtIndex:i]; @@ -89,8 +90,8 @@ static void handle_touch_event(NSArray* touches) if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled) { - g_current_input_data.touches[g_current_input_data.touch_count ].screen_x = coord.x * scale; - g_current_input_data.touches[g_current_input_data.touch_count ++].screen_y = coord.y * scale; + apple->touches[apple->touch_count ].screen_x = coord.x * scale; + apple->touches[apple->touch_count ++].screen_y = coord.y * scale; } } } diff --git a/gfx/gl.c b/gfx/gl.c index d17c68d0b9..2879d856c3 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -2361,6 +2361,9 @@ static bool gl_alive(void *data) { gl_t *gl = (gl_t*)data; bool quit = false, resize = false; + + if (!gl) + return false; context_check_window_func(gl, &quit, &resize, &gl->win_width, &gl->win_height, diff --git a/input/apple_input.c b/input/apple_input.c index 755ae3ca8a..b33cd9ebe8 100644 --- a/input/apple_input.c +++ b/input/apple_input.c @@ -243,9 +243,7 @@ enum input_devices #endif -static const rarch_joypad_driver_t *joypad; -apple_input_data_t g_current_input_data; #ifdef OSX // Taken from https://github.com/depp/keycode, check keycode.h for license static const unsigned char MAC_NATIVE_TO_HID[128] = { @@ -291,6 +289,7 @@ static bool handle_small_keyboard(unsigned* code, bool down) static uint8_t mapping[128]; static bool map_initialized; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; if (!map_initialized) { @@ -309,10 +308,10 @@ static bool handle_small_keyboard(unsigned* code, bool down) unsigned translated_code = (*code < 128) ? mapping[*code] : 0; // Allow old keys to be released - if (!down && g_current_input_data.keys[*code]) + if (!down && apple->keys[*code]) return false; - if ((!down && g_current_input_data.keys[translated_code]) || + if ((!down && apple->keys[translated_code]) || small_keyboard_active) { *code = translated_code; @@ -374,6 +373,7 @@ void apple_input_reset_icade_buttons(void) void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod) { + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; code = HIDKEY(code); if (icade_enabled) @@ -388,7 +388,7 @@ void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, ui if (code == 0 || code >= MAX_KEYS) return; - g_current_input_data.keys[code] = down; + apple->keys[code] = down; /* This is copied here as it isn't defined in any standard iOS header */ enum @@ -419,6 +419,10 @@ void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, ui int32_t apple_input_find_any_key(void) { unsigned i; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; + + if (!apple) + return 0; #ifdef IOS apple_gamecontroller_poll_all(); @@ -426,7 +430,7 @@ int32_t apple_input_find_any_key(void) input_init_keyboard_lut(apple_key_map_hidusage); for (i = 0; apple_key_name_map[i].hid_id; i++) - if (g_current_input_data.keys[apple_key_name_map[i].hid_id]) + if (apple->keys[apple_key_name_map[i].hid_id]) return apple_key_name_map[i].hid_id; return 0; @@ -435,11 +439,13 @@ int32_t apple_input_find_any_key(void) int32_t apple_input_find_any_button(uint32_t port) { unsigned i, buttons; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; + #ifdef IOS apple_gamecontroller_poll_all(); #endif - buttons = g_current_input_data.buttons[port] | + buttons = apple->buttons[port] | ((port == 0) ? apple_input_get_icade_buttons() : 0); if (buttons) @@ -452,13 +458,16 @@ int32_t apple_input_find_any_button(uint32_t port) int32_t apple_input_find_any_axis(uint32_t port) { + int i; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; + #ifdef IOS apple_gamecontroller_poll_all(); #endif - for (int i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { - int16_t value = g_current_input_data.axes[port][i]; + int16_t value = apple->axes[port][i]; if (abs(value) > 0x4000) return (value < 0) ? -(i + 1) : i + 1; @@ -468,86 +477,99 @@ int32_t apple_input_find_any_axis(uint32_t port) } // Game thread interface -static bool apple_key_pressed(enum retro_key key) +static bool apple_key_pressed(apple_input_data_t *apple, enum retro_key key) { if ((int)key >= 0 && key < RETROK_LAST) - return g_current_input_data.keys[input_translate_rk_to_keysym(key)]; - + return apple->keys[input_translate_rk_to_keysym(key)]; return false; } -static bool apple_is_pressed(unsigned port_num, const struct retro_keybind *binds, unsigned key) +static bool apple_is_pressed(apple_input_data_t *apple, unsigned port_num, + const struct retro_keybind *binds, unsigned key) { - return apple_key_pressed(binds[key].key) || input_joypad_pressed(joypad, port_num, binds, key); + return apple_key_pressed(apple, binds[key].key) || + input_joypad_pressed(apple->joypad, port_num, binds, key); } // Exported input driver static void *apple_input_init(void) { + apple_input_data_t *apple = NULL; + if (driver.input_data) - return driver.input_data; - + return driver.input_data; + + apple = (apple_input_data_t*)calloc(1, sizeof(*apple)); + if (!apple) + return NULL; + input_init_keyboard_lut(apple_key_map_hidusage); - memset(&g_current_input_data, 0, sizeof(g_current_input_data)); - joypad = input_joypad_init_driver(g_settings.input.joypad_driver); + apple->joypad = input_joypad_init_driver(g_settings.input.joypad_driver); driver.input_data_own = true; - return (void*)-1; + + return apple; } static void apple_input_poll(void *data) { uint32_t i; - (void)data; + apple_input_data_t *apple = (apple_input_data_t*)data; + + if (!apple) + return; #ifdef IOS apple_gamecontroller_poll_all(); #endif - for (i = 0; i < g_current_input_data.touch_count; i++) + for (i = 0; i < apple->touch_count; i++) { - input_translate_coord_viewport(g_current_input_data.touches[i].screen_x, g_current_input_data.touches[i].screen_y, - &g_current_input_data.touches[i].fixed_x, &g_current_input_data.touches[i].fixed_y, - &g_current_input_data.touches[i].full_x, &g_current_input_data.touches[i].full_y); + input_translate_coord_viewport(apple->touches[i].screen_x, + apple->touches[i].screen_y, + &apple->touches[i].fixed_x, + &apple->touches[i].fixed_y, + &apple->touches[i].full_x, + &apple->touches[i].full_y); } - if (joypad) - joypad->poll(); + if (apple->joypad) + apple->joypad->poll(); - g_current_input_data.buttons[0] |= apple_input_get_icade_buttons(); + apple->buttons[0] |= apple_input_get_icade_buttons(); - g_current_input_data.mouse_delta[0] = 0; - g_current_input_data.mouse_delta[1] = 0; + apple->mouse_delta[0] = 0; + apple->mouse_delta[1] = 0; } static int16_t apple_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id) { - (void)data; + apple_input_data_t *apple = (apple_input_data_t*)data; switch (device) { case RETRO_DEVICE_JOYPAD: - return (id < RARCH_BIND_LIST_END) ? apple_is_pressed(port, binds[port], id) : 0; + return (id < RARCH_BIND_LIST_END) ? apple_is_pressed(apple, port, binds[port], id) : 0; case RETRO_DEVICE_ANALOG: - return input_joypad_analog(joypad, port, index, id, binds[port]); + return input_joypad_analog(apple->joypad, port, index, id, binds[port]); case RETRO_DEVICE_KEYBOARD: - return apple_key_pressed(id); + return apple_key_pressed(apple, id); case RETRO_DEVICE_MOUSE: { switch (id) { case RETRO_DEVICE_ID_MOUSE_X: - return g_current_input_data.mouse_delta[0]; + return apple->mouse_delta[0]; case RETRO_DEVICE_ID_MOUSE_Y: - return g_current_input_data.mouse_delta[1]; + return apple->mouse_delta[1]; case RETRO_DEVICE_ID_MOUSE_LEFT: - return g_current_input_data.mouse_buttons & 1; + return apple->mouse_buttons & 1; case RETRO_DEVICE_ID_MOUSE_RIGHT: - return g_current_input_data.mouse_buttons & 2; + return apple->mouse_buttons & 2; } } @@ -556,9 +578,10 @@ static int16_t apple_input_state(void *data, const struct retro_keybind **binds, { const bool want_full = device == RARCH_DEVICE_POINTER_SCREEN; - if (index < g_current_input_data.touch_count && index < MAX_TOUCHES) + if (index < apple->touch_count && index < MAX_TOUCHES) { - const apple_touch_data_t *touch = (const apple_touch_data_t *)&g_current_input_data.touches[index]; + const apple_touch_data_t *touch = (const apple_touch_data_t *) + &apple->touches[index]; int16_t x = want_full ? touch->full_x : touch->fixed_x; int16_t y = want_full ? touch->full_y : touch->fixed_y; @@ -584,23 +607,33 @@ static int16_t apple_input_state(void *data, const struct retro_keybind **binds, static bool apple_bind_button_pressed(void *data, int key) { const struct retro_keybind *binds = g_settings.input.binds[0]; - (void)data; + apple_input_data_t *apple = (apple_input_data_t*)data; - return (key >= 0 && key < RARCH_BIND_LIST_END) ? apple_is_pressed(0, binds, key) : false; + return (key >= 0 && key < RARCH_BIND_LIST_END) ? + apple_is_pressed(apple, 0, binds, key) : false; } static void apple_input_free_input(void *data) { - (void)data; + apple_input_data_t *apple = (apple_input_data_t*)data; - if (joypad) - joypad->destroy(); + if (!apple) + return; + + if (apple && apple->joypad) + apple->joypad->destroy(); + + free(apple); } -static bool apple_input_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, uint16_t strength) +static bool apple_input_set_rumble(void *data, + unsigned port, enum retro_rumble_effect effect, uint16_t strength) { - (void)data; - return input_joypad_set_rumble(joypad, port, effect, strength); + apple_input_data_t *apple = (apple_input_data_t*)data; + + if (apple && apple->joypad) + return input_joypad_set_rumble(apple->joypad, port, effect, strength); + return false; } static uint64_t apple_input_get_capabilities(void *data) @@ -620,7 +653,11 @@ static uint64_t apple_input_get_capabilities(void *data) static const rarch_joypad_driver_t *apple_get_joypad_driver(void *data) { - return joypad; + apple_input_data_t *apple = (apple_input_data_t*)data; + + if (apple && apple->joypad) + return apple->joypad; + return NULL; } input_driver_t input_apple = { diff --git a/input/apple_input.h b/input/apple_input.h index 53178db349..7e919fd4d2 100644 --- a/input/apple_input.h +++ b/input/apple_input.h @@ -47,6 +47,8 @@ typedef struct uint32_t buttons[MAX_PLAYERS]; int16_t axes[MAX_PLAYERS][4]; int8_t hats[NUM_HATS][2]; + + const rarch_joypad_driver_t *joypad; } apple_input_data_t; struct apple_pad_connection; @@ -78,9 +80,6 @@ bool apple_joypad_has_interface(uint32_t slot); void apple_joypad_send_hid_control(void *connect_data, uint8_t* data, size_t size); -/* Input data for the main thread and the game thread */ -extern apple_input_data_t g_current_input_data; - /* Main thread only */ void apple_input_enable_icade(bool on); diff --git a/input/apple_joypad.c b/input/apple_joypad.c index 013bda7b5f..f8eb165f79 100644 --- a/input/apple_joypad.c +++ b/input/apple_joypad.c @@ -172,7 +172,8 @@ static void apple_joypad_destroy(void) static bool apple_joypad_button(unsigned port, uint16_t joykey) { - if (joykey == NO_BTN) + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; + if (!apple || joykey == NO_BTN) return false; // Check hat. @@ -180,26 +181,25 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey) return false; // Check the button return (port < MAX_PLAYERS && joykey < 32) ? - (g_current_input_data.buttons[port] & (1 << joykey)) != 0 : false; + (apple->buttons[port] & (1 << joykey)) != 0 : false; } static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis) { - int16_t val; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; + int16_t val = 0; - if (joyaxis == AXIS_NONE) + if (!apple || joyaxis == AXIS_NONE) return 0; - val = 0; - if (AXIS_NEG_GET(joyaxis) < 4) { - val = g_current_input_data.axes[port][AXIS_NEG_GET(joyaxis)]; + val = apple->axes[port][AXIS_NEG_GET(joyaxis)]; val = (val < 0) ? val : 0; } else if(AXIS_POS_GET(joyaxis) < 4) { - val = g_current_input_data.axes[port][AXIS_POS_GET(joyaxis)]; + val = apple->axes[port][AXIS_POS_GET(joyaxis)]; val = (val > 0) ? val : 0; } diff --git a/input/apple_joypad_ps3.c b/input/apple_joypad_ps3.c index 058910eb2f..0846dc98a5 100644 --- a/input/apple_joypad_ps3.c +++ b/input/apple_joypad_ps3.c @@ -138,9 +138,10 @@ static int16_t hidpad_ps3_get_axis(void *data, unsigned axis) static void hidpad_ps3_packet_handler(void *data, uint8_t *packet, uint16_t size) { int i; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; struct hidpad_ps3_data *device = (struct hidpad_ps3_data*)data; - if (!device) + if (!device || !apple) return; if (!device->have_led) @@ -151,9 +152,9 @@ static void hidpad_ps3_packet_handler(void *data, uint8_t *packet, uint16_t size memcpy(device->data, packet, size); - g_current_input_data.buttons[device->slot] = hidpad_ps3_get_buttons(device); + apple->buttons[device->slot] = hidpad_ps3_get_buttons(device); for (i = 0; i < 4; i ++) - g_current_input_data.axes[device->slot][i] = hidpad_ps3_get_axis(device, i); + apple->axes[device->slot][i] = hidpad_ps3_get_axis(device, i); } static void hidpad_ps3_set_rumble(void *data, diff --git a/input/apple_joypad_ps4.c b/input/apple_joypad_ps4.c index 75b90f4078..a38961e53a 100644 --- a/input/apple_joypad_ps4.c +++ b/input/apple_joypad_ps4.c @@ -138,9 +138,10 @@ static int16_t hidpad_ps4_get_axis(void *data, unsigned axis) static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size) { int i; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data; - if (!device) + if (!device || !apple) return; (void)i; @@ -155,7 +156,7 @@ static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size memcpy(device->data, packet, size); - g_current_input_data.buttons[device->slot] = hidpad_ps4_get_buttons(device); + apple->buttons[device->slot] = hidpad_ps4_get_buttons(device); #if 0 for (i = 0; i < 4; i ++) g_current_input_data.axes[device->slot][i] = hidpad_ps4_get_axis(device, i); diff --git a/input/apple_joypad_wii.c b/input/apple_joypad_wii.c index ab219b1196..b917ff6043 100644 --- a/input/apple_joypad_wii.c +++ b/input/apple_joypad_wii.c @@ -74,10 +74,11 @@ static void hidpad_wii_packet_handler(void *data, uint8_t *packet, uint16_t size) { int i; + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; struct wiimote_t* device = (struct wiimote_t*)data; byte* msg = packet + 2; - if (!device) + if (!device || !apple) return; switch (packet[1]) @@ -100,12 +101,11 @@ static void hidpad_wii_packet_handler(void *data, break; } - g_current_input_data.buttons[device->unid] = device->btns | + apple->buttons[device->unid] = device->btns | (device->exp.cc.classic.btns << 16); for (i = 0; i < 4; i++) - g_current_input_data.axes[device->unid][i] = - hidpad_wii_get_axis(device, i); + apple->axes[device->unid][i] = hidpad_wii_get_axis(device, i); } static void hidpad_wii_set_rumble(void *data, diff --git a/input/hid/apple_input_hid.c b/input/hid/apple_input_hid.c index 03c4009b17..3ea2765820 100644 --- a/input/hid/apple_input_hid.c +++ b/input/hid/apple_input_hid.c @@ -46,6 +46,7 @@ static void apple_pad_send_control(void *connect_data, static void hid_device_input_callback(void* context, IOReturn result, void* sender, IOHIDValueRef value) { + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; struct apple_pad_connection* connection = (struct apple_pad_connection*) context; IOHIDElementRef element = IOHIDValueGetElement(value); @@ -89,7 +90,7 @@ static void hid_device_input_callback(void* context, IOReturn result, state = IOHIDValueGetIntegerValue(value) - min; val = (float)state / (float)max; - g_current_input_data.axes[connection->slot][i] = + apple->axes[connection->slot][i] = ((val * 2.0f) - 1.0f) * 32767.0f; } } @@ -107,9 +108,9 @@ static void hid_device_input_callback(void* context, IOReturn result, CFIndex state = IOHIDValueGetIntegerValue(value); if (state) - g_current_input_data.buttons[connection->slot] |= (1 << (use - 1)); + apple->buttons[connection->slot] |= (1 << (use - 1)); else - g_current_input_data.buttons[connection->slot] &= ~(1 << (use - 1)); + apple->buttons[connection->slot] &= ~(1 << (use - 1)); } break; } @@ -120,6 +121,7 @@ static void hid_device_input_callback(void* context, IOReturn result, static void hid_device_removed(void* context, IOReturn result, void* sender) { + apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; struct apple_pad_connection* connection = (struct apple_pad_connection*) context; @@ -131,9 +133,8 @@ static void hid_device_removed(void* context, IOReturn result, void* sender) msg_queue_push(g_extern.msg_queue, msg, 0, 60); RARCH_LOG("[apple_input]: %s\n", msg); - g_current_input_data.buttons[connection->slot] = 0; - memset(g_current_input_data.axes[connection->slot], - 0, sizeof(g_current_input_data.axes)); + apple->buttons[connection->slot] = 0; + memset(apple->axes[connection->slot], 0, sizeof(apple->axes)); apple_joypad_disconnect(connection->slot); free(connection);