Simplify code

This commit is contained in:
twinaphex 2018-09-25 01:37:15 +02:00
parent 390cb578a9
commit 1631577b8e

View File

@ -657,6 +657,7 @@ static int setting_string_action_left_netplay_mitm_server(
void *data, bool wraparound) void *data, bool wraparound)
{ {
int i; int i;
int offset = 0;
bool found = false; bool found = false;
unsigned list_len = ARRAY_SIZE(netplay_mitm_server_list); unsigned list_len = ARRAY_SIZE(netplay_mitm_server_list);
rarch_setting_t *setting = (rarch_setting_t*)data; rarch_setting_t *setting = (rarch_setting_t*)data;
@ -672,21 +673,24 @@ static int setting_string_action_left_netplay_mitm_server(
if (i - 1 >= 0) if (i - 1 >= 0)
{ {
found = true; found = true;
strlcpy(setting->value.target.string, netplay_mitm_server_list[i - 1].name, sizeof(setting->value.target.string)); offset = i - 1;
break;
} }
else if (wraparound) else if (wraparound)
{ {
found = true; found = true;
strlcpy(setting->value.target.string, netplay_mitm_server_list[list_len - 1].name, sizeof(setting->value.target.string)); offset = list_len - 1;
break;
} }
if (found)
break;
} }
} }
/* current entry was invalid, go back to the end */ /* current entry was invalid, go back to the end */
if (!found) if (!found)
strlcpy(setting->value.target.string, netplay_mitm_server_list[list_len - 1].name, sizeof(setting->value.target.string)); offset = list_len - 1;
strlcpy(setting->value.target.string, netplay_mitm_server_list[offset].name, sizeof(setting->value.target.string));
return 0; return 0;
} }
@ -695,6 +699,7 @@ static int setting_string_action_right_netplay_mitm_server(
void *data, bool wraparound) void *data, bool wraparound)
{ {
unsigned i; unsigned i;
int offset = 0;
bool found = false; bool found = false;
unsigned list_len = ARRAY_SIZE(netplay_mitm_server_list); unsigned list_len = ARRAY_SIZE(netplay_mitm_server_list);
rarch_setting_t *setting = (rarch_setting_t*)data; rarch_setting_t *setting = (rarch_setting_t*)data;
@ -709,22 +714,22 @@ static int setting_string_action_right_netplay_mitm_server(
/* move to the next one in the list, wrap around if necessary */ /* move to the next one in the list, wrap around if necessary */
if (i + 1 < list_len) if (i + 1 < list_len)
{ {
offset = i + 1;
found = true; found = true;
strlcpy(setting->value.target.string, netplay_mitm_server_list[i + 1].name, sizeof(setting->value.target.string));
break;
} }
else if (wraparound) else if (wraparound)
{
found = true; found = true;
strlcpy(setting->value.target.string, netplay_mitm_server_list[0].name, sizeof(setting->value.target.string));
if (found)
break; break;
} }
} }
}
/* current entry was invalid, go back to the start */ /* current entry was invalid, go back to the start */
if (!found) if (!found)
strlcpy(setting->value.target.string, netplay_mitm_server_list[0].name, sizeof(setting->value.target.string)); offset = 0;
strlcpy(setting->value.target.string, netplay_mitm_server_list[offset].name, sizeof(setting->value.target.string));
return 0; return 0;
} }