(UWP) Cleanups/style nits

(Joypad drivers) Cleanup/slim down axis code
This commit is contained in:
libretroadmin 2023-02-19 19:32:05 +01:00
parent 8b200f552d
commit 5ae2b9f753
4 changed files with 106 additions and 102 deletions

View File

@ -69,7 +69,9 @@ int16_t gamepad_get_axis_value_raw(int16_t state[3][2], axis_data *data, bool do
value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][0]; value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][0];
break; break;
} }
if(do_clamp) {
if (do_clamp)
{
if (data->is_negative && value > 0) if (data->is_negative && value > 0)
return 0; return 0;
if (!data->is_negative && value < 0) if (!data->is_negative && value < 0)

View File

@ -77,13 +77,13 @@ static int16_t android_joypad_axis_state(
{ {
if (AXIS_NEG_GET(joyaxis) < MAX_AXIS) if (AXIS_NEG_GET(joyaxis) < MAX_AXIS)
{ {
int val = android_app->analog_state[port][AXIS_NEG_GET(joyaxis)]; int16_t val = android_app->analog_state[port][AXIS_NEG_GET(joyaxis)];
if (val < 0) if (val < 0)
return val; return val;
} }
else if (AXIS_POS_GET(joyaxis) < MAX_AXIS) else if (AXIS_POS_GET(joyaxis) < MAX_AXIS)
{ {
int val = android_app->analog_state[port][AXIS_POS_GET(joyaxis)]; int16_t val = android_app->analog_state[port][AXIS_POS_GET(joyaxis)];
if (val > 0) if (val > 0)
return val; return val;
} }

View File

@ -152,25 +152,12 @@ static int32_t ps4_joypad_button(unsigned port, uint16_t joykey)
static int16_t ps4_joypad_axis(unsigned port, uint32_t joyaxis) static int16_t ps4_joypad_axis(unsigned port, uint32_t joyaxis)
{ {
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
if (joyaxis == AXIS_NONE || port >= PS4_MAX_ORBISPADS) if (joyaxis == AXIS_NONE || port >= PS4_MAX_ORBISPADS)
return 0; return 0;
if (AXIS_NEG_GET(joyaxis) < 4) if (AXIS_NEG_GET(joyaxis) < 4)
{ {
axis = AXIS_NEG_GET(joyaxis); int16_t val = 0;
is_neg = true; int16_t axis = AXIS_NEG_GET(joyaxis);
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
switch (axis) switch (axis)
{ {
case 0: case 0:
@ -182,14 +169,29 @@ static int16_t ps4_joypad_axis(unsigned port, uint32_t joyaxis)
val = analog_state[port][1][axis - 2]; val = analog_state[port][1][axis - 2];
break; break;
} }
if (val < 0)
if (is_neg && val > 0)
val = 0;
else if (is_pos && val < 0)
val = 0;
return val; return val;
} }
else if (AXIS_POS_GET(joyaxis) < 4)
{
int16_t val = 0;
int16_t axis = AXIS_POS_GET(joyaxis);
switch (axis)
{
case 0:
case 1:
val = analog_state[port][0][axis];
break;
case 2:
case 3:
val = analog_state[port][1][axis - 2];
break;
}
if (val > 0)
return val;
}
return 0;
}
static int16_t ps4_joypad_state( static int16_t ps4_joypad_state(
rarch_joypad_info_t *joypad_info, rarch_joypad_info_t *joypad_info,
@ -200,9 +202,8 @@ static int16_t ps4_joypad_state(
int16_t ret = 0; int16_t ret = 0;
uint16_t port_idx = joypad_info->joy_idx; uint16_t port_idx = joypad_info->joy_idx;
if (port_idx >= PS4_MAX_ORBISPADS) if (port_idx < PS4_MAX_ORBISPADS)
return 0; {
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{ {
/* Auto-binds are per joypad, not per user. */ /* Auto-binds are per joypad, not per user. */
@ -214,6 +215,7 @@ static int16_t ps4_joypad_state(
) )
ret |= ( 1 << i); ret |= ( 1 << i);
} }
}
return ret; return ret;
} }