Get rid of global->netplay

Moved settings values into settings->netplay, and global->netplay.enable
is moved into netplay itself, and is no longer a configuration value
whatsoever, as that conflicts with the behavior of the netplay menu.
This commit is contained in:
Gregor Richards 2016-10-02 22:13:34 -04:00
parent f6a1eb65bb
commit e41ac34561
12 changed files with 121 additions and 115 deletions

View File

@ -32,6 +32,10 @@
#include "../record/record_driver.h" #include "../record/record_driver.h"
#include "audio_thread_wrapper.h" #include "audio_thread_wrapper.h"
#ifdef HAVE_NETWORKING
#include "network/netplay/netplay.h"
#endif
#include "../command.h" #include "../command.h"
#include "../driver.h" #include "../driver.h"
#include "../configuration.h" #include "../configuration.h"
@ -855,8 +859,7 @@ bool audio_driver_set_callback(const void *data)
{ {
const struct retro_audio_callback *cb = (const struct retro_audio_callback*)data; const struct retro_audio_callback *cb = (const struct retro_audio_callback*)data;
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
global_t *global = global_get_ptr(); if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
if (global->netplay.enable)
return false; return false;
#endif #endif

View File

@ -1209,7 +1209,7 @@ static void command_event_load_auto_state(void)
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (global->netplay.enable && !global->netplay.is_spectate) if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) && !settings->netplay.is_spectate)
return; return;
#endif #endif
@ -1312,8 +1312,7 @@ static bool event_init_content(void)
if (content_does_not_need_content()) if (content_does_not_need_content())
{ {
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
global_t *global = global_get_ptr(); if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
if (global->netplay.enable)
RARCH_ERR("sorry, unimplemented: cores that don't demand content cannot participate in netplay\n"); RARCH_ERR("sorry, unimplemented: cores that don't demand content cannot participate in netplay\n");
#endif #endif
return true; return true;
@ -2351,7 +2350,9 @@ bool command_event(enum event_command cmd, void *data)
case CMD_EVENT_NETPLAY_INIT: case CMD_EVENT_NETPLAY_INIT:
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (!init_netplay()) if (!init_netplay(settings->netplay.is_client,
settings->netplay.is_spectate, settings->netplay.server,
settings->netplay.port))
return false; return false;
#endif #endif
break; break;

View File

@ -587,7 +587,7 @@ static int populate_settings_path(settings_t *settings, struct config_path_setti
SETTING_PATH("core_updater_buildbot_url", settings->network.buildbot_url, false, NULL, true); SETTING_PATH("core_updater_buildbot_url", settings->network.buildbot_url, false, NULL, true);
SETTING_PATH("core_updater_buildbot_assets_url", settings->network.buildbot_assets_url, false, NULL, true); SETTING_PATH("core_updater_buildbot_assets_url", settings->network.buildbot_assets_url, false, NULL, true);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
SETTING_PATH("netplay_ip_address", global->netplay.server, false, NULL, true); SETTING_PATH("netplay_ip_address", settings->netplay.server, false, NULL, true);
#endif #endif
SETTING_PATH("recording_output_directory", SETTING_PATH("recording_output_directory",
global->record.output_dir, false, NULL, true); global->record.output_dir, false, NULL, true);
@ -702,7 +702,7 @@ static int populate_settings_bool(settings_t *settings, struct config_bool_setti
SETTING_BOOL("input_remap_binds_enable", &settings->input.remap_binds_enable, true, true, false); SETTING_BOOL("input_remap_binds_enable", &settings->input.remap_binds_enable, true, true, false);
SETTING_BOOL("back_as_menu_toggle_enable", &settings->input.back_as_menu_toggle_enable, true, true, false); SETTING_BOOL("back_as_menu_toggle_enable", &settings->input.back_as_menu_toggle_enable, true, true, false);
SETTING_BOOL("all_users_control_menu", &settings->input.all_users_control_menu, true, all_users_control_menu, false); SETTING_BOOL("all_users_control_menu", &settings->input.all_users_control_menu, true, all_users_control_menu, false);
SETTING_BOOL("netplay_client_swap_input", &settings->input.netplay_client_swap_input, true, netplay_client_swap_input, false); SETTING_BOOL("netplay_client_swap_input", &settings->netplay.swap_input, true, netplay_client_swap_input, false);
SETTING_BOOL("input_descriptor_label_show", &settings->input.input_descriptor_label_show, true, input_descriptor_label_show, false); SETTING_BOOL("input_descriptor_label_show", &settings->input.input_descriptor_label_show, true, input_descriptor_label_show, false);
SETTING_BOOL("input_descriptor_hide_unbound", &settings->input.input_descriptor_hide_unbound, true, input_descriptor_hide_unbound, false); SETTING_BOOL("input_descriptor_hide_unbound", &settings->input.input_descriptor_hide_unbound, true, input_descriptor_hide_unbound, false);
SETTING_BOOL("load_dummy_on_core_shutdown", &settings->load_dummy_on_core_shutdown, true, load_dummy_on_core_shutdown, false); SETTING_BOOL("load_dummy_on_core_shutdown", &settings->load_dummy_on_core_shutdown, true, load_dummy_on_core_shutdown, false);
@ -802,8 +802,8 @@ static int populate_settings_bool(settings_t *settings, struct config_bool_setti
SETTING_BOOL("network_remote_enable", &settings->network_remote_enable, false, false /* TODO */, false); SETTING_BOOL("network_remote_enable", &settings->network_remote_enable, false, false /* TODO */, false);
#endif #endif
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
SETTING_BOOL("netplay_spectator_mode_enable",&global->netplay.is_spectate, false, false /* TODO */, false); SETTING_BOOL("netplay_spectator_mode_enable",&settings->netplay.is_spectate, false, false /* TODO */, false);
SETTING_BOOL("netplay_mode", &global->netplay.is_client, false, false /* TODO */, false); SETTING_BOOL("netplay_mode", &settings->netplay.is_client, false, false /* TODO */, false);
#endif #endif
SETTING_BOOL("block_sram_overwrite", &settings->block_sram_overwrite, true, block_sram_overwrite, false); SETTING_BOOL("block_sram_overwrite", &settings->block_sram_overwrite, true, block_sram_overwrite, false);
SETTING_BOOL("savestate_auto_index", &settings->savestate_auto_index, true, savestate_auto_index, false); SETTING_BOOL("savestate_auto_index", &settings->savestate_auto_index, true, savestate_auto_index, false);
@ -932,9 +932,9 @@ static int populate_settings_int(settings_t *settings, struct config_int_setting
SETTING_INT("aspect_ratio_index", &settings->video.aspect_ratio_idx, true, aspect_ratio_idx, false); SETTING_INT("aspect_ratio_index", &settings->video.aspect_ratio_idx, true, aspect_ratio_idx, false);
SETTING_INT("state_slot", (unsigned*)&settings->state_slot, false, 0 /* TODO */, false); SETTING_INT("state_slot", (unsigned*)&settings->state_slot, false, 0 /* TODO */, false);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
SETTING_INT("netplay_ip_port", &global->netplay.port, false, 0 /* TODO */, false); SETTING_INT("netplay_ip_port", &settings->netplay.port, false, 0 /* TODO */, false);
SETTING_INT("netplay_delay_frames", &global->netplay.sync_frames, true, 16, false); SETTING_INT("netplay_delay_frames", &settings->netplay.sync_frames, true, 16, false);
SETTING_INT("netplay_check_frames", &global->netplay.check_frames, false, 0, false); SETTING_INT("netplay_check_frames", &settings->netplay.check_frames, false, 0, false);
#endif #endif
#ifdef HAVE_LANGEXTRA #ifdef HAVE_LANGEXTRA
SETTING_INT("user_language", &settings->user_language, true, RETRO_LANGUAGE_ENGLISH, false); SETTING_INT("user_language", &settings->user_language, true, RETRO_LANGUAGE_ENGLISH, false);
@ -1770,7 +1770,7 @@ static bool config_load_file(const char *path, bool set_defaults,
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL)) if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL))
override_netplay_ip_address = strdup(global->netplay.server); override_netplay_ip_address = strdup(settings->netplay.server);
#endif #endif
/* Boolean settings */ /* Boolean settings */
@ -1811,10 +1811,10 @@ static bool config_load_file(const char *path, bool set_defaults,
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL)) if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL))
CONFIG_GET_BOOL_BASE(conf, global, netplay.is_spectate, CONFIG_GET_BOOL_BASE(conf, settings, netplay.is_spectate,
"netplay_spectator_mode_enable"); "netplay_spectator_mode_enable");
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL)) if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL))
CONFIG_GET_BOOL_BASE(conf, global, netplay.is_client, "netplay_mode"); CONFIG_GET_BOOL_BASE(conf, settings, netplay.is_client, "netplay_mode");
#endif #endif
#ifdef HAVE_NETWORKGAMEPAD #ifdef HAVE_NETWORKGAMEPAD
for (i = 0; i < MAX_USERS; i++) for (i = 0; i < MAX_USERS; i++)
@ -1861,11 +1861,11 @@ static bool config_load_file(const char *path, bool set_defaults,
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL)) if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL))
CONFIG_GET_INT_BASE(conf, global, netplay.sync_frames, "netplay_delay_frames"); CONFIG_GET_INT_BASE(conf, settings, netplay.sync_frames, "netplay_delay_frames");
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, NULL)) if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, NULL))
CONFIG_GET_INT_BASE(conf, global, netplay.check_frames, "netplay_check_frames"); CONFIG_GET_INT_BASE(conf, settings, netplay.check_frames, "netplay_check_frames");
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_IP_PORT, NULL)) if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_IP_PORT, NULL))
CONFIG_GET_INT_BASE(conf, global, netplay.port, "netplay_ip_port"); CONFIG_GET_INT_BASE(conf, settings, netplay.port, "netplay_ip_port");
#endif #endif
for (i = 0; i < MAX_USERS; i++) for (i = 0; i < MAX_USERS; i++)
{ {
@ -1959,7 +1959,7 @@ static bool config_load_file(const char *path, bool set_defaults,
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL)) if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL))
{ {
strlcpy(global->netplay.server, override_netplay_ip_address, sizeof(global->netplay.server)); strlcpy(settings->netplay.server, override_netplay_ip_address, sizeof(settings->netplay.server));
free(override_netplay_ip_address); free(override_netplay_ip_address);
} }
#endif #endif
@ -2288,13 +2288,6 @@ bool config_load_override(void)
return false; return false;
/* Re-load the configuration with any overrides that might have been found */ /* Re-load the configuration with any overrides that might have been found */
#ifdef HAVE_NETWORKING
if (global && global->netplay.enable)
{
RARCH_WARN("[overrides] can't use overrides in conjunction with netplay, disabling overrides.\n");
return false;
}
#endif
/* Store the libretro_path we're using since it will be /* Store the libretro_path we're using since it will be
* overwritten by the override when reloading. */ * overwritten by the override when reloading. */

View File

@ -277,7 +277,6 @@ typedef struct settings
unsigned device[MAX_USERS]; unsigned device[MAX_USERS];
unsigned device_name_index[MAX_USERS]; unsigned device_name_index[MAX_USERS];
bool autodetect_enable; bool autodetect_enable;
bool netplay_client_swap_input;
unsigned turbo_period; unsigned turbo_period;
unsigned turbo_duty_cycle; unsigned turbo_duty_cycle;
@ -395,6 +394,19 @@ typedef struct settings
char menu_content[PATH_MAX_LENGTH]; char menu_content[PATH_MAX_LENGTH];
} directory; } directory;
#ifdef HAVE_NETWORKING
struct
{
char server[PATH_MAX_LENGTH];
unsigned port;
unsigned sync_frames;
unsigned check_frames;
bool is_client;
bool is_spectate;
bool swap_input;
} netplay;
#endif
unsigned content_history_size; unsigned content_history_size;
unsigned libretro_log_level; unsigned libretro_log_level;

View File

@ -3275,16 +3275,16 @@ static int action_ok_netplay_enable_host(const char *path,
{ {
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
bool netplay_was_on = false; bool netplay_was_on = false;
global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr();
global->netplay.enable = true; netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE, NULL);
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL)) if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
{ {
netplay_was_on = true; netplay_was_on = true;
/* Netplay is already on. Are we in the wrong mode? */ /* Netplay is already on. Are we in the wrong mode? */
if (global->netplay.is_client) if (settings->netplay.is_client)
{ {
/* Kill it! */ /* Kill it! */
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
@ -3296,8 +3296,7 @@ static int action_ok_netplay_enable_host(const char *path,
} }
} }
global->netplay.is_client = false; settings->netplay.is_client = false;
global->netplay.server[0] = '\0';
/* If we haven't yet started, this will load on its own */ /* If we haven't yet started, this will load on its own */
if (!content_is_inited()) if (!content_is_inited())
@ -3329,9 +3328,9 @@ static int action_ok_netplay_enable_client(const char *path,
{ {
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
bool netplay_was_on = false; bool netplay_was_on = false;
global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr();
global->netplay.enable = true; netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE, NULL);
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL)) if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
{ {
@ -3341,10 +3340,10 @@ static int action_ok_netplay_enable_client(const char *path,
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
} }
global->netplay.is_client = true; settings->netplay.is_client = true;
/* We can't do anything without a host specified */ /* We can't do anything without a host specified */
if (!global->netplay.server[0]) if (!settings->netplay.server[0])
{ {
runloop_msg_queue_push( runloop_msg_queue_push(
"Please specify the Netplay server's IP address or hostname.", "Please specify the Netplay server's IP address or hostname.",

View File

@ -1656,21 +1656,21 @@ void general_write_handler(void *data)
break; break;
case MENU_ENUM_LABEL_NETPLAY_MODE: case MENU_ENUM_LABEL_NETPLAY_MODE:
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (!global->netplay.is_client) if (!settings->netplay.is_client)
*global->netplay.server = '\0'; *settings->netplay.server = '\0';
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL); retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL);
#endif #endif
break; break;
case MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE: case MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE:
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
if (global->netplay.is_spectate) if (settings->netplay.is_spectate)
*global->netplay.server = '\0'; *settings->netplay.server = '\0';
#endif #endif
break; break;
case MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES: case MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES:
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
{ {
bool val = (global->netplay.sync_frames > 0); bool val = (settings->netplay.sync_frames > 0);
if (val) if (val)
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL); retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL);
@ -1682,7 +1682,7 @@ void general_write_handler(void *data)
case MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES: case MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES:
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
{ {
bool val = (global->netplay.check_frames > 0); bool val = (settings->netplay.check_frames > 0);
if (val) if (val)
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, NULL); retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, NULL);
@ -5783,24 +5783,7 @@ static bool setting_append_list(
#endif #endif
CONFIG_BOOL( CONFIG_BOOL(
list, list_info, list, list_info,
&global->netplay.enable, &settings->netplay.swap_input,
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_ENABLE),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ENABLE),
false,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON),
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_NONE
);
menu_settings_list_current_add_enum_idx(list, list_info, MENU_ENUM_LABEL_NETPLAY_ENABLE);
CONFIG_BOOL(
list, list_info,
&settings->input.netplay_client_swap_input,
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_CLIENT_SWAP_INPUT), msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_CLIENT_SWAP_INPUT),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_CLIENT_SWAP_INPUT), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_CLIENT_SWAP_INPUT),
netplay_client_swap_input, netplay_client_swap_input,
@ -5816,8 +5799,8 @@ static bool setting_append_list(
CONFIG_STRING( CONFIG_STRING(
list, list_info, list, list_info,
global->netplay.server, settings->netplay.server,
sizeof(global->netplay.server), sizeof(settings->netplay.server),
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_IP_ADDRESS), msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_IP_ADDRESS),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_IP_ADDRESS), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_IP_ADDRESS),
"", "",
@ -5831,7 +5814,7 @@ static bool setting_append_list(
CONFIG_BOOL( CONFIG_BOOL(
list, list_info, list, list_info,
&global->netplay.is_client, &settings->netplay.is_client,
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_MODE), msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_MODE),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_MODE), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_MODE),
false, false,
@ -5847,7 +5830,7 @@ static bool setting_append_list(
CONFIG_BOOL( CONFIG_BOOL(
list, list_info, list, list_info,
&global->netplay.is_spectate, &settings->netplay.is_spectate,
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE), msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_SPECTATOR_MODE_ENABLE), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_SPECTATOR_MODE_ENABLE),
false, false,
@ -5863,7 +5846,7 @@ static bool setting_append_list(
CONFIG_UINT( CONFIG_UINT(
list, list_info, list, list_info,
&global->netplay.sync_frames, &settings->netplay.sync_frames,
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES), msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_DELAY_FRAMES), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_DELAY_FRAMES),
0, 0,
@ -5878,7 +5861,7 @@ static bool setting_append_list(
CONFIG_UINT( CONFIG_UINT(
list, list_info, list, list_info,
&global->netplay.check_frames, &settings->netplay.check_frames,
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES), msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_CHECK_FRAMES), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_CHECK_FRAMES),
0, 0,
@ -5893,7 +5876,7 @@ static bool setting_append_list(
CONFIG_UINT( CONFIG_UINT(
list, list_info, list, list_info,
&global->netplay.port, &settings->netplay.port,
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_TCP_UDP_PORT), msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_TCP_UDP_PORT),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_TCP_UDP_PORT), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_TCP_UDP_PORT),
RARCH_DEFAULT_PORT, RARCH_DEFAULT_PORT,

View File

@ -49,6 +49,7 @@ enum
CMD_OPT_REQUIRE_SYNC = 0x10 CMD_OPT_REQUIRE_SYNC = 0x10
}; };
static bool netplay_enabled = false;
static netplay_t *netplay_data = NULL; static netplay_t *netplay_data = NULL;
static int init_tcp_connection(const struct addrinfo *res, static int init_tcp_connection(const struct addrinfo *res,
@ -267,7 +268,7 @@ static bool get_self_input_state(netplay_t *netplay)
retro_input_state_t cb = netplay->cbs.state_cb; retro_input_state_t cb = netplay->cbs.state_cb;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{ {
int16_t tmp = cb(settings->input.netplay_client_swap_input ? int16_t tmp = cb(settings->netplay.swap_input ?
0 : !netplay->port, 0 : !netplay->port,
RETRO_DEVICE_JOYPAD, 0, i); RETRO_DEVICE_JOYPAD, 0, i);
state[0] |= tmp ? 1 << i : 0; state[0] |= tmp ? 1 << i : 0;
@ -275,10 +276,10 @@ static bool get_self_input_state(netplay_t *netplay)
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
int16_t tmp_x = cb(settings->input.netplay_client_swap_input ? int16_t tmp_x = cb(settings->netplay.swap_input ?
0 : !netplay->port, 0 : !netplay->port,
RETRO_DEVICE_ANALOG, i, 0); RETRO_DEVICE_ANALOG, i, 0);
int16_t tmp_y = cb(settings->input.netplay_client_swap_input ? int16_t tmp_y = cb(settings->netplay.swap_input ?
0 : !netplay->port, 0 : !netplay->port,
RETRO_DEVICE_ANALOG, i, 1); RETRO_DEVICE_ANALOG, i, 1);
state[1 + i] = (uint16_t)tmp_x | (((uint16_t)tmp_y) << 16); state[1 + i] = (uint16_t)tmp_x | (((uint16_t)tmp_y) << 16);
@ -1320,13 +1321,13 @@ void deinit_netplay(void)
* Returns: true (1) if successful, otherwise false (0). * Returns: true (1) if successful, otherwise false (0).
**/ **/
bool init_netplay(void) bool init_netplay(bool is_client, bool is_spectate, const char *server,
unsigned port)
{ {
struct retro_callbacks cbs = {0}; struct retro_callbacks cbs = {0};
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
if (!global->netplay.enable) if (!netplay_enabled)
return false; return false;
if (bsv_movie_ctl(BSV_MOVIE_CTL_START_PLAYBACK, NULL)) if (bsv_movie_ctl(BSV_MOVIE_CTL_START_PLAYBACK, NULL))
@ -1338,10 +1339,9 @@ bool init_netplay(void)
core_set_default_callbacks(&cbs); core_set_default_callbacks(&cbs);
if (*global->netplay.server) if (is_client)
{ {
RARCH_LOG("Connecting to netplay host...\n"); RARCH_LOG("Connecting to netplay host...\n");
global->netplay.is_client = true;
} }
else else
{ {
@ -1352,15 +1352,14 @@ bool init_netplay(void)
} }
netplay_data = (netplay_t*)netplay_new( netplay_data = (netplay_t*)netplay_new(
global->netplay.is_client ? global->netplay.server : NULL, is_client ? server : NULL,
global->netplay.port ? global->netplay.port : RARCH_DEFAULT_PORT, port ? port : RARCH_DEFAULT_PORT,
global->netplay.sync_frames, global->netplay.check_frames, &cbs, settings->netplay.sync_frames, settings->netplay.check_frames, &cbs,
global->netplay.is_spectate, settings->username); is_spectate, settings->username);
if (netplay_data) if (netplay_data)
return true; return true;
global->netplay.is_client = false;
RARCH_WARN("%s\n", msg_hash_to_str(MSG_NETPLAY_FAILED)); RARCH_WARN("%s\n", msg_hash_to_str(MSG_NETPLAY_FAILED));
runloop_msg_queue_push( runloop_msg_queue_push(
@ -1373,16 +1372,36 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
{ {
if (!netplay_data) if (!netplay_data)
{ {
if (state == RARCH_NETPLAY_CTL_IS_DATA_INITED) switch (state)
return false; {
else case RARCH_NETPLAY_CTL_ENABLE:
return true; netplay_enabled = true;
return true;
case RARCH_NETPLAY_CTL_DISABLE:
netplay_enabled = false;
return true;
case RARCH_NETPLAY_CTL_IS_ENABLED:
return netplay_enabled;
case RARCH_NETPLAY_CTL_IS_DATA_INITED:
return false;
default:
return true;
}
} }
switch (state) switch (state)
{ {
case RARCH_NETPLAY_CTL_ENABLE:
case RARCH_NETPLAY_CTL_IS_DATA_INITED: case RARCH_NETPLAY_CTL_IS_DATA_INITED:
return true; return true;
case RARCH_NETPLAY_CTL_DISABLE:
return false;
case RARCH_NETPLAY_CTL_IS_ENABLED:
return true;
case RARCH_NETPLAY_CTL_POST_FRAME: case RARCH_NETPLAY_CTL_POST_FRAME:
netplay_post_frame(netplay_data); netplay_post_frame(netplay_data);
break; break;

View File

@ -35,6 +35,9 @@ enum rarch_netplay_ctl_state
RARCH_NETPLAY_CTL_FULLSCREEN_TOGGLE, RARCH_NETPLAY_CTL_FULLSCREEN_TOGGLE,
RARCH_NETPLAY_CTL_POST_FRAME, RARCH_NETPLAY_CTL_POST_FRAME,
RARCH_NETPLAY_CTL_PRE_FRAME, RARCH_NETPLAY_CTL_PRE_FRAME,
RARCH_NETPLAY_CTL_ENABLE,
RARCH_NETPLAY_CTL_DISABLE,
RARCH_NETPLAY_CTL_IS_ENABLED,
RARCH_NETPLAY_CTL_IS_DATA_INITED, RARCH_NETPLAY_CTL_IS_DATA_INITED,
RARCH_NETPLAY_CTL_PAUSE, RARCH_NETPLAY_CTL_PAUSE,
RARCH_NETPLAY_CTL_UNPAUSE, RARCH_NETPLAY_CTL_UNPAUSE,
@ -206,7 +209,11 @@ void netplay_load_savestate(netplay_t *netplay, retro_ctx_serialize_info_t *seri
bool netplay_disconnect(netplay_t *netplay); bool netplay_disconnect(netplay_t *netplay);
/** /**
* init_netplay: * init_netplay
* @is_client : true if starting Netplay as client
* @is_spectate : true if running in spectate mode
* @server : server address to connect to (client only)
* @port : TCP port to host on/connect to
* *
* Initializes netplay. * Initializes netplay.
* *
@ -214,7 +221,8 @@ bool netplay_disconnect(netplay_t *netplay);
* *
* Returns: true (1) if successful, otherwise false (0). * Returns: true (1) if successful, otherwise false (0).
**/ **/
bool init_netplay(void); bool init_netplay(bool is_client, bool is_spectate, const char *server,
unsigned port);
void deinit_netplay(void); void deinit_netplay(void);

View File

@ -380,11 +380,11 @@ void path_init_savefile(void)
bool should_sram_be_used = rarch_ctl(RARCH_CTL_IS_SRAM_USED, NULL) bool should_sram_be_used = rarch_ctl(RARCH_CTL_IS_SRAM_USED, NULL)
&& !rarch_ctl(RARCH_CTL_IS_SRAM_SAVE_DISABLED, NULL); && !rarch_ctl(RARCH_CTL_IS_SRAM_SAVE_DISABLED, NULL);
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr();
should_sram_be_used = should_sram_be_used && should_sram_be_used = should_sram_be_used &&
(!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL) (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL)
|| !global->netplay.is_client); || !settings->netplay.is_client);
#endif #endif
if (should_sram_be_used) if (should_sram_be_used)

View File

@ -57,6 +57,10 @@
#include "menu/menu_driver.h" #include "menu/menu_driver.h"
#endif #endif
#ifdef HAVE_NETWORKING
#include "network/netplay/netplay.h"
#endif
#include "config.features.h" #include "config.features.h"
#include "content.h" #include "content.h"
#include "core_type.h" #include "core_type.h"
@ -688,20 +692,20 @@ static void retroarch_parse_input(int argc, char *argv[])
case 'H': case 'H':
retroarch_override_setting_set( retroarch_override_setting_set(
RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL); RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL);
global->netplay.enable = true; netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE, NULL);
*global->netplay.server = '\0'; settings->netplay.is_client = false;
break; break;
case 'C': case 'C':
retroarch_override_setting_set( retroarch_override_setting_set(
RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL); RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, NULL);
global->netplay.enable = true; netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE, NULL);
strlcpy(global->netplay.server, optarg, strlcpy(settings->netplay.server, optarg,
sizeof(global->netplay.server)); sizeof(settings->netplay.server));
break; break;
case 'F': case 'F':
global->netplay.sync_frames = strtol(optarg, NULL, 0); settings->netplay.sync_frames = strtol(optarg, NULL, 0);
retroarch_override_setting_set( retroarch_override_setting_set(
RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL); RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL);
break; break;
@ -709,19 +713,19 @@ static void retroarch_parse_input(int argc, char *argv[])
case RA_OPT_CHECK_FRAMES: case RA_OPT_CHECK_FRAMES:
retroarch_override_setting_set( retroarch_override_setting_set(
RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, NULL); RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, NULL);
global->netplay.check_frames = strtoul(optarg, NULL, 0); settings->netplay.check_frames = strtoul(optarg, NULL, 0);
break; break;
case RA_OPT_PORT: case RA_OPT_PORT:
retroarch_override_setting_set( retroarch_override_setting_set(
RARCH_OVERRIDE_SETTING_NETPLAY_IP_PORT, NULL); RARCH_OVERRIDE_SETTING_NETPLAY_IP_PORT, NULL);
global->netplay.port = strtoul(optarg, NULL, 0); settings->netplay.port = strtoul(optarg, NULL, 0);
break; break;
case RA_OPT_SPECTATE: case RA_OPT_SPECTATE:
retroarch_override_setting_set( retroarch_override_setting_set(
RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL); RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL);
global->netplay.is_spectate = true; settings->netplay.is_spectate = true;
break; break;
#if defined(HAVE_NETWORK_CMD) #if defined(HAVE_NETWORK_CMD)

View File

@ -682,11 +682,9 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
const struct retro_frame_time_callback *info = const struct retro_frame_time_callback *info =
(const struct retro_frame_time_callback*)data; (const struct retro_frame_time_callback*)data;
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
global_t *global = global_get_ptr();
/* retro_run() will be called in very strange and /* retro_run() will be called in very strange and
* mysterious ways, have to disable it. */ * mysterious ways, have to disable it. */
if (global && global->netplay.enable) if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
return false; return false;
#endif #endif
runloop_frame_time = *info; runloop_frame_time = *info;

View File

@ -148,20 +148,6 @@ typedef struct global
char remapfile[PATH_MAX_LENGTH]; char remapfile[PATH_MAX_LENGTH];
} name; } name;
#ifdef HAVE_NETWORKING
/* Netplay. */
struct
{
char server[PATH_MAX_LENGTH];
bool enable;
bool is_client;
bool is_spectate;
unsigned sync_frames;
unsigned check_frames;
unsigned port;
} netplay;
#endif
/* Recording. */ /* Recording. */
struct struct
{ {