(Apple) Refactor apple_input_data_t
This commit is contained in:
parent
b285044e78
commit
f137f680c3
|
@ -35,47 +35,47 @@ static void apple_gamecontroller_poll(GCController *controller)
|
|||
uint32_t slot = (uint32_t)controller.playerIndex;
|
||||
|
||||
/* retain the start (pause) value */
|
||||
uint32_t pause = g_current_input_data.pad_buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
uint32_t pause = g_current_input_data.buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
|
||||
g_current_input_data.pad_buttons[slot] = 0;
|
||||
memset(g_current_input_data.pad_axis[slot], 0, sizeof(g_current_input_data.pad_axis[0]));
|
||||
g_current_input_data.buttons[slot] = 0;
|
||||
memset(g_current_input_data.axes[slot], 0, sizeof(g_current_input_data.axes[0]));
|
||||
|
||||
g_current_input_data.pad_buttons[slot] |= pause;
|
||||
g_current_input_data.buttons[slot] |= pause;
|
||||
|
||||
if (controller.extendedGamepad)
|
||||
{
|
||||
GCExtendedGamepad *gp = (GCExtendedGamepad *)controller.extendedGamepad;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0;
|
||||
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.pad_buttons[slot] |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
|
||||
g_current_input_data.pad_axis[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f;
|
||||
g_current_input_data.pad_axis[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f;
|
||||
g_current_input_data.pad_axis[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f;
|
||||
g_current_input_data.pad_axis[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f;
|
||||
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;
|
||||
}
|
||||
else if (controller.gamepad)
|
||||
{
|
||||
GCGamepad *gp = (GCGamepad *)controller.gamepad;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0;
|
||||
g_current_input_data.pad_buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,10 +98,10 @@ static void apple_gamecontroller_register(GCGamepad *gamepad)
|
|||
|
||||
uint32_t slot = (uint32_t)controller.playerIndex;
|
||||
|
||||
g_current_input_data.pad_buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
g_current_input_data.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.pad_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
g_current_input_data.buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START);
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -439,7 +439,7 @@ int32_t apple_input_find_any_button(uint32_t port)
|
|||
apple_gamecontroller_poll_all();
|
||||
#endif
|
||||
|
||||
buttons = g_current_input_data.pad_buttons[port] |
|
||||
buttons = g_current_input_data.buttons[port] |
|
||||
((port == 0) ? apple_input_get_icade_buttons() : 0);
|
||||
|
||||
if (buttons)
|
||||
|
@ -458,7 +458,7 @@ int32_t apple_input_find_any_axis(uint32_t port)
|
|||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int16_t value = g_current_input_data.pad_axis[port][i];
|
||||
int16_t value = g_current_input_data.axes[port][i];
|
||||
|
||||
if (abs(value) > 0x4000)
|
||||
return (value < 0) ? -(i + 1) : i + 1;
|
||||
|
@ -515,7 +515,7 @@ static void apple_input_poll(void *data)
|
|||
if (joypad)
|
||||
joypad->poll();
|
||||
|
||||
g_current_input_data.pad_buttons[0] |= apple_input_get_icade_buttons();
|
||||
g_current_input_data.buttons[0] |= apple_input_get_icade_buttons();
|
||||
|
||||
g_current_input_data.mouse_delta[0] = 0;
|
||||
g_current_input_data.mouse_delta[1] = 0;
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
#define MAX_TOUCHES 16
|
||||
#define MAX_KEYS 256
|
||||
|
||||
#ifndef NUM_HATS
|
||||
#define NUM_HATS 4
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16_t screen_x, screen_y;
|
||||
|
@ -40,8 +44,9 @@ typedef struct
|
|||
|
||||
uint32_t keys[MAX_KEYS];
|
||||
|
||||
uint32_t pad_buttons[MAX_PLAYERS];
|
||||
int16_t pad_axis[MAX_PLAYERS][4];
|
||||
uint32_t buttons[MAX_PLAYERS];
|
||||
int16_t axes[MAX_PLAYERS][4];
|
||||
int8_t hats[NUM_HATS][2];
|
||||
} apple_input_data_t;
|
||||
|
||||
struct apple_pad_connection;
|
||||
|
|
|
@ -180,7 +180,7 @@ 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.pad_buttons[port] & (1 << joykey)) != 0 : false;
|
||||
(g_current_input_data.buttons[port] & (1 << joykey)) != 0 : false;
|
||||
}
|
||||
|
||||
static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis)
|
||||
|
@ -194,12 +194,12 @@ static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis)
|
|||
|
||||
if (AXIS_NEG_GET(joyaxis) < 4)
|
||||
{
|
||||
val = g_current_input_data.pad_axis[port][AXIS_NEG_GET(joyaxis)];
|
||||
val = g_current_input_data.axes[port][AXIS_NEG_GET(joyaxis)];
|
||||
val = (val < 0) ? val : 0;
|
||||
}
|
||||
else if(AXIS_POS_GET(joyaxis) < 4)
|
||||
{
|
||||
val = g_current_input_data.pad_axis[port][AXIS_POS_GET(joyaxis)];
|
||||
val = g_current_input_data.axes[port][AXIS_POS_GET(joyaxis)];
|
||||
val = (val > 0) ? val : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,9 +151,9 @@ static void hidpad_ps3_packet_handler(void *data, uint8_t *packet, uint16_t size
|
|||
|
||||
memcpy(device->data, packet, size);
|
||||
|
||||
g_current_input_data.pad_buttons[device->slot] = hidpad_ps3_get_buttons(device);
|
||||
g_current_input_data.buttons[device->slot] = hidpad_ps3_get_buttons(device);
|
||||
for (i = 0; i < 4; i ++)
|
||||
g_current_input_data.pad_axis[device->slot][i] = hidpad_ps3_get_axis(device, i);
|
||||
g_current_input_data.axes[device->slot][i] = hidpad_ps3_get_axis(device, i);
|
||||
}
|
||||
|
||||
static void hidpad_ps3_set_rumble(void *data,
|
||||
|
|
|
@ -155,10 +155,10 @@ static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size
|
|||
|
||||
memcpy(device->data, packet, size);
|
||||
|
||||
g_current_input_data.pad_buttons[device->slot] = hidpad_ps4_get_buttons(device);
|
||||
g_current_input_data.buttons[device->slot] = hidpad_ps4_get_buttons(device);
|
||||
#if 0
|
||||
for (i = 0; i < 4; i ++)
|
||||
g_current_input_data.pad_axis[device->slot][i] = hidpad_ps4_get_axis(device, i);
|
||||
g_current_input_data.axes[device->slot][i] = hidpad_ps4_get_axis(device, i);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -100,11 +100,11 @@ static void hidpad_wii_packet_handler(void *data,
|
|||
break;
|
||||
}
|
||||
|
||||
g_current_input_data.pad_buttons[device->unid] = device->btns |
|
||||
g_current_input_data.buttons[device->unid] = device->btns |
|
||||
(device->exp.cc.classic.btns << 16);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
g_current_input_data.pad_axis[device->unid][i] =
|
||||
g_current_input_data.axes[device->unid][i] =
|
||||
hidpad_wii_get_axis(device, i);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ static void hid_device_input_callback(void* context, IOReturn result,
|
|||
state = IOHIDValueGetIntegerValue(value) - min;
|
||||
|
||||
val = (float)state / (float)max;
|
||||
g_current_input_data.pad_axis[connection->slot][i] =
|
||||
g_current_input_data.axes[connection->slot][i] =
|
||||
((val * 2.0f) - 1.0f) * 32767.0f;
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +107,9 @@ static void hid_device_input_callback(void* context, IOReturn result,
|
|||
CFIndex state = IOHIDValueGetIntegerValue(value);
|
||||
|
||||
if (state)
|
||||
g_current_input_data.pad_buttons[connection->slot] |= (1 << (use - 1));
|
||||
g_current_input_data.buttons[connection->slot] |= (1 << (use - 1));
|
||||
else
|
||||
g_current_input_data.pad_buttons[connection->slot] &= ~(1 << (use - 1));
|
||||
g_current_input_data.buttons[connection->slot] &= ~(1 << (use - 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -131,9 +131,9 @@ 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.pad_buttons[connection->slot] = 0;
|
||||
memset(g_current_input_data.pad_axis[connection->slot],
|
||||
0, sizeof(g_current_input_data.pad_axis));
|
||||
g_current_input_data.buttons[connection->slot] = 0;
|
||||
memset(g_current_input_data.axes[connection->slot],
|
||||
0, sizeof(g_current_input_data.axes));
|
||||
|
||||
apple_joypad_disconnect(connection->slot);
|
||||
free(connection);
|
||||
|
|
Loading…
Reference in New Issue