mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 06:32:48 +00:00
(X11) Further optimizations to x_is_pressed
This commit is contained in:
parent
f96e148f74
commit
42984968f2
@ -120,27 +120,18 @@ static bool x_is_pressed(x11_input_t *x11,
|
|||||||
unsigned port, unsigned id)
|
unsigned port, unsigned id)
|
||||||
{
|
{
|
||||||
const struct retro_keybind *bind = &binds[id];
|
const struct retro_keybind *bind = &binds[id];
|
||||||
|
/* Auto-binds are per joypad, not per user. */
|
||||||
if ((bind->key < RETROK_LAST) && x_keyboard_pressed(x11, bind->key) )
|
const uint64_t joykey = (binds[id].joykey != NO_BTN)
|
||||||
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !input_x.keyboard_mapping_blocked)
|
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
|
||||||
return true;
|
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
|
||||||
|
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
|
||||||
if (binds && binds[id].valid)
|
if (x_mouse_button_pressed(x11, port, bind->mbutton))
|
||||||
{
|
return true;
|
||||||
/* Auto-binds are per joypad, not per user. */
|
if ((uint16_t)joykey != NO_BTN
|
||||||
const uint64_t joykey = (binds[id].joykey != NO_BTN)
|
&& x11->joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
|
||||||
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
|
return true;
|
||||||
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
|
if (((float)abs(x11->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
|
||||||
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
|
return true;
|
||||||
|
|
||||||
if (x_mouse_button_pressed(x11, port, bind->mbutton))
|
|
||||||
return true;
|
|
||||||
if ((uint16_t)joykey != NO_BTN
|
|
||||||
&& x11->joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
|
|
||||||
return true;
|
|
||||||
if (((float)abs(x11->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -321,11 +312,28 @@ static int16_t x_input_state(void *data,
|
|||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int16_t ret = 0;
|
int16_t ret = 0;
|
||||||
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
if (input_x.keyboard_mapping_blocked)
|
||||||
{
|
{
|
||||||
if (x_is_pressed(
|
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||||
x11, joypad_info, binds[port], port, i))
|
{
|
||||||
ret |= (1 << i);
|
if (binds[port][i].valid)
|
||||||
|
if (x_is_pressed(
|
||||||
|
x11, joypad_info, binds[port], port, i))
|
||||||
|
ret |= (1 << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
|
||||||
|
{
|
||||||
|
if ((binds[port][i].key < RETROK_LAST) &&
|
||||||
|
x_keyboard_pressed(x11, binds[port][i].key) )
|
||||||
|
return true;
|
||||||
|
if (binds[port][i].valid)
|
||||||
|
if (x_is_pressed(
|
||||||
|
x11, joypad_info, binds[port], port, i))
|
||||||
|
ret |= (1 << i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -333,8 +341,15 @@ static int16_t x_input_state(void *data,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (id < RARCH_BIND_LIST_END)
|
if (id < RARCH_BIND_LIST_END)
|
||||||
if (x_is_pressed(x11, joypad_info, binds[port], port, id))
|
{
|
||||||
return 1;
|
if ((binds[port][id].key < RETROK_LAST) &&
|
||||||
|
x_keyboard_pressed(x11, binds[port][i].key) )
|
||||||
|
if (( id == RARCH_GAME_FOCUS_TOGGLE)
|
||||||
|
|| !input_x.keyboard_mapping_blocked)
|
||||||
|
return 1;
|
||||||
|
if (binds[port][id].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port], port, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RETRO_DEVICE_ANALOG:
|
case RETRO_DEVICE_ANALOG:
|
||||||
@ -370,36 +385,130 @@ static int16_t x_input_state(void *data,
|
|||||||
|
|
||||||
/*buttons*/
|
/*buttons*/
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_TRIGGER);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_TRIGGER].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_TRIGGER].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_TRIGGER].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_TRIGGER);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
|
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_RELOAD);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_RELOAD].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_RELOAD].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_RELOAD].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_RELOAD);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
|
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_A);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_AUX_A].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_AUX_A].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_AUX_A].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_AUX_A);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
|
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_B);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_AUX_B].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_AUX_B].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_AUX_B].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_AUX_B);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
|
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_C);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_AUX_C].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_AUX_C].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_AUX_C].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_AUX_C);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_START);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_START].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_START].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_START].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_START);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
|
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_SELECT);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_SELECT].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_SELECT].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_SELECT].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_SELECT);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP:
|
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_UP);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_DPAD_UP].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_DPAD_UP].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_DPAD_UP].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_DPAD_UP);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN:
|
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_DOWN);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_DPAD_DOWN].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_DPAD_DOWN].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_DPAD_DOWN].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_DPAD_DOWN);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
|
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_LEFT);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_DPAD_LEFT].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_DPAD_LEFT].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_DPAD_LEFT].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_DPAD_LEFT);
|
||||||
|
break;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
|
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_RIGHT);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_DPAD_RIGHT].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_DPAD_RIGHT].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_DPAD_RIGHT].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_DPAD_RIGHT);
|
||||||
|
break;
|
||||||
/*deprecated*/
|
/*deprecated*/
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||||
return x11->mouse_x - x11->mouse_last_x;
|
return x11->mouse_x - x11->mouse_last_x;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||||
return x11->mouse_y - x11->mouse_last_y;
|
return x11->mouse_y - x11->mouse_last_y;
|
||||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||||
return x_is_pressed(x11, joypad_info, binds[port], port, RARCH_LIGHTGUN_START);
|
if (!input_x.keyboard_mapping_blocked)
|
||||||
|
if ((binds[port][RARCH_LIGHTGUN_START].key < RETROK_LAST)
|
||||||
|
&& x_keyboard_pressed(x11, binds[port]
|
||||||
|
[RARCH_LIGHTGUN_START].key) )
|
||||||
|
return 1;
|
||||||
|
if (binds[port][RARCH_LIGHTGUN_START].valid)
|
||||||
|
return x_is_pressed(x11, joypad_info, binds[port],
|
||||||
|
port, RARCH_LIGHTGUN_START);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user