Skip to content

Commit

Permalink
Better support for multiple reserved devices of the same kind.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanvb authored and LibretroAdmin committed Jun 5, 2024
1 parent a9968e9 commit a8d77f6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
2 changes: 1 addition & 1 deletion menu/cbs/menu_cbs_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 17 additions & 4 deletions tasks/task_autodetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -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. */
Expand Down
33 changes: 33 additions & 0 deletions tests-other/test_input_joypad_device_reservation2.ratst
Original file line number Diff line number Diff line change
@@ -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"
}
]
29 changes: 29 additions & 0 deletions tests-other/testinput_device_reservation_test2.cfg
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a8d77f6

Please sign in to comment.