From 7c3d07bf6dddf20f0861b0d7a8eb7e540d869200 Mon Sep 17 00:00:00 2001 From: Bobby Smith <33353403+bslenul@users.noreply.github.com> Date: Fri, 2 Feb 2024 21:53:24 +0100 Subject: [PATCH] Tweaks to how the "Analog to Digital Type" setting is saved (#16187) --- input/input_driver.c | 7 ++++--- input/input_remapping.h | 13 +++++++++---- retroarch.c | 25 +++++++++++++------------ runloop.c | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index d112eb9049..74d9e74bb8 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -6062,7 +6062,7 @@ void input_remapping_cache_global_config(void) | INP_FLAG_OLD_LIBRETRO_DEVICE_SET; } -void input_remapping_restore_global_config(bool clear_cache) +void input_remapping_restore_global_config(bool clear_cache, bool restore_analog_dpad_mode) { unsigned i; settings_t *settings = config_get_ptr(); @@ -6073,7 +6073,8 @@ void input_remapping_restore_global_config(bool clear_cache) for (i = 0; i < MAX_USERS; i++) { - if ((input_st->flags & INP_FLAG_OLD_ANALOG_DPAD_MODE_SET) + if ( (input_st->flags & INP_FLAG_OLD_ANALOG_DPAD_MODE_SET) + && restore_analog_dpad_mode && (settings->uints.input_analog_dpad_mode[i] != input_st->old_analog_dpad_mode[i])) configuration_set_uint(settings, @@ -6195,7 +6196,7 @@ void input_remapping_set_defaults(bool clear_cache) * the last core init * > Prevents remap changes from 'bleeding through' * into the main config file */ - input_remapping_restore_global_config(clear_cache); + input_remapping_restore_global_config(clear_cache, true); } void input_driver_collect_system_input(input_driver_state_t *input_st, diff --git a/input/input_remapping.h b/input/input_remapping.h index 4dfb43bd49..57736e356c 100644 --- a/input/input_remapping.h +++ b/input/input_remapping.h @@ -58,11 +58,16 @@ void input_remapping_cache_global_config(void); * init if INP_FLAG_REMAPPING_CACHE_ACTIVE is set. * Must be called on core deinitialization. * - * @param clear_cache If true, function becomes a NOOP until the next time - * `input_remapping_cache_global_config()` is called, and - * INP_FLAG_REMAPPING_CACHE_ACTIVE is set. + * @param clear_cache If true, function becomes a NOOP until the next time + * `input_remapping_cache_global_config()` is called, and + * INP_FLAG_REMAPPING_CACHE_ACTIVE is set. + * @param restore_analog_dpad_mode Treat 'Analog to Digital Type' like a regular setting, + * meaning this should be false when we're not using any + * remap file so its value is saved globally on close/quit, + * and it should be true when we're using a remap or if + * we're resetting settings, to restore its global value. */ -void input_remapping_restore_global_config(bool clear_cache); +void input_remapping_restore_global_config(bool clear_cache, bool restore_analog_dpad_mode); /** * Must be called whenever `settings->uints.input_remap_ports` is modified. diff --git a/retroarch.c b/retroarch.c index b9e9aa5f30..a15e24872e 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3666,7 +3666,7 @@ bool command_event(enum event_command cmd, void *data) input_remapping_set_defaults(true); } else - input_remapping_restore_global_config(true); + input_remapping_restore_global_config(true, false); #ifdef HAVE_CONFIGFILE if (runloop_st->flags & RUNLOOP_FLAG_OVERRIDES_ACTIVE) @@ -7578,7 +7578,7 @@ bool retroarch_main_init(int argc, char *argv[]) input_remapping_set_defaults(true); } else - input_remapping_restore_global_config(true); + input_remapping_restore_global_config(true, false); #ifdef HAVE_CONFIGFILE /* Reload the original config */ @@ -8155,15 +8155,6 @@ bool retroarch_main_quit(void) } if (!(runloop_st->flags & RUNLOOP_FLAG_SHUTDOWN_INITIATED)) { - /* Save configs before quitting - * as for UWP depending on `OnSuspending` is not important as we can call it directly here - * specifically we need to get width,height which requires UI thread and it will not be available on exit - */ -#if defined(HAVE_DYNAMIC) - if (config_save_on_exit) - command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL); -#endif - if (settings->bools.savestate_auto_save && runloop_st->current_core_type != CORE_TYPE_DUMMY) command_event_save_auto_state(); @@ -8183,7 +8174,7 @@ bool retroarch_main_quit(void) input_remapping_set_defaults(true); } else - input_remapping_restore_global_config(true); + input_remapping_restore_global_config(true, false); #ifdef HAVE_CONFIGFILE if (runloop_st->flags & RUNLOOP_FLAG_OVERRIDES_ACTIVE) @@ -8192,6 +8183,16 @@ bool retroarch_main_quit(void) config_unload_override(); } #endif + + /* Save configs before quitting + * as for UWP depending on `OnSuspending` is not important as we can call it directly here + * specifically we need to get width,height which requires UI thread and it will not be available on exit + */ +#if defined(HAVE_DYNAMIC) + if (config_save_on_exit) + command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL); +#endif + #if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL) runloop_st->runtime_shader_preset_path[0] = '\0'; #endif diff --git a/runloop.c b/runloop.c index 0a9d177853..938323ba3d 100644 --- a/runloop.c +++ b/runloop.c @@ -4088,7 +4088,7 @@ void runloop_event_deinit_core(void) input_remapping_set_defaults(true); } else - input_remapping_restore_global_config(true); + input_remapping_restore_global_config(true, false); RARCH_LOG("[Core]: Unloading core symbols..\n"); uninit_libretro_symbols(&runloop_st->current_core);