From 0ed9f055710aa4e3c497817c92e756ca149238af Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 8 Apr 2018 00:44:05 -0500 Subject: [PATCH] remap-redux part2: - remapping analogs to buttons works 100% - remapping analogs to other analogs still messed up for some reason - need to reset input of the original axis in input_driver.c still --- input/input_driver.c | 32 ++++++++++++++++++- input/input_mapper.c | 31 ++++++++++++++---- libretro-common/include/retro_miscellaneous.h | 2 ++ 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index 70a7d0340d..bad2559b6d 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -1121,7 +1121,8 @@ void input_keys_pressed(void *data, retro_bits_t* p_new_state) void input_get_state_for_port(void *data, unsigned port, retro_bits_t* p_new_state) { - unsigned i; + unsigned i, j; + int16_t val; rarch_joypad_info_t joypad_info; settings_t *settings = (settings_t*)data; BIT256_CLEAR_ALL_PTR(p_new_state); @@ -1140,6 +1141,35 @@ void input_get_state_for_port(void *data, unsigned port, retro_bits_t* p_new_sta if (bit_pressed) BIT256_SET_PTR(p_new_state, i); } + + /* left-stick x */ + val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 0, 0, libretro_input_binds[port]); + if (val >= 0) + p_new_state->analogs[0] = val; + else + p_new_state->analogs[1] = val; + + /* left-stick y */ + val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 0, 1, libretro_input_binds[port]); + if (val >= 0) + p_new_state->analogs[2] = val; + else + p_new_state->analogs[3] = val; + + /* right-stick x */ + val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 1, 0, libretro_input_binds[port]); + if (val >= 0) + p_new_state->analogs[4] = val; + else + p_new_state->analogs[5] = val; + + /* right-stick y */ + val = input_joypad_analog(input_driver_get_joypad_driver(), joypad_info, port, 1, 1, libretro_input_binds[port]); + if (val >= 0) + p_new_state->analogs[6] = val; + else + p_new_state->analogs[7] = val; + } void *input_driver_get_data(void) diff --git a/input/input_mapper.c b/input/input_mapper.c index 805297a3b9..a467e6008f 100644 --- a/input/input_mapper.c +++ b/input/input_mapper.c @@ -51,7 +51,7 @@ struct input_mapper { /* Left X, Left Y, Right X, Right Y */ - int16_t analog[4]; + int16_t analog[MAX_USERS][8]; /* the whole keyboard state */ uint32_t keys[RETROK_LAST / 32 + 1]; /* This is a bitmask of (1 << key_bind_id). */ @@ -83,13 +83,14 @@ bool input_mapper_button_pressed(input_mapper_t *handle, unsigned port, unsigned void input_mapper_poll(input_mapper_t *handle) { - int i, j; + int i, j, k; settings_t *settings = config_get_ptr(); retro_bits_t current_input; unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); unsigned device = 0; unsigned current_button_value; - unsigned remap_button; + int16_t current_axis_value; + unsigned remap_button, remap_axis; bool key_event[RARCH_CUSTOM_BIND_LIST_END]; #ifdef HAVE_MENU bool menu_is_alive = menu_driver_is_alive(); @@ -157,15 +158,29 @@ void input_mapper_poll(input_mapper_t *handle) remap_button != RARCH_UNMAPPED) BIT256_SET(handle->buttons[i], remap_button); } -#if 0 +#if 1 /* --CURRENTLY NOT IMPLEMENTED-- this loop should iterate on all users and all analog stick axes and if the axes are moved and is assigned to a button it should set the bit on the mapper input bitmap. Once implemented we should make sure to clear the original analog stick input in input_state in input_driver.c */ - for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_CUSTOM_BIND_LIST_END; j++) - { } + for (j = 0; j < 8; j++) + { + handle->analog[i][j] = 0; + + k = j + RARCH_FIRST_CUSTOM_BIND; + current_axis_value = current_input.analogs[j]; + remap_axis = settings->uints.input_remap_ids[i][k]; + if (current_axis_value != 0 && k != remap_axis && remap_axis != RARCH_UNMAPPED) + { + if (remap_axis < RARCH_FIRST_CUSTOM_BIND) + BIT256_SET(handle->buttons[i], remap_axis); + else + handle->analog[i][remap_axis - RARCH_FIRST_CUSTOM_BIND] = current_axis_value; + } + + } #endif } } @@ -188,6 +203,10 @@ void input_mapper_state( if (input_mapper_button_pressed(handle, port, id)) *ret = 1; break; + case RETRO_DEVICE_ANALOG: + if (handle->analog[port][idx == 0 ? id : id / 2] != 0) + *ret = handle->analog[port][idx == 0 ? id : id / 2]; + break; case RETRO_DEVICE_KEYBOARD: if (id < RETROK_LAST) { diff --git a/libretro-common/include/retro_miscellaneous.h b/libretro-common/include/retro_miscellaneous.h index 23f9ef02ac..d39b51feca 100644 --- a/libretro-common/include/retro_miscellaneous.h +++ b/libretro-common/include/retro_miscellaneous.h @@ -153,6 +153,8 @@ static INLINE bool bits_any_set(uint32_t* ptr, uint32_t count) typedef struct { uint32_t data[8]; + uint16_t analogs[8]; } retro_bits_t; + #endif