Get rid of button_is_pressed

This commit is contained in:
twinaphex 2021-04-15 06:55:35 +02:00
parent 36bf1ad112
commit cfe9d60f51
6 changed files with 147 additions and 90 deletions

View File

@ -746,15 +746,28 @@ static int16_t dinput_input_state(
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
{ {
unsigned new_id = dinput_retro_id_to_rarch(id); unsigned new_id = dinput_retro_id_to_rarch(id);
const uint64_t bind_joykey = input_config_binds[port][new_id].joykey;
const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis;
const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey;
const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis;
uint16_t port = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if (binds[port][new_id].valid) if (binds[port][new_id].valid)
{ {
if (button_is_pressed(joypad, if ((uint16_t)joykey != NO_BTN && joypad->button(
joypad_info, port, (uint16_t)joykey))
binds[port], new_id)) return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1; return 1;
else if ( else if (
binds[port][new_id].key < RETROK_LAST binds[port][new_id].key < RETROK_LAST
&& !keyboard_mapping_blocked && !keyboard_mapping_blocked
&& di->state[rarch_keysym_lut && di->state[rarch_keysym_lut
[(enum retro_key)binds[port][new_id].key]] & 0x80 [(enum retro_key)binds[port][new_id].key]] & 0x80
@ -764,11 +777,11 @@ static int16_t dinput_input_state(
{ {
settings = config_get_ptr(); settings = config_get_ptr();
if ( if (
settings->uints.input_mouse_index[port] == 0 settings->uints.input_mouse_index[port] == 0
&& dinput_mouse_button_pressed( && dinput_mouse_button_pressed(
di, port, binds[port][new_id].mbutton) di, port, binds[port][new_id].mbutton)
) )
return 1; return 1;
} }
} }
} }

View File

@ -1134,23 +1134,38 @@ static int16_t udev_input_state(
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */ case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */
id = udev_retro_id_to_rarch(id); {
if (!keyboard_mapping_blocked) unsigned new_id = udev_retro_id_to_rarch(id);
if ((binds[port][id].key < RETROK_LAST) const uint64_t bind_joykey = input_config_binds[port][new_id].joykey;
&& udev_keyboard_pressed(udev, binds[port] const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis;
[id].key)) const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey;
return 1; const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis;
if (binds[port][id].valid) uint16_t port = joypad_info->joy_idx;
{ float axis_threshold = joypad_info->axis_threshold;
unsigned new_id = id; const uint64_t joykey = (bind_joykey != NO_BTN)
if (button_is_pressed(joypad, ? bind_joykey : autobind_joykey;
joypad_info, binds[port], const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
new_id) ? bind_joyaxis : autobind_joyaxis;
|| udev_mouse_button_pressed(udev, port, if (!keyboard_mapping_blocked)
binds[port][new_id].mbutton) if ((binds[port][new_id].key < RETROK_LAST)
) && udev_keyboard_pressed(udev, binds[port]
return 1; [new_id].key))
} return 1;
if (binds[port][new_id].valid)
{
if ((uint16_t)joykey != NO_BTN && joypad->button(
port, (uint16_t)joykey))
return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1;
if (udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton))
return 1;
}
}
break;
/*deprecated*/ /*deprecated*/
case RETRO_DEVICE_ID_LIGHTGUN_X: case RETRO_DEVICE_ID_LIGHTGUN_X:
{ {

View File

@ -643,9 +643,11 @@ static int16_t winraw_input_lightgun_state(
const struct retro_keybind **binds, const struct retro_keybind **binds,
bool keyboard_mapping_blocked, bool keyboard_mapping_blocked,
unsigned port, unsigned port,
unsigned device, unsigned id,
unsigned idx, float axis_threshold,
unsigned id) const uint64_t joykey,
const uint32_t joyaxis
)
{ {
if (!keyboard_mapping_blocked) if (!keyboard_mapping_blocked)
if ((binds[port][id].key < RETROK_LAST) if ((binds[port][id].key < RETROK_LAST)
@ -654,13 +656,17 @@ static int16_t winraw_input_lightgun_state(
return 1; return 1;
if (binds[port][id].valid) if (binds[port][id].valid)
{ {
if ((uint16_t)joykey != NO_BTN && joypad->button(
port, (uint16_t)joykey))
return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1;
if (mouse && winraw_mouse_button_pressed(wr, if (mouse && winraw_mouse_button_pressed(wr,
mouse, port, binds[port] mouse, port, binds[port]
[id].mbutton)) [id].mbutton))
return 1; return 1;
return button_is_pressed(
joypad, joypad_info, binds[port],
id);
} }
return 0; return 0;
} }
@ -862,12 +868,27 @@ static int16_t winraw_input_state(
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */ case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */
{ {
unsigned new_id = winraw_retro_id_to_rarch(id); unsigned new_id = winraw_retro_id_to_rarch(id);
return winraw_input_lightgun_state(wr, mouse, joypad, const uint64_t bind_joykey = input_config_binds[port][new_id].joykey;
const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis;
const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey;
const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis;
uint16_t port = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
return winraw_input_lightgun_state(
wr, mouse, joypad,
joypad_info, joypad_info,
binds, binds,
keyboard_mapping_blocked, keyboard_mapping_blocked,
port, device, idx, new_id); port,
new_id,
axis_threshold,
joykey,
joyaxis);
} }
/*deprecated*/ /*deprecated*/
case RETRO_DEVICE_ID_LIGHTGUN_X: case RETRO_DEVICE_ID_LIGHTGUN_X:

View File

@ -389,7 +389,17 @@ static int16_t x_input_state(
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */ case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */
{ {
unsigned new_id = x_retro_id_to_rarch(id); unsigned new_id = x_retro_id_to_rarch(id);
const uint64_t bind_joykey = input_config_binds[port][new_id].joykey;
const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis;
const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey;
const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis;
uint16_t port = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if (!keyboard_mapping_blocked) if (!keyboard_mapping_blocked)
if ((binds[port][new_id].key < RETROK_LAST) if ((binds[port][new_id].key < RETROK_LAST)
&& x_keyboard_pressed(x11, binds[port] && x_keyboard_pressed(x11, binds[port]
@ -397,9 +407,12 @@ static int16_t x_input_state(
return 1; return 1;
if (binds[port][new_id].valid) if (binds[port][new_id].valid)
{ {
if (button_is_pressed(joypad, if ((uint16_t)joykey != NO_BTN && joypad->button(
joypad_info, binds[port], port, (uint16_t)joykey))
new_id)) return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1; return 1;
else if (settings->uints.input_mouse_index[port] == 0) else if (settings->uints.input_mouse_index[port] == 0)
{ {

View File

@ -594,12 +594,6 @@ bool menu_input_dialog_start(menu_input_ctx_line_t *line);
void menu_input_dialog_end(void); void menu_input_dialog_end(void);
int16_t button_is_pressed(
const input_device_driver_t *joypad,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind *binds,
unsigned id);
RETRO_END_DECLS RETRO_END_DECLS
#endif #endif

View File

@ -479,15 +479,32 @@ static int16_t input_state_wrap(
* states together */ * states together */
if (binds[port][id].valid) if (binds[port][id].valid)
{ {
if (button_is_pressed( /* Auto-binds are per joypad, not per user. */
joypad, const uint64_t bind_joykey = binds[port][id].joykey;
joypad_info, binds[port], id)) const uint64_t bind_joyaxis = binds[port][id].joyaxis;
const uint64_t autobind_joykey = joypad_info->auto_binds[id].joykey;
const uint64_t autobind_joyaxis= joypad_info->auto_binds[id].joyaxis;
uint16_t port = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if ((uint16_t)joykey != NO_BTN && joypad->button(
port, (uint16_t)joykey))
return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1; return 1;
#ifdef HAVE_MFI #ifdef HAVE_MFI
else if (sec_joypad && if ((uint16_t)joykey != NO_BTN && sec_joypad->button(
button_is_pressed( port, (uint16_t)joykey))
sec_joypad, return 1;
joypad_info, binds[port], id)) if (joyaxis != AXIS_NONE &&
((float)abs(sec_joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1; return 1;
#endif #endif
} }
@ -25025,17 +25042,29 @@ bool input_key_pressed(int key, bool keyboard_pressed)
) )
{ {
rarch_joypad_info_t joypad_info; rarch_joypad_info_t joypad_info;
struct rarch_state struct rarch_state *p_rarch = &rarch_st;
*p_rarch = &rarch_st;
const input_device_driver_t const input_device_driver_t
*joypad = (const input_device_driver_t*)p_rarch->joypad; *joypad = (const input_device_driver_t*)
joypad_info.joy_idx = 0; p_rarch->joypad;
joypad_info.auto_binds = input_autoconf_binds[0]; const uint64_t bind_joykey = input_config_binds[0][key].joykey;
joypad_info.axis_threshold = p_rarch->input_driver_axis_threshold; const uint64_t bind_joyaxis = input_config_binds[0][key].joyaxis;
return button_is_pressed( const uint64_t autobind_joykey = input_autoconf_binds[0][key].joykey;
joypad, &joypad_info, const uint64_t autobind_joyaxis= input_autoconf_binds[0][key].joyaxis;
input_config_binds[0], uint16_t port = 0;
key); float axis_threshold = p_rarch->input_driver_axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if ((uint16_t)joykey != NO_BTN && joypad->button(
port, (uint16_t)joykey))
return true;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return true;
return false;
} }
return true; return true;
} }
@ -25046,34 +25075,6 @@ bool input_mouse_grabbed(void)
return p_rarch->input_driver_grab_mouse_state; return p_rarch->input_driver_grab_mouse_state;
} }
int16_t button_is_pressed(
const input_device_driver_t *joypad,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind *binds,
unsigned id)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t bind_joykey = binds[id].joykey;
const uint64_t bind_joyaxis = binds[id].joyaxis;
const uint64_t autobind_joykey = joypad_info->auto_binds[id].joykey;
const uint64_t autobind_joyaxis= joypad_info->auto_binds[id].joyaxis;
uint16_t port = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if ((uint16_t)joykey != NO_BTN && joypad->button(
port, (uint16_t)joykey))
return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1;
return 0;
}
/** /**
* input_joypad_analog: * input_joypad_analog:
* @drv : Input device driver handle. * @drv : Input device driver handle.