From 5a064ef4ca03b32cc16a076409e0a57ce04fba1b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 12 Jun 2020 06:26:03 +0200 Subject: [PATCH] (dinput) Cleanups - use button_is_pressed --- input/drivers/dinput.c | 81 ++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 5b6f9bf25f..a21d965f02 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -540,35 +540,6 @@ static int16_t dinput_pointer_state(struct dinput_input *di, return 0; } -static int16_t dinput_is_pressed( - struct dinput_input *di, - const input_device_driver_t *joypad, - settings_t *settings, - rarch_joypad_info_t *joypad_info, - const struct retro_keybind *binds, - unsigned port, unsigned id) -{ - const struct retro_keybind *bind = &binds[id]; - /* 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 (settings->uints.input_mouse_index[port] == 0) - if (dinput_mouse_button_pressed( - di, port, binds[id].mbutton)) - return 1; - if ((uint16_t)joykey != NO_BTN - && joypad->button( - joypad_info->joy_idx, (uint16_t)joykey)) - return 1; - if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis)) - / 0x8000) > joypad_info->axis_threshold) - return 1; - return 0; -} - static int16_t dinput_input_state(void *data, rarch_joypad_info_t *joypad_info, const struct retro_keybind **binds, unsigned port, @@ -595,10 +566,18 @@ static int16_t dinput_input_state(void *data, for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { if (binds[port][i].valid) - if (dinput_is_pressed( - di, di->joypad, - settings, joypad_info, binds[port], port, i)) + { + if ( + settings->uints.input_mouse_index[port] == 0 + && dinput_mouse_button_pressed( + di, port, binds[port][i].mbutton) + ) ret |= (1 << i); + else if (button_is_pressed( + di->joypad, + joypad_info, binds[port], port, i)) + ret |= (1 << i); + } } } else @@ -609,10 +588,18 @@ static int16_t dinput_input_state(void *data, di->state[rarch_keysym_lut[(enum retro_key)binds[port][i].key]] & 0x80) ret |= (1 << i); else if (binds[port][i].valid) - if (dinput_is_pressed( - di, di->joypad, settings, joypad_info, + { + if ( + settings->uints.input_mouse_index[port] == 0 + && dinput_mouse_button_pressed( + di, port, binds[port][i].mbutton) + ) + ret |= (1 << i); + else if (button_is_pressed( + di->joypad, joypad_info, binds[port], port, i)) ret |= (1 << i); + } } } return ret; @@ -628,9 +615,17 @@ static int16_t dinput_input_state(void *data, return 1; } if (binds[port][id].valid) - return dinput_is_pressed( - di, di->joypad, - settings, joypad_info, binds[port], port, id); + { + if ( + settings->uints.input_mouse_index[port] == 0 + && dinput_mouse_button_pressed( + di, port, binds[port][id].mbutton) + ) + return 1; + return button_is_pressed( + di->joypad, + joypad_info, binds[port], port, id); + } } } } @@ -739,9 +734,17 @@ static int16_t dinput_input_state(void *data, return 1; } if (binds[port][new_id].valid) - return dinput_is_pressed(di, di->joypad, - settings, joypad_info, + { + if ( + settings->uints.input_mouse_index[port] == 0 + && dinput_mouse_button_pressed( + di, port, binds[port][new_id].mbutton) + ) + return 1; + return button_is_pressed(di->joypad, + joypad_info, binds[port], port, new_id); + } } break; /*deprecated*/