Revert "[Switch] Really fix splitting/joining JoyCons via single option"

This commit is contained in:
Twinaphex 2019-08-26 14:22:58 +02:00 committed by GitHub
parent 045a4cce10
commit 1091193ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 139 additions and 106 deletions

View File

@ -1775,7 +1775,14 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
SETTING_UINT("rgui_particle_effect", &settings->uints.menu_rgui_particle_effect, true, rgui_particle_effect, false);
#endif
#ifdef HAVE_LIBNX
SETTING_UINT("split_joycon", &settings->uints.input_split_joycon, true, 0, false);
SETTING_UINT("split_joycon_p1", &settings->uints.input_split_joycon[0], true, 0, false);
SETTING_UINT("split_joycon_p2", &settings->uints.input_split_joycon[1], true, 0, false);
SETTING_UINT("split_joycon_p3", &settings->uints.input_split_joycon[2], true, 0, false);
SETTING_UINT("split_joycon_p4", &settings->uints.input_split_joycon[3], true, 0, false);
SETTING_UINT("split_joycon_p5", &settings->uints.input_split_joycon[4], true, 0, false);
SETTING_UINT("split_joycon_p6", &settings->uints.input_split_joycon[5], true, 0, false);
SETTING_UINT("split_joycon_p7", &settings->uints.input_split_joycon[6], true, 0, false);
SETTING_UINT("split_joycon_p8", &settings->uints.input_split_joycon[7], true, 0, false);
#endif
#ifdef HAVE_XMB
SETTING_UINT("menu_xmb_animation_opening_main_menu", &settings->uints.menu_xmb_animation_opening_main_menu, true, 0 /* TODO/FIXME - implement */, false);

View File

@ -543,7 +543,7 @@ typedef struct settings
unsigned input_overlay_show_physical_inputs_port;
unsigned input_split_joycon;
unsigned input_split_joycon[MAX_USERS];
unsigned input_joypad_map[MAX_USERS];
unsigned input_device[MAX_USERS];
unsigned input_mouse_index[MAX_USERS];

View File

@ -29,7 +29,7 @@ static HidVibrationValue vibration_values[DEFAULT_MAX_PADS][2];
static HidVibrationValue vibration_stop;
static int previous_handheld = -1;
/* 1 = handheld, 0 = docked, -1 = first use */
static uint previous_split_joycon_setting = { -1 };
static uint previous_split_joycon_setting[MAX_USERS] = { 0 };
#endif
static const char *switch_joypad_name(unsigned pad)
@ -166,7 +166,8 @@ static void switch_joypad_destroy(void)
previous_handheld = -1;
previous_split_joycon_setting = 0;
for (i = 0; i < MAX_USERS; i++)
previous_split_joycon_setting[i] = 0;
for (i = 0; i < DEFAULT_MAX_PADS; i++)
{
@ -184,46 +185,6 @@ static void switch_joypad_destroy(void)
#ifdef HAVE_LIBNX
static void switch_split_joycons(void)
{
unsigned i;
for (i = 0; i < MAX_USERS; i += 2)
{
hidSetNpadJoyAssignmentModeSingleByDefault(i);
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
}
}
static void switch_join_joycons(void)
{
/* find all left/right single JoyCon pairs and join them together */
int id, id_0, id_1;
int last_right_id = MAX_USERS;
for (id = 0; id < MAX_USERS; id++)
hidSetNpadJoyAssignmentModeDual(id);
for (id_0 = 0; id_0 < MAX_USERS; id_0++)
{
if (hidGetControllerType(id_0) & TYPE_JOYCON_LEFT)
{
for (id_1 = last_right_id - 1; id_1 >= 0; id_1--)
{
if (hidGetControllerType(id_1) & TYPE_JOYCON_RIGHT)
{
/* prevent missing player numbers */
last_right_id = id_1;
if (id_0 < id_1)
hidMergeSingleJoyAsDualJoy(id_0, id_1);
else if (id_0 > id_1)
hidMergeSingleJoyAsDualJoy(id_1, id_0);
break;
}
}
}
}
}
static void switch_joypad_poll(void)
{
int i, handheld;
@ -231,49 +192,106 @@ static void switch_joypad_poll(void)
hidScanInput();
/* handheld means the Switch is neither docked nor in tabletop mode */
/* e.g. it is used held in hands with both joycons attached */
handheld = hidGetHandheldMode();
if (previous_handheld == -1)
{
/* first call of this function, apply joycon settings
* according to preferences */
if (!handheld && settings->uints.input_split_joycon)
switch_split_joycons();
else
switch_join_joycons();
/* First call of this function, apply joycon settings
* according to preferences, init variables */
if (!handheld)
{
for (i = 0; i < MAX_USERS; i += 2)
{
if (settings->uints.input_split_joycon[i])
{
hidSetNpadJoyAssignmentModeSingleByDefault(i);
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
}
else if (!settings->uints.input_split_joycon[i])
{
hidSetNpadJoyAssignmentModeDual(i);
hidSetNpadJoyAssignmentModeDual(i + 1);
hidMergeSingleJoyAsDualJoy(i, i + 1);
}
}
}
previous_handheld = handheld;
for (i = 0; i < MAX_USERS; i += 2)
previous_split_joycon_setting[i] = settings->uints.input_split_joycon[i];
}
else
if (!handheld && previous_handheld)
{
if (!handheld && previous_handheld)
/* switching out of handheld, so make sure
* joycons are correctly split. */
for (i = 0; i < MAX_USERS; i += 2)
{
/* switching out of handheld, so make sure
* joycons are correctly split. */
if (settings->uints.input_split_joycon)
switch_split_joycons();
}
else if (handheld && !previous_handheld)
{
/* switching into handheld, so make sure all split joycons are joined */
switch_join_joycons();
}
else if (!handheld)
{
/* the user might have changed the split joycon setting, so respond */
if (settings->uints.input_split_joycon && !previous_split_joycon_setting)
/* CONTROLLER_PLAYER_X, X == i++ */
if (settings->uints.input_split_joycon[i])
{
/* setting changed from unsplit to split, so split them all */
switch_split_joycons();
}
else if (!settings->uints.input_split_joycon && previous_split_joycon_setting)
{
/* setting changed from split to unsplit, so join them all */
switch_join_joycons();
hidSetNpadJoyAssignmentModeSingleByDefault(i);
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
}
}
}
previous_split_joycon_setting = settings->uints.input_split_joycon;
else if (handheld && !previous_handheld)
{
/* switching into handheld, so make sure all split joycons are joined */
for (i = 0; i < MAX_USERS; i += 2)
{
/* find all left/right single JoyCon pairs and join them together */
int id, id_0, id_1;
int last_right_id = MAX_USERS;
for (id = 0; id < MAX_USERS; id++)
hidSetNpadJoyAssignmentModeDual(id);
for (id_0 = 0; id_0 < MAX_USERS; id_0++)
{
if (hidGetControllerType(id_0) & TYPE_JOYCON_LEFT)
{
for (id_1 = last_right_id - 1; id_1 >= 0; id_1--)
{
if (hidGetControllerType(id_1) & TYPE_JOYCON_RIGHT)
{
/* prevent missing player numbers */
last_right_id = id_1;
if (id_0 < id_1)
hidMergeSingleJoyAsDualJoy(id_0, id_1);
else if (id_0 > id_1)
hidMergeSingleJoyAsDualJoy(id_1, id_0);
break;
}
}
}
}
}
}
else if (!handheld)
{
/* split or join joycons every time the user changes a setting */
for (i = 0; i < MAX_USERS; i += 2)
{
if ( settings->uints.input_split_joycon[i]
&& !previous_split_joycon_setting[i])
{
hidSetNpadJoyAssignmentModeSingleByDefault(i);
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
}
else if (!settings->uints.input_split_joycon[i]
&& previous_split_joycon_setting[i])
{
hidSetNpadJoyAssignmentModeDual(i);
hidSetNpadJoyAssignmentModeDual(i + 1);
hidMergeSingleJoyAsDualJoy(i, i + 1);
}
}
}
for (i = 0; i < MAX_USERS; i += 2)
previous_split_joycon_setting[i] = settings->uints.input_split_joycon[i];
previous_handheld = handheld;
for (i = 0; i < DEFAULT_MAX_PADS; i++)

View File

@ -3728,7 +3728,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"Title of Stream")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3504,7 +3504,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"串流名稱")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3633,7 +3633,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"Streamtitel")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3392,7 +3392,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"Title of Stream")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -8863,7 +8863,7 @@ MSG_HASH(
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3382,7 +3382,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"Titel van Stream")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -8697,7 +8697,7 @@ MSG_HASH(
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3458,7 +3458,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"Title of Stream")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3656,7 +3656,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"Title of Stream")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -8761,7 +8761,7 @@ MSG_HASH(
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3546,7 +3546,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
"Title of Stream")
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
"Split Joy-Cons"
"Split Joy-Con"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

View File

@ -3835,17 +3835,23 @@ unsigned menu_displaylist_build_list(file_list_t *list, enum menu_displaylist_ct
#ifdef HAVE_LIBNX
{
char key_split_joycon[PATH_MAX_LENGTH];
unsigned user;
key_split_joycon[0] = '\0';
for (user = 0; user < 8; user++)
{
char key_split_joycon[PATH_MAX_LENGTH];
unsigned val = user + 1;
snprintf(key_split_joycon, sizeof(key_split_joycon),
"%s",
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON));
key_split_joycon[0] = '\0';
if (menu_displaylist_parse_settings(list,
key_split_joycon, PARSE_ONLY_UINT, true, 0) != -1)
count++;
snprintf(key_split_joycon, sizeof(key_split_joycon),
"%s_%u",
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON), val);
if (menu_displaylist_parse_settings(list,
key_split_joycon, PARSE_ONLY_UINT, true, 0) != -1)
count++;
}
}
#endif

View File

@ -5763,7 +5763,8 @@ static void get_string_representation_split_joycon(rarch_setting_t *setting, cha
size_t len)
{
settings_t *settings = config_get_ptr();
unsigned map = settings->uints.input_split_joycon;
unsigned index_offset = setting->index_offset;
unsigned map = settings->uints.input_split_joycon[index_offset];
if (map == 0)
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF), len);
@ -6489,8 +6490,8 @@ static bool setting_append_list_input_player_options(
static char key_analog[MAX_USERS][64];
static char key_bind_all[MAX_USERS][64];
static char key_bind_all_save_autoconfig[MAX_USERS][64];
static char split_joycon[64];
static char split_joycon_lbl[64];
static char split_joycon[MAX_USERS][64];
static char split_joycon_lbl[MAX_USERS][64];
static char key_bind_defaults[MAX_USERS][64];
static char mouse_index[MAX_USERS][64];
@ -6514,9 +6515,10 @@ static bool setting_append_list_input_player_options(
snprintf(key_analog[user], sizeof(key_analog[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE),
user + 1);
snprintf(split_joycon, sizeof(split_joycon),
"%s",
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON));
snprintf(split_joycon[user], sizeof(split_joycon[user]),
"%s_%u",
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON),
user + 1);
fill_pathname_join_delim(key_bind_all[user], tmp_string, "bind_all", '_',
sizeof(key_bind_all[user]));
fill_pathname_join_delim(key_bind_all_save_autoconfig[user],
@ -6528,8 +6530,8 @@ static bool setting_append_list_input_player_options(
fill_pathname_join_delim(mouse_index[user], tmp_string, "mouse_index", '_',
sizeof(mouse_index[user]));
snprintf(split_joycon_lbl, sizeof(label),
"%s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON));
snprintf(split_joycon_lbl[user], sizeof(label[user]),
"%s %u", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON), user + 1);
snprintf(label[user], sizeof(label[user]),
"%s %u %s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), user + 1,
@ -6602,9 +6604,9 @@ static bool setting_append_list_input_player_options(
#ifdef HAVE_LIBNX
CONFIG_UINT_ALT(
list, list_info,
&settings->uints.input_split_joycon,
split_joycon,
split_joycon_lbl,
&settings->uints.input_split_joycon[user],
split_joycon[user],
split_joycon_lbl[user],
user,
&group_info,
&subgroup_info,