From 6fb51eb360f4f6566548b8db381d2ccf2d98251e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 5 Jan 2015 22:53:21 +0100 Subject: [PATCH] Initial implementation of remap binds feature --- general.h | 3 ++- libretro_version_1.c | 32 +++++++++++++++++++------------- menu/menu_common.h | 2 +- menu/menu_entries_cbs.c | 36 ++++++++++++++++++++++++++++++++---- retroarch.cfg | 3 +++ settings.c | 16 ++++++++++------ settings_data.c | 24 ++++++++++++++++++++++++ 7 files changed, 91 insertions(+), 25 deletions(-) diff --git a/general.h b/general.h index d824361133..247d9faece 100644 --- a/general.h +++ b/general.h @@ -361,8 +361,8 @@ struct settings char joypad_driver[32]; char keyboard_layout[64]; + unsigned remap_ids[MAX_USERS][RARCH_BIND_LIST_END]; struct retro_keybind binds[MAX_USERS][RARCH_BIND_LIST_END]; - struct retro_keybind remap_binds[MAX_USERS][RARCH_BIND_LIST_END]; struct retro_keybind autoconf_binds[MAX_USERS][RARCH_BIND_LIST_END]; unsigned max_users; @@ -374,6 +374,7 @@ struct settings unsigned libretro_device[MAX_USERS]; unsigned analog_dpad_mode[MAX_USERS]; + bool remap_binds_enable; float axis_threshold; unsigned joypad_map[MAX_USERS]; unsigned device[MAX_USERS]; diff --git a/libretro_version_1.c b/libretro_version_1.c index 75aae9b0e3..5d4266710e 100644 --- a/libretro_version_1.c +++ b/libretro_version_1.c @@ -266,23 +266,13 @@ static bool input_apply_turbo(unsigned port, unsigned id, bool res) return res; } + static int16_t input_state(unsigned port, unsigned device, unsigned idx, unsigned id) { int16_t res = 0; - device &= RETRO_DEVICE_MASK; - - if (g_extern.bsv.movie && g_extern.bsv.movie_playback) - { - int16_t ret; - if (bsv_movie_get_input(g_extern.bsv.movie, &ret)) - return ret; - - g_extern.bsv.movie_end = true; - } - - static const struct retro_keybind *binds[MAX_USERS] = { + static const struct retro_keybind *libretro_input_binds[MAX_USERS] = { g_settings.input.binds[0], g_settings.input.binds[1], g_settings.input.binds[2], @@ -301,10 +291,26 @@ static int16_t input_state(unsigned port, unsigned device, g_settings.input.binds[15], }; + device &= RETRO_DEVICE_MASK; + + if (g_extern.bsv.movie && g_extern.bsv.movie_playback) + { + int16_t ret; + if (bsv_movie_get_input(g_extern.bsv.movie, &ret)) + return ret; + + g_extern.bsv.movie_end = true; + } + + if (g_settings.input.remap_binds_enable) + { + id = g_settings.input.remap_ids[port][id]; + } + if (!driver.block_libretro_input) { if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD))) - res = driver.input->input_state(driver.input_data, binds, port, + res = driver.input->input_state(driver.input_data, libretro_input_binds, port, device, idx, id); #ifdef HAVE_OVERLAY diff --git a/menu/menu_common.h b/menu/menu_common.h index a660fa1fe9..65d85c7d27 100644 --- a/menu/menu_common.h +++ b/menu/menu_common.h @@ -150,7 +150,7 @@ typedef enum MENU_SETTINGS_CHEAT_BEGIN, MENU_SETTINGS_CHEAT_END = MENU_SETTINGS_CHEAT_BEGIN + (MAX_CHEAT_COUNTERS - 1), MENU_SETTINGS_INPUT_DESC_BEGIN, - MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + (RARCH_MENU_TOGGLE), + MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + (MAX_USERS * RARCH_CUSTOM_BIND_LIST_END), } menu_settings_t; void *menu_init(const void *data); diff --git a/menu/menu_entries_cbs.c b/menu/menu_entries_cbs.c index 87c3256a09..597e4d4c69 100644 --- a/menu/menu_entries_cbs.c +++ b/menu/menu_entries_cbs.c @@ -845,12 +845,14 @@ static int action_start_performance_counters_core(unsigned type, const char *lab static int action_start_input_desc(unsigned type, const char *label, unsigned action) { - unsigned offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN; + unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN; + unsigned inp_desc_user = inp_desc_index_offset / RARCH_FIRST_CUSTOM_BIND; + unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * RARCH_FIRST_CUSTOM_BIND); (void)label; (void)action; - RARCH_LOG("label is: %s, offset is: %u\n", label, offset); + g_settings.input.remap_ids[inp_desc_user][inp_desc_button_index_offset] = g_settings.input.binds[inp_desc_user][inp_desc_button_index_offset].id; return 0; } @@ -982,6 +984,28 @@ static int action_toggle_cheat(unsigned type, const char *label, return 0; } +static int action_toggle_input_desc(unsigned type, const char *label, + unsigned action) +{ + unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN; + unsigned inp_desc_user = inp_desc_index_offset / RARCH_FIRST_CUSTOM_BIND; + unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * RARCH_FIRST_CUSTOM_BIND); + + switch (action) + { + case MENU_ACTION_LEFT: + if (g_settings.input.remap_ids[inp_desc_user][inp_desc_button_index_offset] > 0) + g_settings.input.remap_ids[inp_desc_user][inp_desc_button_index_offset]--; + break; + case MENU_ACTION_RIGHT: + if (g_settings.input.remap_ids[inp_desc_user][inp_desc_button_index_offset] < RARCH_FIRST_CUSTOM_BIND) + g_settings.input.remap_ids[inp_desc_user][inp_desc_button_index_offset]++; + break; + } + + return 0; +} + #ifdef HAVE_SHADER_MANAGER extern size_t hack_shader_pass; #endif @@ -2030,13 +2054,14 @@ static int deferred_push_core_input_remapping_options(void *data, void *userdata for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++) { char desc_label[64]; + unsigned user = p + 1; const char *description = g_extern.system.input_desc_btn[p][retro_id]; if (!description) continue; - snprintf(desc_label, sizeof(desc_label), "User %u %s : ", p + 1, description); - menu_list_push(list, desc_label, "", MENU_SETTINGS_INPUT_DESC_BEGIN + retro_id, p); + snprintf(desc_label, sizeof(desc_label), "User %u %s : ", user, description); + menu_list_push(list, desc_label, "", MENU_SETTINGS_INPUT_DESC_BEGIN + (p * RARCH_FIRST_CUSTOM_BIND) + retro_id, 0); } } @@ -2646,6 +2671,9 @@ static void menu_entries_cbs_init_bind_toggle(menu_file_list_cbs_t *cbs, else if (type >= MENU_SETTINGS_CHEAT_BEGIN && type <= MENU_SETTINGS_CHEAT_END) cbs->action_toggle = action_toggle_cheat; + else if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN + && type <= MENU_SETTINGS_INPUT_DESC_END) + cbs->action_toggle = action_toggle_input_desc; else if ( !strcmp(label, "core_list") || !strcmp(label, "core_manager_list") || diff --git a/retroarch.cfg b/retroarch.cfg index 20e14c4cf9..ce31ef8a27 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -291,6 +291,9 @@ # Enable or disable the current overlay. # input_overlay_enable = true +# If enabled, overrides the input binds with the remapped binds set for the current core. +# input_remap_binds_enable = true + # Path to input overlay # input_overlay = diff --git a/settings.c b/settings.c index 3cd6590eb4..3328a17be7 100644 --- a/settings.c +++ b/settings.c @@ -445,20 +445,22 @@ static void config_set_defaults(void) g_settings.input.autoconfig_descriptor_label_show = true; g_settings.input.input_descriptor_label_show = input_descriptor_label_show; g_settings.input.input_descriptor_hide_unbound = input_descriptor_hide_unbound; + g_settings.input.remap_binds_enable = true; g_settings.input.max_users = MAX_USERS; rarch_assert(sizeof(g_settings.input.binds[0]) >= sizeof(retro_keybinds_1)); rarch_assert(sizeof(g_settings.input.binds[1]) >= sizeof(retro_keybinds_rest)); memcpy(g_settings.input.binds[0], retro_keybinds_1, sizeof(retro_keybinds_1)); - memcpy(g_settings.input.remap_binds[0], retro_keybinds_1, sizeof(retro_keybinds_1)); for (i = 1; i < MAX_USERS; i++) - { memcpy(g_settings.input.binds[i], retro_keybinds_rest, sizeof(retro_keybinds_rest)); - memcpy(g_settings.input.remap_binds[i], retro_keybinds_rest, - sizeof(retro_keybinds_rest)); + + for (i = 0; i < MAX_USERS; i++) + { + for (j = 0; j < RARCH_BIND_LIST_END; j++) + g_settings.input.remap_ids[i][j] = g_settings.input.binds[i][j].id; } for (i = 0; i < MAX_USERS; i++) @@ -478,8 +480,6 @@ static void config_set_defaults(void) { if (g_settings.input.binds[i][j].valid) rarch_assert(j == g_settings.input.binds[i][j].id); - if (g_settings.input.remap_binds[i][j].valid) - rarch_assert(j == g_settings.input.remap_binds[i][j].id); } g_settings.input.axis_threshold = axis_threshold; @@ -1014,6 +1014,8 @@ static bool config_load_file(const char *path, bool set_defaults) if (!strcmp(g_settings.audio.filter_dir, "default")) *g_settings.audio.filter_dir = '\0'; + CONFIG_GET_BOOL(input.remap_binds_enable, + "input_remap_binds_enable"); CONFIG_GET_FLOAT(input.axis_threshold, "input_axis_threshold"); CONFIG_GET_BOOL(input.netplay_client_swap_input, "netplay_client_swap_input"); @@ -1587,6 +1589,8 @@ bool config_save_file(const char *path) config_set_int(conf, "input_max_users", g_settings.input.max_users); config_set_float(conf, "input_axis_threshold", g_settings.input.axis_threshold); + config_set_bool(conf, "input_remap_binds_enable", + g_settings.input.remap_binds_enable); config_set_bool(conf, "netplay_client_swap_input", g_settings.input.netplay_client_swap_input); config_set_bool(conf, "input_descriptor_label_show", diff --git a/settings_data.c b/settings_data.c index 17aaebd941..e26b0dde7c 100644 --- a/settings_data.c +++ b/settings_data.c @@ -2404,6 +2404,7 @@ void setting_data_get_label(char *type_str, && type <= MENU_SETTINGS_CHEAT_END) { unsigned cheat_index = type - MENU_SETTINGS_CHEAT_BEGIN; + if (cheat_index < g_extern.cheat->buf_size) snprintf(type_str, type_str_size, "%s : (%s)", (g_extern.cheat->cheats[cheat_index].code != NULL) @@ -2411,6 +2412,17 @@ void setting_data_get_label(char *type_str, g_extern.cheat->cheats[cheat_index].state ? "ON" : "OFF" ); } + else if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN + && type <= MENU_SETTINGS_INPUT_DESC_END) + { + unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN; + unsigned inp_desc_user = inp_desc_index_offset / RARCH_FIRST_CUSTOM_BIND; + unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * RARCH_FIRST_CUSTOM_BIND); + + //snprintf(type_str, type_str_size, "user %u, index offset %u", type, inp_desc_user, inp_desc_button_index_offset); + unsigned remap_id = g_settings.input.remap_ids[inp_desc_user][inp_desc_button_index_offset]; + snprintf(type_str, type_str_size, "%s", g_settings.input.binds[inp_desc_user][remap_id].desc); + } else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN && type <= MENU_SETTINGS_PERF_COUNTERS_END) menu_common_setting_set_label_perf(type_str, type_str_size, w, type, @@ -4303,6 +4315,18 @@ static bool setting_data_append_list_input_options( general_read_handler); settings_list_current_add_range(list, list_info, 1, MAX_USERS, 1, true, true); + CONFIG_BOOL( + g_settings.input.remap_binds_enable, + "input_remap_binds_enable", + "Remap Binds Enable", + true, + "OFF", + "ON", + group_info.name, + subgroup_info.name, + general_write_handler, + general_read_handler); + CONFIG_BOOL( g_settings.input.autodetect_enable, "input_autodetect_enable",