From df0fbb7cf37ae2ca757538d2db940be9bed47298 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 5 Oct 2014 03:28:43 +0200 Subject: [PATCH] (OSX) More optimal polling of buttons/axis from pad_connection --- input/apple_joypad_hid.c | 17 ++++++----------- input/connect/joypad_connection.c | 8 +------- input/connect/joypad_connection.h | 3 +-- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/input/apple_joypad_hid.c b/input/apple_joypad_hid.c index 9d7ebbad9e..45c11dbda3 100644 --- a/input/apple_joypad_hid.c +++ b/input/apple_joypad_hid.c @@ -151,15 +151,6 @@ static void hid_device_report(void* context, IOReturn result, void *sender, pad_connection_packet(connection->slot, connection->data, reportLength + 1); } -static void apple_hid_receive_control(unsigned index) -{ - int i; - apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; - apple->buttons[index] = pad_connection_get_buttons(index); - for (i = 0; i < 4; i++) - apple->axes[index][i] = pad_connection_get_axis(index, i); -} - static void add_device(void* context, IOReturn result, void* sender, IOHIDDeviceRef device) { @@ -259,7 +250,7 @@ static bool apple_joypad_init(void) IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone); - pad_connection_init(&apple_hid_receive_control); + pad_connection_init(); return true; } @@ -292,6 +283,7 @@ static void apple_joypad_destroy(void) static bool apple_joypad_button(unsigned port, uint16_t joykey) { apple_input_data_t *apple = (apple_input_data_t*)driver.input_data; + uint32_t buttons = pad_connection_get_buttons(port); if (!apple || joykey == NO_BTN) return false; @@ -300,7 +292,8 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey) return false; // Check the button if ((port < MAX_PLAYERS) && (joykey < 32)) - return ((apple->buttons[port] & (1 << joykey)) != 0); + return ((apple->buttons[port] & (1 << joykey)) != 0) || + ((buttons & (1 << joykey)) != 0); return false; } @@ -315,11 +308,13 @@ static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis) if (AXIS_NEG_GET(joyaxis) < 4) { val = apple->axes[port][AXIS_NEG_GET(joyaxis)]; + val += pad_connection_get_axis(port, AXIS_NEG_GET(joyaxis)); val = (val < 0) ? val : 0; } else if(AXIS_POS_GET(joyaxis) < 4) { val = apple->axes[port][AXIS_POS_GET(joyaxis)]; + val += pad_connection_get_axis(port, AXIS_POS_GET(joyaxis)); val = (val > 0) ? val : 0; } diff --git a/input/connect/joypad_connection.c b/input/connect/joypad_connection.c index 1934804f61..ddc153f9bb 100644 --- a/input/connect/joypad_connection.c +++ b/input/connect/joypad_connection.c @@ -20,7 +20,6 @@ typedef struct { bool used; struct pad_connection_interface *iface; - receive_control_t receive_control; void* data; bool is_gcapi; @@ -42,14 +41,11 @@ static int find_vacant_pad(void) return -1; } -void pad_connection_init(receive_control_t receive_control) +void pad_connection_init() { int i; for (i = 0; i < MAX_PLAYERS; i++) - { memset(&slots[i], 0, sizeof(slots[0])); - slots[i].receive_control = receive_control; - } } int32_t pad_connection_connect(const char* name, void *data, send_control_t ptr) @@ -132,8 +128,6 @@ void pad_connection_packet(uint32_t pad, if (s->iface && s->data && s->iface->packet_handler) s->iface->packet_handler(s->data, data, length); - if (s->receive_control) - s->receive_control(pad); } } diff --git a/input/connect/joypad_connection.h b/input/connect/joypad_connection.h index 3435648181..10e0d8fcfd 100644 --- a/input/connect/joypad_connection.h +++ b/input/connect/joypad_connection.h @@ -21,7 +21,6 @@ #include typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size); -typedef void (*receive_control_t)(unsigned index); typedef struct pad_connection_interface { @@ -41,7 +40,7 @@ int32_t pad_connection_connect(const char* name, void *data, send_control_t ptr) int32_t apple_joypad_connect_gcapi(void); -void pad_connection_init(receive_control_t receive_control); +void pad_connection_init(void); void pad_connection_destroy(void);