Create RARCH_NETPLAY_CTL_IS_ENABLED, RARCH_NETPLAY_CTL_SET_ENABLE,

and RARCH_NETPLAY_CTL_USNET_ENABLE
This commit is contained in:
twinaphex 2016-03-14 15:03:42 +01:00
parent 29bc5b1d50
commit 1a978b0f3c
9 changed files with 55 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;

View File

@ -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,

View File

@ -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:

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -242,7 +242,6 @@ typedef struct global
struct
{
char server[PATH_MAX_LENGTH];
bool enable;
bool is_client;
bool is_spectate;
unsigned sync_frames;