From 5419757c4017c35963bd3e9241ee4760b9468791 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 24 Jan 2015 23:42:31 +0100 Subject: [PATCH] Add input remapping saving/loading --- general.h | 2 ++ input/input_remapping.c | 3 +++ retroarch.c | 18 ++++++++++++++++++ retroarch.cfg | 3 +++ retroarch.h | 2 ++ settings.c | 20 ++++++++++++-------- settings_data.c | 3 +++ 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/general.h b/general.h index 03298bb1a3..cf6f77849a 100644 --- a/general.h +++ b/general.h @@ -304,6 +304,8 @@ struct settings bool autoconfig_descriptor_label_show; bool input_descriptor_label_show; bool input_descriptor_hide_unbound; + + char remapping_path[PATH_MAX_LENGTH]; } input; struct diff --git a/input/input_remapping.c b/input/input_remapping.c index 4a43695edd..b1156fdc63 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -36,6 +36,9 @@ bool input_remapping_load_file(const char *path) if (!conf) return false; + strlcpy(g_settings.input.remapping_path, path, + sizeof(g_settings.input.remapping_path)); + for (i = 0; i < MAX_USERS; i++) { char buf[64]; diff --git a/retroarch.c b/retroarch.c index 7bab577109..556e6357ad 100644 --- a/retroarch.c +++ b/retroarch.c @@ -36,7 +36,10 @@ #include "cheats.h" #include #include + #include "input/keyboard_line.h" +#include "input/input_remapping.h" + #include "git_version.h" #include "intl/intl.h" @@ -1182,6 +1185,14 @@ static void save_files(void) } } +static void init_remapping(void) +{ + if (!g_settings.input.remap_binds_enable) + return; + + input_remapping_load_file(g_settings.input.remapping_path); +} + static void init_cheats(void) { bool allow_cheats = true; @@ -2179,6 +2190,7 @@ int rarch_main_init(int argc, char *argv[]) rarch_main_command(RARCH_CMD_CONTROLLERS_INIT); rarch_main_command(RARCH_CMD_RECORD_INIT); rarch_main_command(RARCH_CMD_CHEATS_INIT); + rarch_main_command(RARCH_CMD_REMAPPING_INIT); rarch_main_command(RARCH_CMD_SAVEFILES_INIT); @@ -2560,6 +2572,12 @@ bool rarch_main_command(unsigned cmd) rarch_main_command(RARCH_CMD_CHEATS_DEINIT); init_cheats(); break; + case RARCH_CMD_REMAPPING_DEINIT: + break; + case RARCH_CMD_REMAPPING_INIT: + rarch_main_command(RARCH_CMD_REMAPPING_DEINIT); + init_remapping(); + break; case RARCH_CMD_REWIND_DEINIT: #ifdef HAVE_NETPLAY if (driver.netplay_data) diff --git a/retroarch.cfg b/retroarch.cfg index 78ce742267..d6aed9e2a2 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -317,6 +317,9 @@ # Joypad driver. (Valid: linuxraw, sdl, dinput) # input_joypad_driver = +# Path to input remapping file. +# input_remapping_path = + # Maximum amount of users supported by RetroArch. # input_max_users = 16 diff --git a/retroarch.h b/retroarch.h index d0685ae070..eaf82cca1e 100644 --- a/retroarch.h +++ b/retroarch.h @@ -186,6 +186,8 @@ enum basic_event /* Toggles fullscreen mode. */ RARCH_CMD_FULLSCREEN_TOGGLE, RARCH_CMD_PERFCNT_REPORT_FRONTEND_LOG, + RARCH_CMD_REMAPPING_INIT, + RARCH_CMD_REMAPPING_DEINIT, }; enum action_state diff --git a/settings.c b/settings.c index bf28862eaa..b3dd7d55e2 100644 --- a/settings.c +++ b/settings.c @@ -1322,6 +1322,8 @@ static bool config_load_file(const char *path, bool set_defaults) } } + CONFIG_GET_PATH(input.remapping_path, "input_remapping_path"); + CONFIG_GET_PATH(resampler_directory, "resampler_directory"); CONFIG_GET_PATH(extraction_directory, "extraction_directory"); CONFIG_GET_PATH(input_remapping_directory, "input_remapping_directory"); @@ -1556,25 +1558,25 @@ static void config_load_core_specific(void) static void parse_config_file(void) { - bool ret; + bool ret = config_load_file((*g_extern.config_path) + ? g_extern.config_path : NULL, false); + if (*g_extern.config_path) { RARCH_LOG("Loading config from: %s.\n", g_extern.config_path); - ret = config_load_file(g_extern.config_path, false); } else { RARCH_LOG("Loading default config.\n"); - ret = config_load_file(NULL, false); if (*g_extern.config_path) RARCH_LOG("Found default config: %s.\n", g_extern.config_path); } - if (!ret) - { - RARCH_ERR("Couldn't find config at path: \"%s\"\n", - g_extern.config_path); - } + if (ret) + return; + + RARCH_ERR("Couldn't find config at path: \"%s\"\n", + g_extern.config_path); } @@ -1921,6 +1923,8 @@ bool config_save_file(const char *path) g_settings.extraction_directory); config_set_path(conf, "input_remapping_directory", g_settings.input_remapping_directory); + config_set_path(conf, "input_remapping_path", + g_settings.input.remapping_path); config_set_path(conf, "resampler_directory", g_settings.resampler_directory); config_set_string(conf, "audio_resampler", g_settings.audio.resampler); diff --git a/settings_data.c b/settings_data.c index 7aa94c4533..6eee664d15 100644 --- a/settings_data.c +++ b/settings_data.c @@ -2905,6 +2905,9 @@ void setting_data_get_label(char *type_str, #endif if (!strcmp(label, "cheat_num_passes")) snprintf(type_str, type_str_size, "%u", g_extern.cheat->buf_size); + else if (!strcmp(label, "remap_file_load")) + fill_pathname_base(type_str, g_settings.input.remapping_path, + type_str_size); else if (type >= MENU_SETTINGS_CHEAT_BEGIN && type <= MENU_SETTINGS_CHEAT_END) {