From 68cbd5048c7c4decbac82c69905669b39aeee543 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 19 Jun 2019 05:16:24 +0200 Subject: [PATCH] Convert input_conv_analog_id_to_bind into macro --- input/drivers/dinput.c | 2 +- input/drivers/linuxraw_input.c | 2 +- input/drivers/rwebinput_input.c | 2 +- input/drivers/sdl_input.c | 2 +- input/drivers/udev_input.c | 2 +- input/drivers/uwp_input.c | 2 +- input/drivers/wayland_input.c | 2 +- input/drivers/x11_input.c | 2 +- input/input_driver.h | 22 ++++++++++++++-- retroarch.c | 45 +-------------------------------- 10 files changed, 29 insertions(+), 54 deletions(-) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 6e8778c207..676caf0125 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -345,7 +345,7 @@ static int16_t dinput_pressed_analog(struct dinput_input *di, int16_t pressed_minus = 0, pressed_plus = 0; unsigned id_minus = 0, id_plus = 0; - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); bind_minus = &binds[id_minus]; bind_plus = &binds[id_plus]; diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index 9366cbf140..00f6e1feb3 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -82,7 +82,7 @@ static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw, unsigned id_minus = 0; unsigned id_plus = 0; - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); if ((id_minus < RARCH_BIND_LIST_END) && binds->valid && linuxraw->state[rarch_keysym_lut[(enum retro_key)binds[id_minus].key]] diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index 76c625b566..ed911a05a4 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -506,7 +506,7 @@ static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput, unsigned id_minus = 0; unsigned id_plus = 0; - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); if (rwebinput_is_pressed(rwebinput, joypad_info, binds, idx, id_minus)) pressed_minus = -0x7fff; diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 85d6c7d41c..c8878ee973 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -82,7 +82,7 @@ static int16_t sdl_analog_pressed(sdl_input_t *sdl, const struct retro_keybind * unsigned id_minus = 0; unsigned id_plus = 0; - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); if ((binds[id_minus].key < RETROK_LAST) && sdl_key_pressed(binds[id_minus].key)) pressed_minus = -0x7fff; diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index a72471930d..b7734ff6e2 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -922,7 +922,7 @@ static int16_t udev_analog_pressed(const struct retro_keybind *binds, int16_t pressed_minus = 0; int16_t pressed_plus = 0; - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); if ( binds[id_minus].valid && BIT_GET(udev_key_state, diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index 66c029d1c9..4082c9453b 100644 --- a/input/drivers/uwp_input.c +++ b/input/drivers/uwp_input.c @@ -157,7 +157,7 @@ static int16_t uwp_pressed_analog(uwp_input_t *uwp, unsigned id_minus = 0, id_plus = 0; /* First, process the keyboard bindings */ - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); bind_minus = &binds[id_minus]; bind_plus = &binds[id_plus]; diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 4ee19dc1c9..75d7db617e 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -157,7 +157,7 @@ static int16_t input_wl_analog_pressed(input_ctx_wayland_data_t *wl, int16_t pressed_minus = 0; int16_t pressed_plus = 0; - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); if (binds && binds[id_minus].valid diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 846c96fbfa..13467d6ef2 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -157,7 +157,7 @@ static int16_t x_pressed_analog(x11_input_t *x11, int id_plus_key = 0; unsigned keycode = 0; - input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); + input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus); id_minus_key = binds[id_minus].key; id_plus_key = binds[id_plus].key; diff --git a/input/input_driver.h b/input/input_driver.h index 05d984da9e..08fba4e19a 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -432,8 +432,26 @@ const input_device_driver_t *input_joypad_init_driver( * Takes as input analog key identifiers and converts * them to corresponding bind IDs @ident_minus and @ident_plus. **/ -void input_conv_analog_id_to_bind_id(unsigned idx, unsigned ident, - unsigned *ident_minus, unsigned *ident_plus); +#define input_conv_analog_id_to_bind_id(idx, ident, ident_minus, ident_plus) \ + switch ((idx << 1) | ident) \ + { \ + case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X: \ + ident_minus = RARCH_ANALOG_LEFT_X_MINUS; \ + ident_plus = RARCH_ANALOG_LEFT_X_PLUS; \ + break; \ + case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y: \ + ident_minus = RARCH_ANALOG_LEFT_Y_MINUS; \ + ident_plus = RARCH_ANALOG_LEFT_Y_PLUS; \ + break; \ + case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X: \ + ident_minus = RARCH_ANALOG_RIGHT_X_MINUS; \ + ident_plus = RARCH_ANALOG_RIGHT_X_PLUS; \ + break; \ + case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y: \ + ident_minus = RARCH_ANALOG_RIGHT_Y_MINUS; \ + ident_plus = RARCH_ANALOG_RIGHT_Y_PLUS; \ + break; \ + } /** * input_joypad_pressed: diff --git a/retroarch.c b/retroarch.c index b7d72b7ddd..13f65a2127 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3228,7 +3228,7 @@ int16_t input_joypad_analog(const input_device_driver_t *drv, const struct retro_keybind *bind_minus = NULL; const struct retro_keybind *bind_plus = NULL; - input_conv_analog_id_to_bind_id(idx, ident, &ident_minus, &ident_plus); + input_conv_analog_id_to_bind_id(idx, ident, ident_minus, ident_plus); bind_minus = &binds[ident_minus]; bind_plus = &binds[ident_plus]; @@ -3318,49 +3318,6 @@ void input_pad_connect(unsigned port, input_device_driver_t *driver) input_config_set_device_name(port, driver->name(port)); } -/** - * input_conv_analog_id_to_bind_id: - * @idx : Analog key index. - * E.g.: - * - RETRO_DEVICE_INDEX_ANALOG_LEFT - * - RETRO_DEVICE_INDEX_ANALOG_RIGHT - * @ident : Analog key identifier. - * E.g.: - * - RETRO_DEVICE_ID_ANALOG_X - * - RETRO_DEVICE_ID_ANALOG_Y - * @ident_minus : Bind ID minus, will be set by function. - * @ident_plus : Bind ID plus, will be set by function. - * - * Takes as input analog key identifiers and converts - * them to corresponding bind IDs @ident_minus and @ident_plus. - **/ -void input_conv_analog_id_to_bind_id(unsigned idx, unsigned ident, - unsigned *ident_minus, unsigned *ident_plus) -{ - switch ((idx << 1) | ident) - { - case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X: - *ident_minus = RARCH_ANALOG_LEFT_X_MINUS; - *ident_plus = RARCH_ANALOG_LEFT_X_PLUS; - break; - - case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y: - *ident_minus = RARCH_ANALOG_LEFT_Y_MINUS; - *ident_plus = RARCH_ANALOG_LEFT_Y_PLUS; - break; - - case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X: - *ident_minus = RARCH_ANALOG_RIGHT_X_MINUS; - *ident_plus = RARCH_ANALOG_RIGHT_X_PLUS; - break; - - case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y: - *ident_minus = RARCH_ANALOG_RIGHT_Y_MINUS; - *ident_plus = RARCH_ANALOG_RIGHT_Y_PLUS; - break; - } -} - #ifdef HAVE_HID /** * hid_driver_find_handle: