mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 00:39:53 +00:00
Optimize input_joypad_pressed code
This commit is contained in:
parent
2f12d8982c
commit
647ffca76c
@ -1112,8 +1112,10 @@ static int16_t android_input_state(void *data,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return input_joypad_pressed(android->joypad, port, binds[port], id) ||
|
||||
android_keyboard_port_input_pressed(binds[port],id);
|
||||
if (binds[port][id].valid)
|
||||
return input_joypad_pressed(android->joypad, port, binds[port], id) ||
|
||||
android_keyboard_port_input_pressed(binds[port],id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return input_joypad_analog(android->joypad, port, idx, id,
|
||||
binds[port]);
|
||||
@ -1166,12 +1168,14 @@ static bool android_input_key_pressed(void *data, int key)
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
if (input_joypad_pressed(android->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(android->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(android->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(android->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
|
@ -277,12 +277,16 @@ static int16_t cocoa_input_state(void *data,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return apple_input_is_pressed(port, binds[port], id) ||
|
||||
input_joypad_pressed(apple->joypad, port, binds[port], id)
|
||||
if (binds[port][id].valid)
|
||||
{
|
||||
return apple_input_is_pressed(port, binds[port], id) ||
|
||||
input_joypad_pressed(apple->joypad, port, binds[port], id)
|
||||
#ifdef HAVE_MFI
|
||||
|| input_joypad_pressed(apple->sec_joypad, port, binds[port], id)
|
||||
|| input_joypad_pressed(apple->sec_joypad, port, binds[port], id)
|
||||
#endif
|
||||
;
|
||||
;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
#ifdef HAVE_MFI
|
||||
ret = input_joypad_analog(apple->sec_joypad, port,
|
||||
@ -318,26 +322,34 @@ static bool cocoa_input_key_pressed(void *data, int key)
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
{
|
||||
if (settings->input.binds[0][key].valid)
|
||||
{
|
||||
if (input_joypad_pressed(apple->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
#ifdef HAVE_MFI
|
||||
if (input_joypad_pressed(apple->sec_joypad, port, settings->input.binds[0], key))
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (settings->input.binds[0][key].valid)
|
||||
{
|
||||
if (input_joypad_pressed(apple->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
#ifdef HAVE_MFI
|
||||
if (input_joypad_pressed(apple->sec_joypad, port, settings->input.binds[0], key))
|
||||
if (input_joypad_pressed(apple->sec_joypad, 0, settings->input.binds[0], key))
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(apple->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
#ifdef HAVE_MFI
|
||||
if (input_joypad_pressed(apple->sec_joypad, 0, settings->input.binds[0], key))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -57,7 +57,9 @@ static int16_t ctr_input_state(void *data, const struct retro_keybind **binds,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return input_joypad_pressed(ctr->joypad, port, binds[port], id);
|
||||
if (binds[port][id].valid)
|
||||
return input_joypad_pressed(ctr->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return input_joypad_analog(ctr->joypad, port, idx, id, binds[port]);
|
||||
}
|
||||
@ -96,12 +98,14 @@ static bool ctr_input_key_pressed(void *data, int key)
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
if (input_joypad_pressed(ctr->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(ctr->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(ctr->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(ctr->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
|
@ -281,7 +281,7 @@ static bool dinput_is_pressed(struct dinput_input *di,
|
||||
|
||||
if (!di->blocked && dinput_keyboard_pressed(di, bind->key))
|
||||
return true;
|
||||
if (input_joypad_pressed(di->joypad, port, binds, id))
|
||||
if (binds[port][id].valid && input_joypad_pressed(di->joypad, port, binds, id))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -51,7 +51,9 @@ static int16_t gx_input_state(void *data, const struct retro_keybind **binds,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return input_joypad_pressed(gx->joypad, port, binds[port], id);
|
||||
if (binds[port][id].valid)
|
||||
return input_joypad_pressed(gx->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return input_joypad_analog(gx->joypad, port, idx, id, binds[port]);
|
||||
}
|
||||
@ -101,12 +103,14 @@ static bool gx_input_key_pressed(void *data, int key)
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
if (input_joypad_pressed(gx->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(gx->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(gx->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(gx->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
|
@ -119,12 +119,14 @@ static bool linuxraw_input_key_pressed(void *data, int key)
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
if (input_joypad_pressed(linuxraw->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(linuxraw->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(linuxraw->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(linuxraw->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
@ -146,9 +148,10 @@ static int16_t linuxraw_input_state(void *data,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return linuxraw_is_pressed(linuxraw, binds[port], id) ||
|
||||
input_joypad_pressed(linuxraw->joypad, port, binds[port], id);
|
||||
|
||||
if (binds[port][id].valid)
|
||||
return linuxraw_is_pressed(linuxraw, binds[port], id) ||
|
||||
input_joypad_pressed(linuxraw->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
ret = linuxraw_analog_pressed(linuxraw, binds[port], idx, id);
|
||||
if (!ret)
|
||||
|
@ -112,7 +112,9 @@ static int16_t ps3_input_state(void *data,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return input_joypad_pressed(ps3->joypad, port, binds[port], id);
|
||||
if (binds[port][id].valid)
|
||||
return input_joypad_pressed(ps3->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return input_joypad_analog(ps3->joypad, port, idx, id, binds[port]);
|
||||
#if 0
|
||||
|
@ -74,7 +74,9 @@ static int16_t psp_input_state(void *data, const struct retro_keybind **binds,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return input_joypad_pressed(psp->joypad, port, binds[port], id);
|
||||
if (binds[port][id].valid)
|
||||
return input_joypad_pressed(psp->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return input_joypad_analog(psp->joypad, port, idx, id, binds[port]);
|
||||
}
|
||||
|
@ -780,7 +780,9 @@ static int16_t qnx_input_state(void *data,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return input_joypad_pressed(qnx->joypad, port, binds[port], id);
|
||||
if (binds[port][id].valid)
|
||||
return input_joypad_pressed(qnx->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return qnx_analog_input_state(qnx, port, idx, id);
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
|
@ -149,8 +149,9 @@ static int16_t rwebinput_input_state(void *data, const struct retro_keybind **bi
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return rwebinput_is_pressed(rwebinput, binds[port], id);
|
||||
|
||||
if (binds[port][id].valid)
|
||||
return rwebinput_is_pressed(rwebinput, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return rwebinput_analog_pressed(rwebinput, binds[port], idx, id);
|
||||
|
||||
|
@ -121,12 +121,14 @@ static bool sdl_input_key_pressed(void *data, int key)
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
if (input_joypad_pressed(sdl->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(sdl->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(sdl->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(sdl->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
|
@ -467,9 +467,9 @@ static int16_t udev_analog_pressed(const struct retro_keybind *binds, unsigned i
|
||||
|
||||
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
|
||||
|
||||
if (udev_input_is_pressed(binds, id_minus))
|
||||
if (binds[id_minus].valid && udev_input_is_pressed(binds, id_minus))
|
||||
pressed_minus = -0x7fff;
|
||||
if (udev_input_is_pressed(binds, id_plus))
|
||||
if (binds[id_plus].valid && udev_input_is_pressed(binds, id_plus))
|
||||
pressed_plus = 0x7fff;
|
||||
|
||||
return pressed_plus + pressed_minus;
|
||||
@ -523,9 +523,10 @@ static int16_t udev_input_state(void *data, const struct retro_keybind **binds,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return udev_input_is_pressed(binds[port], id) ||
|
||||
input_joypad_pressed(udev->joypad, port, binds[port], id);
|
||||
|
||||
if (binds[port][id].valid)
|
||||
return udev_input_is_pressed(binds[port], id) ||
|
||||
input_joypad_pressed(udev->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
ret = udev_analog_pressed(binds[port], idx, id);
|
||||
if (!ret)
|
||||
@ -555,18 +556,21 @@ static bool udev_input_key_pressed(void *data, int key)
|
||||
settings_t *settings = config_get_ptr();
|
||||
int port = 0;
|
||||
|
||||
if (udev_input_is_pressed(settings->input.binds[0], key))
|
||||
if (settings->input.binds[0][key].valid
|
||||
&& udev_input_is_pressed(settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
if (input_joypad_pressed(udev->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(udev->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(udev->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(udev->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
|
@ -96,7 +96,7 @@ static bool x_is_pressed(x11_input_t *x11,
|
||||
if (id < RARCH_BIND_LIST_END)
|
||||
{
|
||||
const struct retro_keybind *bind = &binds[id];
|
||||
return bind->valid && x_key_pressed(x11, binds[id].key);
|
||||
return x_key_pressed(x11, binds[id].key);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -111,9 +111,9 @@ static int16_t x_pressed_analog(x11_input_t *x11,
|
||||
|
||||
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
|
||||
|
||||
if (x_is_pressed(x11, binds, id_minus))
|
||||
if (binds[id_minus].valid && x_is_pressed(x11, binds, id_minus))
|
||||
pressed_minus = -0x7fff;
|
||||
if (x_is_pressed(x11, binds, id_plus))
|
||||
if (binds[id_plus].valid && x_is_pressed(x11, binds, id_plus))
|
||||
pressed_plus = 0x7fff;
|
||||
|
||||
return pressed_plus + pressed_minus;
|
||||
@ -125,7 +125,7 @@ static bool x_input_key_pressed(void *data, int key)
|
||||
settings_t *settings = config_get_ptr();
|
||||
int port = 0;
|
||||
|
||||
if (x_is_pressed(x11, settings->input.binds[0], key))
|
||||
if (settings->input.binds[0][key].valid && x_is_pressed(x11, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
if (settings->input.all_users_control_menu)
|
||||
@ -257,12 +257,12 @@ static int16_t x_input_state(void *data,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return x_is_pressed(x11, binds[port], id) ||
|
||||
input_joypad_pressed(x11->joypad, port, binds[port], id);
|
||||
|
||||
if (binds[port][id].valid)
|
||||
return x_is_pressed(x11, binds[port], id) ||
|
||||
input_joypad_pressed(x11->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return x_key_pressed(x11, id);
|
||||
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
ret = x_pressed_analog(x11, binds[port], idx, id);
|
||||
if (!ret)
|
||||
|
@ -59,7 +59,9 @@ static int16_t xdk_input_state(void *data, const struct retro_keybind **binds,
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
return input_joypad_pressed(xdk->joypad, port, binds[port], id);
|
||||
if (binds[port][id].valid)
|
||||
return input_joypad_pressed(xdk->joypad, port, binds[port], id);
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
return input_joypad_analog(xdk->joypad, port, index, id, binds[port]);
|
||||
}
|
||||
@ -101,12 +103,14 @@ static bool xdk_input_key_pressed(void *data, int key)
|
||||
if (settings->input.all_users_control_menu)
|
||||
{
|
||||
for (port = 0; port < MAX_USERS; port++)
|
||||
if (input_joypad_pressed(xdk->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(xdk->joypad,
|
||||
port, settings->input.binds[0], key))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (input_joypad_pressed(xdk->joypad,
|
||||
if (settings->input.binds[0][key].valid &&
|
||||
input_joypad_pressed(xdk->joypad,
|
||||
0, settings->input.binds[0], key))
|
||||
return true;
|
||||
|
||||
|
@ -69,7 +69,7 @@ bool udev_input_is_pressed(const struct retro_keybind *binds, unsigned id)
|
||||
{
|
||||
const struct retro_keybind *bind = &binds[id];
|
||||
unsigned bit = input_keymaps_translate_rk_to_keysym(binds[id].key);
|
||||
return bind->valid && BIT_GET(udev_key_state, bit);
|
||||
return BIT_GET(udev_key_state, bit);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -239,31 +239,24 @@ bool input_joypad_pressed(
|
||||
const void *binds_data,
|
||||
unsigned key)
|
||||
{
|
||||
float scaled_axis;
|
||||
int16_t axis;
|
||||
uint32_t joyaxis;
|
||||
uint64_t joykey;
|
||||
settings_t *settings = config_get_ptr();
|
||||
const struct retro_keybind *binds = (const struct retro_keybind*)
|
||||
binds_data;
|
||||
unsigned joy_idx = settings->input.joypad_map[port];
|
||||
const struct retro_keybind *binds = (const struct retro_keybind*)binds_data;
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
const struct retro_keybind *auto_binds = settings->input.autoconf_binds[joy_idx];
|
||||
|
||||
if (!drv || !binds[key].valid)
|
||||
return false;
|
||||
|
||||
joykey = (binds[key].joykey != NO_BTN)
|
||||
uint64_t joykey = (binds[key].joykey != NO_BTN)
|
||||
? binds[key].joykey : auto_binds[key].joykey;
|
||||
|
||||
if (drv->button(joy_idx, (uint16_t)joykey))
|
||||
return true;
|
||||
if (!drv->button(joy_idx, (uint16_t)joykey))
|
||||
{
|
||||
uint32_t joyaxis = (binds[key].joyaxis != AXIS_NONE)
|
||||
? binds[key].joyaxis : auto_binds[key].joyaxis;
|
||||
int16_t axis = drv->axis(joy_idx, joyaxis);
|
||||
float scaled_axis = (float)abs(axis) / 0x8000;
|
||||
return scaled_axis > settings->input.axis_threshold;
|
||||
}
|
||||
|
||||
joyaxis = (binds[key].joyaxis != AXIS_NONE)
|
||||
? binds[key].joyaxis : auto_binds[key].joyaxis;
|
||||
axis = drv->axis(joy_idx, joyaxis);
|
||||
scaled_axis = (float)abs(axis) / 0x8000;
|
||||
return scaled_axis > settings->input.axis_threshold;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user