From a8d77f618c3291cf2512727addc7cc63ec181c6f Mon Sep 17 00:00:00 2001 From: zoltanvb Date: Wed, 5 Jun 2024 20:36:02 +0200 Subject: [PATCH] Better support for multiple reserved devices of the same kind. --- menu/cbs/menu_cbs_scan.c | 2 +- tasks/task_autodetect.c | 21 +++++++++--- ...est_input_joypad_device_reservation2.ratst | 33 +++++++++++++++++++ .../testinput_device_reservation_test2.cfg | 29 ++++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 tests-other/test_input_joypad_device_reservation2.ratst create mode 100644 tests-other/testinput_device_reservation_test2.cfg diff --git a/menu/cbs/menu_cbs_scan.c b/menu/cbs/menu_cbs_scan.c index 50767265743..c8b55f2f841 100644 --- a/menu/cbs/menu_cbs_scan.c +++ b/menu/cbs/menu_cbs_scan.c @@ -231,7 +231,7 @@ static int action_scan_input_desc(const char *path, inp_desc_user = (unsigned)(player_no_str - 1); /* This hardcoded value may cause issues if any entries are added on top of the input binds */ - key = (unsigned)(idx - 6); + key = (unsigned)(idx - 8); /* Select the reorderer bind */ key = (key < RARCH_ANALOG_BIND_LIST_END) ? input_config_bind_order[key] : key; diff --git a/tasks/task_autodetect.c b/tasks/task_autodetect.c index c200bd38f13..d6797af8fd5 100644 --- a/tasks/task_autodetect.c +++ b/tasks/task_autodetect.c @@ -383,7 +383,7 @@ static void reallocate_port_if_needed(unsigned detected_port, int vendor_id, for (player = 0; player < MAX_USERS; player++) { - if (first_free_player_slot > settings->uints.input_max_users && + if (first_free_player_slot > MAX_USERS && ( detected_port == settings->uints.input_joypad_index[player] || !input_config_get_device_name(settings->uints.input_joypad_index[player])) && settings->uints.input_device_reservation_type[player] != INPUT_DEVICE_RESERVATION_RESERVED ) @@ -437,8 +437,21 @@ static void reallocate_port_if_needed(unsigned detected_port, int vendor_id, if (device_has_reserved_slot) { - RARCH_DBG("[Autoconf]: Reserved device matched\n"); - break; + unsigned prev_assigned_port = settings->uints.input_joypad_index[player]; + if ( detected_port != prev_assigned_port && + !string_is_empty(input_config_get_device_name(prev_assigned_port)) && + (( settings_value_vendor_id == input_config_get_device_vid(prev_assigned_port) && + settings_value_product_id == input_config_get_device_pid(prev_assigned_port)) || + strcmp(input_config_get_device_name(prev_assigned_port), settings_value_device_name) == 0)) + { + RARCH_DBG("[Autoconf]: Same type of device already took this slot, continuing search\n"); + device_has_reserved_slot = false; + } + else + { + RARCH_DBG("[Autoconf]: Reserved device matched\n"); + break; + } } } } @@ -481,7 +494,7 @@ static void reallocate_port_if_needed(unsigned detected_port, int vendor_id, } else { - RARCH_DBG("[Autoconf]: Device \"%s\" (%d:%d) is not reserved for " + RARCH_DBG("[Autoconf]: Device \"%s\" (%x:%x) is not reserved for " "any player slot.\n", device_name, vendor_id, product_id); /* Fallback in case no reservation is set up at all - to preserve any previous setup where input_joypad_index may have been customized. */ diff --git a/tests-other/test_input_joypad_device_reservation2.ratst b/tests-other/test_input_joypad_device_reservation2.ratst new file mode 100644 index 00000000000..afeaccf3964 --- /dev/null +++ b/tests-other/test_input_joypad_device_reservation2.ratst @@ -0,0 +1,33 @@ +[ +{ + "action": 1, + "param_num": 0, + "param_str": "(0001:0002) Test joypad device A", + "frame": 0 +}, +{ + "action": 1, + "param_num": 1, + "param_str": "(0003:0004) Test joypad device B" +}, +{ + "action": 1, + "param_num": 2, + "param_str": "(0005:0006) Test joypad device C" +}, +{ + "action": 1, + "param_num": 3, + "param_str": "(0005:0006) Test joypad device C" +}, +{ + "action": 1, + "param_num": 4, + "param_str": "(0005:0006) Test joypad device C" +}, +{ + "action": 1, + "param_num": 5, + "param_str": "(0005:0006) Test joypad device C" +} +] diff --git a/tests-other/testinput_device_reservation_test2.cfg b/tests-other/testinput_device_reservation_test2.cfg new file mode 100644 index 00000000000..7be535a878b --- /dev/null +++ b/tests-other/testinput_device_reservation_test2.cfg @@ -0,0 +1,29 @@ +# Test configuration file to be used with --appendconfig. +# Sets up joypad driver, test input file for the joypad driver, +# logging and autoconfig dir, and prevents saving. +# Usage: +# retroarch --appendconfig tests_other/testinput_device_reservation_test.cfg\|tests_other/all_binds_empty.cfg + +# Test scenario: +# - Player 1 through 4 has preferred device C +# - Player 5 and 6 has no reserved device +# - Connect controller A, then B, then 4 instances of C +# - VALIDATE: check that Player 1 - C (1), Player 2 - C(2), Player 3 - C(3), Player 4 - C(4), +# Player 5 - A, Player 6 - B + +input_joypad_driver = "test" +test_input_file_joypad = "tests-other/test_input_joypad_device_reservation2.ratst" +joypad_autoconfig_dir = "tests-other/autoconf" +frontend_log_level = "0" +libretro_log_level = "0" +log_verbosity = "true" +config_save_on_exit = "false" +input_player1_reserved_device = "Test joypad device C" +input_player1_device_reservation_type = "2" +input_player2_reserved_device = "Test joypad device C" +input_player2_device_reservation_type = "2" +input_player3_reserved_device = "0005:0006 Test joypad device C" +input_player3_device_reservation_type = "2" +input_player4_reserved_device = "0005:0006 " +input_player4_device_reservation_type = "2" +# input_max_users = "3" \ No newline at end of file