Skip to content

Commit

Permalink
Say goodbye to spectator mode (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorR committed Dec 19, 2016
1 parent 4768970 commit 9b2270f
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 405 deletions.
1 change: 0 additions & 1 deletion Makefile.common
Expand Up @@ -1123,7 +1123,6 @@ ifeq ($(HAVE_NETWORKING), 1)
# Netplay
DEFINES += -DHAVE_NETWORK_CMD
OBJ += network/netplay/netplay_net.o \
network/netplay/netplay_spectate.o \
network/netplay/netplay_common.o \
network/netplay/netplay_discovery.o \
network/netplay/netplay_buf.o \
Expand Down
5 changes: 2 additions & 3 deletions command.c
Expand Up @@ -1227,8 +1227,7 @@ static void command_event_load_auto_state(void)
global_t *global = global_get_ptr();

#ifdef HAVE_NETWORKING
if ( netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)
&& !settings->netplay.is_spectate)
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
return;
#endif

Expand Down Expand Up @@ -2362,7 +2361,7 @@ bool command_event(enum event_command cmd, void *data)
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
#ifdef HAVE_NETWORKING
if (!init_netplay(
settings->netplay.is_spectate, data, settings->netplay.server,
data, settings->netplay.server,
settings->netplay.port))
return false;
#endif
Expand Down
8 changes: 0 additions & 8 deletions configuration.c
Expand Up @@ -822,7 +822,6 @@ 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);
#endif
#ifdef HAVE_NETWORKING
SETTING_BOOL("netplay_spectator_mode_enable",&settings->netplay.is_spectate, false, false /* TODO */, false);
SETTING_BOOL("netplay_nat_traversal", &settings->netplay.nat_traversal, true, true, false);
#endif
SETTING_BOOL("block_sram_overwrite", &settings->block_sram_overwrite, true, block_sram_overwrite, false);
Expand Down Expand Up @@ -1807,13 +1806,6 @@ static bool config_load_file(const char *path, bool set_defaults,
if (!rarch_ctl(RARCH_CTL_IS_FORCE_FULLSCREEN, NULL))
CONFIG_GET_BOOL_BASE(conf, settings, video.fullscreen, "video_fullscreen");

#ifdef HAVE_NETWORKING
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL))
{
CONFIG_GET_BOOL_BASE(conf, settings, netplay.is_spectate,
"netplay_spectator_mode_enable");
}
#endif
#ifdef HAVE_NETWORKGAMEPAD
for (i = 0; i < MAX_USERS; i++)
{
Expand Down
1 change: 0 additions & 1 deletion configuration.h
Expand Up @@ -403,7 +403,6 @@ typedef struct settings
unsigned port;
unsigned delay_frames;
unsigned check_frames;
bool is_spectate;
bool swap_input;
bool nat_traversal;
} netplay;
Expand Down
4 changes: 0 additions & 4 deletions menu/menu_displaylist.c
Expand Up @@ -4697,10 +4697,6 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES,
PARSE_ONLY_UINT, false) != -1)
count++;
if (menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE,
PARSE_ONLY_BOOL, false) != -1)
count++;
if (menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_NETPLAY_CLIENT_SWAP_INPUT,
PARSE_ONLY_BOOL, false) != -1)
Expand Down
20 changes: 0 additions & 20 deletions menu/menu_setting.c
Expand Up @@ -1719,11 +1719,6 @@ void general_write_handler(void *data)
case MENU_ENUM_LABEL_NETPLAY_MODE:
#ifdef HAVE_NETWORKING
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL);
#endif
break;
case MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE:
#ifdef HAVE_NETWORKING
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL);
#endif
break;
case MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES:
Expand Down Expand Up @@ -5610,21 +5605,6 @@ static bool setting_append_list(
menu_settings_list_current_add_range(list, list_info, 0, 10, 1, true, false);
settings_data_list_current_add_flags(list, list_info, SD_FLAG_ADVANCED);

CONFIG_BOOL(
list, list_info,
&settings->netplay.is_spectate,
MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE,
MENU_ENUM_LABEL_VALUE_NETPLAY_SPECTATOR_MODE_ENABLE,
false,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_NONE);

CONFIG_BOOL(
list, list_info,
&settings->netplay.nat_traversal,
Expand Down
34 changes: 9 additions & 25 deletions network/netplay/netplay.c
Expand Up @@ -61,7 +61,7 @@ static void announce_nat_traversal(netplay_t *netplay);
#endif

static int init_tcp_connection(const struct addrinfo *res,
bool server, bool spectate,
bool server,
struct sockaddr *other_addr, socklen_t addr_size)
{
bool ret = true;
Expand Down Expand Up @@ -114,7 +114,7 @@ static int init_tcp_connection(const struct addrinfo *res,
}
#endif
if ( !socket_bind(fd, (void*)res) ||
listen(fd, spectate ? MAX_SPECTATORS : 1) < 0)
listen(fd, 1024) < 0)
{
ret = false;
goto end;
Expand All @@ -132,7 +132,7 @@ static int init_tcp_connection(const struct addrinfo *res,
}

static bool init_tcp_socket(netplay_t *netplay, void *direct_host,
const char *server, uint16_t port, bool spectate)
const char *server, uint16_t port)
{
char port_buf[16];
bool ret = false;
Expand Down Expand Up @@ -206,7 +206,6 @@ static bool init_tcp_socket(netplay_t *netplay, void *direct_host,
int fd = init_tcp_connection(
tmp_info,
direct_host || server,
netplay->spectate.enabled,
(struct sockaddr*)&sad,
sizeof(sad));

Expand Down Expand Up @@ -261,7 +260,7 @@ static bool init_socket(netplay_t *netplay, void *direct_host, const char *serve
if (!network_init())
return false;

if (!init_tcp_socket(netplay, direct_host, server, port, netplay->spectate.enabled))
if (!init_tcp_socket(netplay, direct_host, server, port))
return false;

if (netplay->is_server && netplay->nat_traversal)
Expand Down Expand Up @@ -349,8 +348,7 @@ static bool netplay_can_poll(netplay_t *netplay)
* finishing the initial handshake */
static void send_input(netplay_t *netplay, struct netplay_connection *connection)
{
if (!netplay->spectate.enabled && /* Spectate sends in its own way */
netplay->self_mode == NETPLAY_CONNECTION_PLAYING &&
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING &&
connection->mode >= NETPLAY_CONNECTION_CONNECTED)
{
netplay->input_packet_buffer[2] = htonl(netplay->self_frame_count);
Expand Down Expand Up @@ -1434,7 +1432,6 @@ static bool netplay_init_buffers(netplay_t *netplay, unsigned frames)
* @delay_frames : Amount of delay frames.
* @check_frames : Frequency with which to check CRCs.
* @cb : Libretro callbacks.
* @spectate : If true, enable spectator mode.
* @nat_traversal : If true, attempt NAT traversal.
* @nick : Nickname of user.
* @quirks : Netplay quirks required for this session.
Expand All @@ -1446,7 +1443,7 @@ static bool netplay_init_buffers(netplay_t *netplay, unsigned frames)
**/
netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
unsigned delay_frames, unsigned check_frames,
const struct retro_callbacks *cb, bool spectate, bool nat_traversal,
const struct retro_callbacks *cb, bool nat_traversal,
const char *nick, uint64_t quirks)
{
netplay_t *netplay = (netplay_t*)calloc(1, sizeof(*netplay));
Expand All @@ -1457,7 +1454,6 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
netplay->tcp_port = port;
netplay->cbs = *cb;
netplay->port = server ? 0 : 1;
netplay->spectate.enabled = spectate;
netplay->is_server = server == NULL;
netplay->nat_traversal = netplay->is_server ? nat_traversal : false;
netplay->delay_frames = delay_frames;
Expand All @@ -1481,10 +1477,7 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,

strlcpy(netplay->nick, nick[0] ? nick : RARCH_DEFAULT_NICK, sizeof(netplay->nick));

if(spectate)
netplay->net_cbs = netplay_get_cbs_spectate();
else
netplay->net_cbs = netplay_get_cbs_net();
netplay->net_cbs = netplay_get_cbs_net();

if (!init_socket(netplay, direct_host, server, port))
{
Expand Down Expand Up @@ -1620,15 +1613,6 @@ void netplay_free(netplay_t *netplay)
}
}

if (netplay->spectate.enabled)
{
for (i = 0; i < MAX_SPECTATORS; i++)
if (netplay->spectate.fds[i] >= 0)
socket_close(netplay->spectate.fds[i]);

free(netplay->spectate.input);
}

if (netplay->connections && netplay->connections != &netplay->one_connection)
free(netplay->connections);

Expand Down Expand Up @@ -1897,7 +1881,7 @@ void deinit_netplay(void)
* Returns: true (1) if successful, otherwise false (0).
**/

bool init_netplay(bool is_spectate, void *direct_host, const char *server, unsigned port)
bool init_netplay(void *direct_host, const char *server, unsigned port)
{
struct retro_callbacks cbs = {0};
settings_t *settings = config_get_ptr();
Expand Down Expand Up @@ -1953,7 +1937,7 @@ bool init_netplay(bool is_spectate, void *direct_host, const char *server, unsig
netplay_is_client ? server : NULL,
port ? port : RARCH_DEFAULT_PORT,
settings->netplay.delay_frames, settings->netplay.check_frames, &cbs,
is_spectate, settings->netplay.nat_traversal, settings->username,
settings->netplay.nat_traversal, settings->username,
quirks);

if (netplay_data)
Expand Down
3 changes: 1 addition & 2 deletions network/netplay/netplay.h
Expand Up @@ -58,7 +58,6 @@ size_t audio_sample_batch_net(const int16_t *data, size_t frames);

/**
* init_netplay
* @is_spectate : true if running in spectate mode
* @server : server address to connect to (client only)
* @port : TCP port to host on/connect to
*
Expand All @@ -68,7 +67,7 @@ size_t audio_sample_batch_net(const int16_t *data, size_t frames);
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool init_netplay(bool is_spectate, void *direct_host, const char *server, unsigned port);
bool init_netplay(void *direct_host, const char *server, unsigned port);

void deinit_netplay(void);

Expand Down
7 changes: 0 additions & 7 deletions network/netplay/netplay_common.c
Expand Up @@ -466,13 +466,6 @@ bool netplay_is_server(netplay_t* netplay)
return netplay->is_server;
}

bool netplay_is_spectate(netplay_t* netplay)
{
if (!netplay)
return false;
return netplay->spectate.enabled;
}

bool netplay_delta_frame_ready(netplay_t *netplay, struct delta_frame *delta, uint32_t frame)
{
void *remember_state;
Expand Down
27 changes: 6 additions & 21 deletions network/netplay/netplay_private.h
Expand Up @@ -35,7 +35,6 @@
#endif

#define WORDS_PER_FRAME 4 /* Allows us to send 128 bits worth of state per frame. */
#define MAX_SPECTATORS 16
#define RARCH_DEFAULT_PORT 55435
#define RARCH_DEFAULT_NICK "Anonymous"

Expand Down Expand Up @@ -253,6 +252,9 @@ struct netplay_connection

struct netplay
{
/* Are we the server? */
bool is_server;

/* Our nickname */
char nick[32];

Expand Down Expand Up @@ -350,24 +352,12 @@ struct netplay
/* A buffer for outgoing input packets. */
uint32_t input_packet_buffer[2 + WORDS_PER_FRAME];

/* And socket info */
/* Our local socket info */
struct addrinfo *addr;
struct sockaddr_storage their_addr;
bool has_client_addr;

/* Counter for timeouts */
unsigned timeout_cnt;

/* Spectating. */
struct {
bool enabled;
int fds[MAX_SPECTATORS];
uint32_t frames[MAX_SPECTATORS];
uint16_t *input;
size_t input_ptr;
size_t input_sz;
} spectate;
bool is_server;

/* User flipping
* Flipping state. If frame >= flip_frame, we apply the flip.
* If not, we apply the opposite, effectively creating a trigger point. */
Expand Down Expand Up @@ -400,7 +390,6 @@ void input_poll_net(void);
* @delay_frames : Amount of delay frames.
* @check_frames : Frequency with which to check CRCs.
* @cb : Libretro callbacks.
* @spectate : If true, enable spectator mode.
* @nat_traversal : If true, attempt NAT traversal.
* @nick : Nickname of user.
* @quirks : Netplay quirks.
Expand All @@ -412,7 +401,7 @@ void input_poll_net(void);
**/
netplay_t *netplay_new(void *direct_host, const char *server,
uint16_t port, unsigned delay_frames, unsigned check_frames,
const struct retro_callbacks *cb, bool spectate, bool nat_traversal,
const struct retro_callbacks *cb, bool nat_traversal,
const char *nick, uint64_t quirks);

/**
Expand Down Expand Up @@ -476,8 +465,6 @@ bool netplay_disconnect(netplay_t *netplay);

struct netplay_callbacks* netplay_get_cbs_net(void);

struct netplay_callbacks* netplay_get_cbs_spectate(void);

/* Normally called at init time, unless the INITIALIZATION quirk is set */
bool netplay_init_serialization(netplay_t *netplay);

Expand All @@ -503,8 +490,6 @@ uint32_t netplay_impl_magic(void);

bool netplay_is_server(netplay_t* netplay);

bool netplay_is_spectate(netplay_t* netplay);

bool netplay_delta_frame_ready(netplay_t *netplay, struct delta_frame *delta, uint32_t frame);

uint32_t netplay_delta_frame_crc(netplay_t *netplay, struct delta_frame *delta);
Expand Down

0 comments on commit 9b2270f

Please sign in to comment.