mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 07:13:35 +00:00
(OSX) More optimal polling of buttons/axis from pad_connection
This commit is contained in:
parent
d1e26a6911
commit
df0fbb7cf3
@ -151,15 +151,6 @@ static void hid_device_report(void* context, IOReturn result, void *sender,
|
|||||||
pad_connection_packet(connection->slot, connection->data, reportLength + 1);
|
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,
|
static void add_device(void* context, IOReturn result,
|
||||||
void* sender, IOHIDDeviceRef device)
|
void* sender, IOHIDDeviceRef device)
|
||||||
{
|
{
|
||||||
@ -259,7 +250,7 @@ static bool apple_joypad_init(void)
|
|||||||
|
|
||||||
IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone);
|
IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone);
|
||||||
|
|
||||||
pad_connection_init(&apple_hid_receive_control);
|
pad_connection_init();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -292,6 +283,7 @@ static void apple_joypad_destroy(void)
|
|||||||
static bool apple_joypad_button(unsigned port, uint16_t joykey)
|
static bool apple_joypad_button(unsigned port, uint16_t joykey)
|
||||||
{
|
{
|
||||||
apple_input_data_t *apple = (apple_input_data_t*)driver.input_data;
|
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)
|
if (!apple || joykey == NO_BTN)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -300,7 +292,8 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey)
|
|||||||
return false;
|
return false;
|
||||||
// Check the button
|
// Check the button
|
||||||
if ((port < MAX_PLAYERS) && (joykey < 32))
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,11 +308,13 @@ static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis)
|
|||||||
if (AXIS_NEG_GET(joyaxis) < 4)
|
if (AXIS_NEG_GET(joyaxis) < 4)
|
||||||
{
|
{
|
||||||
val = apple->axes[port][AXIS_NEG_GET(joyaxis)];
|
val = apple->axes[port][AXIS_NEG_GET(joyaxis)];
|
||||||
|
val += pad_connection_get_axis(port, AXIS_NEG_GET(joyaxis));
|
||||||
val = (val < 0) ? val : 0;
|
val = (val < 0) ? val : 0;
|
||||||
}
|
}
|
||||||
else if(AXIS_POS_GET(joyaxis) < 4)
|
else if(AXIS_POS_GET(joyaxis) < 4)
|
||||||
{
|
{
|
||||||
val = apple->axes[port][AXIS_POS_GET(joyaxis)];
|
val = apple->axes[port][AXIS_POS_GET(joyaxis)];
|
||||||
|
val += pad_connection_get_axis(port, AXIS_POS_GET(joyaxis));
|
||||||
val = (val > 0) ? val : 0;
|
val = (val > 0) ? val : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ typedef struct
|
|||||||
{
|
{
|
||||||
bool used;
|
bool used;
|
||||||
struct pad_connection_interface *iface;
|
struct pad_connection_interface *iface;
|
||||||
receive_control_t receive_control;
|
|
||||||
void* data;
|
void* data;
|
||||||
|
|
||||||
bool is_gcapi;
|
bool is_gcapi;
|
||||||
@ -42,14 +41,11 @@ static int find_vacant_pad(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pad_connection_init(receive_control_t receive_control)
|
void pad_connection_init()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < MAX_PLAYERS; i++)
|
for (i = 0; i < MAX_PLAYERS; i++)
|
||||||
{
|
|
||||||
memset(&slots[i], 0, sizeof(slots[0]));
|
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)
|
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)
|
if (s->iface && s->data && s->iface->packet_handler)
|
||||||
s->iface->packet_handler(s->data, data, length);
|
s->iface->packet_handler(s->data, data, length);
|
||||||
if (s->receive_control)
|
|
||||||
s->receive_control(pad);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef void (*send_control_t)(void *data, uint8_t *buf, size_t size);
|
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
|
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);
|
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);
|
void pad_connection_destroy(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user