diff --git a/audio/audio_driver.c b/audio/audio_driver.c index a83f7aea22..df63c57a13 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -31,6 +31,10 @@ #include "../verbosity.h" #include "../string_list_special.h" +#ifdef HAVE_NETPLAY +#include "../netplay/netplay.h" +#endif + #ifndef AUDIO_BUFFER_FREE_SAMPLES_COUNT #define AUDIO_BUFFER_FREE_SAMPLES_COUNT (8 * 1024) #endif @@ -850,15 +854,12 @@ bool audio_driver_ctl(enum rarch_audio_ctl_state state, void *data) { const struct retro_audio_callback *cb = (const struct retro_audio_callback*)data; -#ifdef HAVE_NETPLAY - global_t *global = global_get_ptr(); -#endif if (recording_driver_get_data_ptr()) /* A/V sync is a must. */ return false; #ifdef HAVE_NETPLAY - if (global->netplay.enable) + if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)) return false; #endif if (cb) diff --git a/command_event.c b/command_event.c index 52d0decd8b..39b6d8b1d9 100644 --- a/command_event.c +++ b/command_event.c @@ -461,7 +461,8 @@ static void event_load_auto_state(void) global_t *global = global_get_ptr(); #ifdef HAVE_NETPLAY - if (global->netplay.enable && !global->netplay.is_spectate) + if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) + && !global->netplay.is_spectate) return; #endif diff --git a/configuration.c b/configuration.c index 59960b4ff2..6580075763 100644 --- a/configuration.c +++ b/configuration.c @@ -36,6 +36,10 @@ #include "system.h" #include "verbosity.h" +#ifdef HAVE_NETPLAY +#include "netplay/netplay.h" +#endif + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -2038,7 +2042,7 @@ bool config_load_override(void) } #ifdef HAVE_NETPLAY - if (global->netplay.enable) + if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)) { RARCH_WARN("Overrides: can't use overrides in conjunction with netplay, disabling overrides\n"); return false; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 5156146e02..6b6161e23f 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -55,6 +55,9 @@ #include "../tasks/tasks_internal.h" +#ifdef HAVE_NETPLAY +#include "../netplay/netplay.h" +#endif struct rarch_setting_info { @@ -154,6 +157,9 @@ struct rarch_setting bool enforce_maxrange; }; +/* static local variables */ +static bool setting_netplay_enable; + /* forward decls */ static void setting_get_string_representation_default(void *data, char *s, size_t len); @@ -2839,6 +2845,14 @@ void general_write_handler(void *data) switch (hash) { + case MENU_LABEL_NETPLAY_ENABLE: +#ifdef HAVE_NETPLAY + if (*setting->value.boolean) + netplay_driver_ctl(RARCH_NETPLAY_CTL_SET_ENABLE, NULL); + else + netplay_driver_ctl(RARCH_NETPLAY_CTL_UNSET_ENABLE, NULL); +#endif + break; case MENU_LABEL_VIDEO_THREADED: { if (*setting->value.boolean) @@ -6353,7 +6367,7 @@ static bool setting_append_list_netplay_options( CONFIG_BOOL( list, list_info, - &global->netplay.enable, + &setting_netplay_enable, menu_hash_to_str(MENU_LABEL_NETPLAY_ENABLE), menu_hash_to_str(MENU_LABEL_VALUE_NETPLAY_ENABLE), false, diff --git a/netplay/netplay.c b/netplay/netplay.c index 595b7a9696..be0c4aa07d 100644 --- a/netplay/netplay.c +++ b/netplay/netplay.c @@ -1102,6 +1102,9 @@ void netplay_post_frame(netplay_t *netplay) void deinit_netplay(void) { netplay_t *netplay = (netplay_t*)netplay_data; + + netplay_driver_ctl(RARCH_NETPLAY_CTL_DEINIT, NULL); + if (netplay) netplay_free(netplay); netplay_data = NULL; @@ -1123,7 +1126,7 @@ bool init_netplay(void) settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); - if (!global->netplay.enable) + if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)) return false; if (bsv_movie_ctl(BSV_MOVIE_CTL_START_PLAYBACK, NULL)) @@ -1163,11 +1166,23 @@ bool init_netplay(void) bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data) { + static bool netplay_is_enabled = false; if (!netplay_data) return false; switch (state) { + case RARCH_NETPLAY_CTL_DEINIT: + netplay_is_enabled = false; + break; + case RARCH_NETPLAY_CTL_IS_ENABLED: + return netplay_is_enabled; + case RARCH_NETPLAY_CTL_SET_ENABLE: + netplay_is_enabled = true; + break; + case RARCH_NETPLAY_CTL_UNSET_ENABLE: + netplay_is_enabled = false; + break; case RARCH_NETPLAY_CTL_IS_DATA_INITED: return true; case RARCH_NETPLAY_CTL_POST_FRAME: diff --git a/netplay/netplay.h b/netplay/netplay.h index 8ca7536480..05ec44c3a4 100644 --- a/netplay/netplay.h +++ b/netplay/netplay.h @@ -31,11 +31,15 @@ typedef struct netplay netplay_t; enum rarch_netplay_ctl_state { RARCH_NETPLAY_CTL_NONE = 0, + RARCH_NETPLAY_CTL_DEINIT, RARCH_NETPLAY_CTL_FLIP_PLAYERS, RARCH_NETPLAY_CTL_FULLSCREEN_TOGGLE, RARCH_NETPLAY_CTL_POST_FRAME, RARCH_NETPLAY_CTL_PRE_FRAME, - RARCH_NETPLAY_CTL_IS_DATA_INITED + RARCH_NETPLAY_CTL_IS_DATA_INITED, + RARCH_NETPLAY_CTL_IS_ENABLED, + RARCH_NETPLAY_CTL_SET_ENABLE, + RARCH_NETPLAY_CTL_UNSET_ENABLE }; enum netplay_cmd diff --git a/retroarch.c b/retroarch.c index 4dec592c1c..a89d441279 100644 --- a/retroarch.c +++ b/retroarch.c @@ -68,6 +68,10 @@ #include "command.h" #endif +#ifdef HAVE_NETPLAY +#include "netplay/netplay.h" +#endif + #ifdef HAVE_MENU #include "menu/menu_driver.h" #include "menu/menu_content.h" @@ -852,13 +856,13 @@ static void parse_input(int argc, char *argv[]) #ifdef HAVE_NETPLAY case 'H': global->has_set.netplay_ip_address = true; - global->netplay.enable = true; + netplay_driver_ctl(RARCH_NETPLAY_CTL_SET_ENABLE, NULL); *global->netplay.server = '\0'; break; case 'C': global->has_set.netplay_ip_address = true; - global->netplay.enable = true; + netplay_driver_ctl(RARCH_NETPLAY_CTL_SET_ENABLE, NULL); strlcpy(global->netplay.server, optarg, sizeof(global->netplay.server)); break; diff --git a/runloop.c b/runloop.c index 545c42bac7..b45ffd4226 100644 --- a/runloop.c +++ b/runloop.c @@ -572,11 +572,9 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) const struct retro_frame_time_callback *info = (const struct retro_frame_time_callback*)data; #ifdef HAVE_NETPLAY - global_t *global = global_get_ptr(); - /* retro_run() will be called in very strange and * mysterious ways, have to disable it. */ - if (global->netplay.enable) + if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)) return false; #endif runloop_frame_time = *info; diff --git a/runloop.h b/runloop.h index 90b6afcc86..c265289037 100644 --- a/runloop.h +++ b/runloop.h @@ -242,7 +242,6 @@ typedef struct global struct { char server[PATH_MAX_LENGTH]; - bool enable; bool is_client; bool is_spectate; unsigned sync_frames;