(X11) Further optimizations to x_is_pressed

This commit is contained in:
twinaphex 2020-06-11 19:00:08 +02:00
parent f96e148f74
commit 42984968f2

View File

@ -120,27 +120,18 @@ static bool x_is_pressed(x11_input_t *x11,
unsigned port, unsigned id)
{
const struct retro_keybind *bind = &binds[id];
if ((bind->key < RETROK_LAST) && x_keyboard_pressed(x11, bind->key) )
if ((id == RARCH_GAME_FOCUS_TOGGLE) || !input_x.keyboard_mapping_blocked)
return true;
if (binds && binds[id].valid)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[id].joykey != NO_BTN)
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
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;
}
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[id].joykey != NO_BTN)
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
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;
}
@ -321,11 +312,28 @@ static int16_t x_input_state(void *data,
{
unsigned i;
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
if (input_x.keyboard_mapping_blocked)
{
if (x_is_pressed(
x11, joypad_info, binds[port], port, i))
ret |= (1 << i);
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; 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;
@ -333,8 +341,15 @@ static int16_t x_input_state(void *data,
else
{
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;
case RETRO_DEVICE_ANALOG:
@ -370,36 +385,130 @@ static int16_t x_input_state(void *data,
/*buttons*/
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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*/
case RETRO_DEVICE_ID_LIGHTGUN_X:
return x11->mouse_x - x11->mouse_last_x;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
return x11->mouse_y - x11->mouse_last_y;
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;
}