Skip to content

Commit

Permalink
Goodbye delay_frames! stateless_mode is the new delay_frames=0
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorR committed Dec 19, 2016
1 parent 45d732a commit f7f6590
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 77 deletions.
3 changes: 3 additions & 0 deletions config.def.h
Expand Up @@ -794,6 +794,9 @@ static const bool pause_nonactive = true;
* It is measured in seconds. A value of 0 disables autosave. */
static const unsigned autosave_interval = 0;

/* Netplay without savestates/rewind */
static const bool netplay_stateless_mode = false;

/* When being client over netplay, use keybinds for
* user 1 rather than user 2. */
static const bool netplay_client_swap_input = true;
Expand Down
6 changes: 3 additions & 3 deletions configuration.c
Expand Up @@ -718,6 +718,7 @@ static int populate_settings_bool(settings_t *settings, struct config_bool_setti
SETTING_BOOL("all_users_control_menu", &settings->input.all_users_control_menu, true, all_users_control_menu, false);
SETTING_BOOL("menu_swap_ok_cancel_buttons", &settings->input.menu_swap_ok_cancel_buttons, true, menu_swap_ok_cancel_buttons, false);
#ifdef HAVE_NETWORKING
SETTING_BOOL("netplay_stateless_mode", &settings->netplay.stateless_mode, false, netplay_stateless_mode, false);
SETTING_BOOL("netplay_client_swap_input", &settings->netplay.swap_input, true, netplay_client_swap_input, false);
#endif
SETTING_BOOL("input_descriptor_label_show", &settings->input.input_descriptor_label_show, true, input_descriptor_label_show, false);
Expand Down Expand Up @@ -947,7 +948,6 @@ static int populate_settings_int(settings_t *settings, struct config_int_setting
SETTING_INT("state_slot", (unsigned*)&settings->state_slot, false, 0 /* TODO */, false);
#ifdef HAVE_NETWORKING
SETTING_INT("netplay_ip_port", &settings->netplay.port, true, RARCH_DEFAULT_PORT, false);
SETTING_INT("netplay_delay_frames", &settings->netplay.delay_frames, true, netplay_delay_frames, false);
SETTING_INT("netplay_check_frames", &settings->netplay.check_frames, true, netplay_check_frames, false);
#endif
#ifdef HAVE_LANGEXTRA
Expand Down Expand Up @@ -1856,8 +1856,8 @@ static bool config_load_file(const char *path, bool set_defaults,
}

#ifdef HAVE_NETWORKING
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL))
CONFIG_GET_INT_BASE(conf, settings, netplay.delay_frames, "netplay_delay_frames");
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_STATELESS_MODE, NULL))
CONFIG_GET_BOOL_BASE(conf, settings, netplay.stateless_mode, "netplay_stateless_mode");
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, NULL))
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))
Expand Down
2 changes: 1 addition & 1 deletion configuration.h
Expand Up @@ -401,7 +401,7 @@ typedef struct settings
{
char server[255];
unsigned port;
unsigned delay_frames;
bool stateless_mode;
unsigned check_frames;
bool swap_input;
bool nat_traversal;
Expand Down
4 changes: 2 additions & 2 deletions intl/msg_hash_lbl.h
Expand Up @@ -571,8 +571,6 @@ MSG_HASH(MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES,
"netplay_check_frames")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_CLIENT_SWAP_INPUT,
"netplay_client_swap_input")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES,
"netplay_delay_frames")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_DISCONNECT,
"menu_netplay_disconnect")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_ENABLE,
Expand All @@ -597,6 +595,8 @@ MSG_HASH(MENU_ENUM_LABEL_NETPLAY_SPECTATE_PASSWORD,
"netplay_spectate_password")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE,
"netplay_spectator_mode_enable")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_STATELESS_MODE,
"netplay_stateless_mode")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_TCP_UDP_PORT,
"netplay_tcp_udp_port")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_LAN_SCAN_SETTINGS,
Expand Down
9 changes: 9 additions & 0 deletions intl/msg_hash_us.c
Expand Up @@ -1561,6 +1561,15 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
"Increasing this value will increase \n"
"performance, but introduce more latency.");
break;
case MENU_ENUM_LABEL_NETPLAY_STATELESS_MODE:
snprintf(s, len,
"Whether to run netplay in a mode not requiring\n"
"save states. \n"
" \n"
"If set to true, a very fast network is required,\n"
"but no rewinding is performed, so there will be\n"
"no netplay jitter.\n");
break;
case MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES:
snprintf(s, len,
"The frequency in frames with which netplay \n"
Expand Down
2 changes: 2 additions & 0 deletions intl/msg_hash_us.h
Expand Up @@ -976,6 +976,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_PASSWORD,
"Server Password")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_SETTINGS,
"Netplay settings")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_STATELESS_MODE,
"Netplay Stateless Mode")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_SPECTATE_PASSWORD,
"Server Spectate-Only Password")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_SPECTATOR_MODE_ENABLE,
Expand Down
2 changes: 1 addition & 1 deletion menu/menu_displaylist.c
Expand Up @@ -4698,7 +4698,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
PARSE_ONLY_STRING, false) != -1)
count++;
if (menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES,
MENU_ENUM_LABEL_NETPLAY_STATELESS_MODE,
PARSE_ONLY_UINT, false) != -1)
count++;
if (menu_displaylist_parse_settings_enum(menu, info,
Expand Down
28 changes: 11 additions & 17 deletions menu/menu_setting.c
Expand Up @@ -1721,16 +1721,9 @@ void general_write_handler(void *data)
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_MODE, NULL);
#endif
break;
case MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES:
case MENU_ENUM_LABEL_NETPLAY_STATELESS_MODE:
#ifdef HAVE_NETWORKING
{
bool val = (settings->netplay.delay_frames > 0);

if (val)
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL);
else
retroarch_override_setting_unset(RARCH_OVERRIDE_SETTING_NETPLAY_DELAY_FRAMES, NULL);
}
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_NETPLAY_STATELESS_MODE, NULL);
#endif
break;
case MENU_ENUM_LABEL_NETPLAY_CHECK_FRAMES:
Expand Down Expand Up @@ -5605,19 +5598,20 @@ static bool setting_append_list(
general_read_handler);
settings_data_list_current_add_flags(list, list_info, SD_FLAG_ALLOW_INPUT);

CONFIG_UINT(
CONFIG_BOOL(
list, list_info,
&settings->netplay.delay_frames,
MENU_ENUM_LABEL_NETPLAY_DELAY_FRAMES,
MENU_ENUM_LABEL_VALUE_NETPLAY_DELAY_FRAMES,
netplay_delay_frames,
&settings->netplay.stateless_mode,
MENU_ENUM_LABEL_NETPLAY_STATELESS_MODE,
MENU_ENUM_LABEL_VALUE_NETPLAY_STATELESS_MODE,
false,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
menu_settings_list_current_add_range(list, list_info, 0, 60, 1, true, false);
settings_data_list_current_add_flags(list, list_info, SD_FLAG_ADVANCED);
general_read_handler,
SD_FLAG_NONE);

CONFIG_UINT(
list, list_info,
Expand Down
1 change: 1 addition & 0 deletions msg_hash.h
Expand Up @@ -1008,6 +1008,7 @@ enum msg_hash_enums
MENU_LABEL(BLUETOOTH_ENABLE),
MENU_LABEL(NETPLAY_CLIENT_SWAP_INPUT),
MENU_LABEL(NETPLAY_DELAY_FRAMES),
MENU_LABEL(NETPLAY_STATELESS_MODE),
MENU_LABEL(NETPLAY_CHECK_FRAMES),
MENU_LABEL(NETPLAY_SPECTATOR_MODE_ENABLE),
MENU_LABEL(NETPLAY_TCP_UDP_PORT),
Expand Down
10 changes: 5 additions & 5 deletions network/netplay/netplay_frontend.c
Expand Up @@ -178,7 +178,7 @@ static bool netplay_poll(void)

/* Read Netplay input, block if we're configured to stall for input every
* frame */
if (netplay_data->delay_frames == 0 &&
if (netplay_data->stateless_mode &&
netplay_data->unread_frame_count <= netplay_data->self_frame_count)
res = netplay_poll_net_input(netplay_data, true);
else
Expand Down Expand Up @@ -226,9 +226,9 @@ static bool netplay_poll(void)
if (netplay_data->frame_run_time_avg)
max_ahead = 50000 / netplay_data->frame_run_time_avg;
else
max_ahead = netplay_data->delay_frames;
if (max_ahead > netplay_data->delay_frames)
max_ahead = netplay_data->delay_frames;
max_ahead = NETPLAY_MAX_STALL_FRAMES;
if (max_ahead > NETPLAY_MAX_STALL_FRAMES)
max_ahead = NETPLAY_MAX_STALL_FRAMES;

/* Are we too far ahead? */
netplay_update_unread_ptr(netplay_data);
Expand Down Expand Up @@ -846,7 +846,7 @@ bool init_netplay(void *direct_host, const char *server, unsigned port,
netplay_is_client ? server : NULL,
port ? port : RARCH_DEFAULT_PORT,
play_password, spectate_password,
settings->netplay.delay_frames, settings->netplay.check_frames, &cbs,
settings->netplay.stateless_mode, settings->netplay.check_frames, &cbs,
settings->netplay.nat_traversal, settings->username,
quirks);

Expand Down
23 changes: 10 additions & 13 deletions network/netplay/netplay_init.c
Expand Up @@ -230,11 +230,11 @@ static bool init_socket(netplay_t *netplay, void *direct_host, const char *serve

static bool netplay_init_socket_buffers(netplay_t *netplay)
{
/* Make our packet buffer big enough for a save state and frames-many frames
* of input data, plus the headers for each of them */
/* Make our packet buffer big enough for a save state and stall-frames-many
* frames of input data, plus the headers for each of them */
size_t i;
size_t packet_buffer_size = netplay->zbuffer_size +
netplay->delay_frames * WORDS_PER_FRAME + (netplay->delay_frames+1)*3;
NETPLAY_MAX_STALL_FRAMES * WORDS_PER_FRAME + (NETPLAY_MAX_STALL_FRAMES+1)*3;
netplay->packet_buffer_size = packet_buffer_size;

for (i = 0; i < netplay->connections_size; i++)
Expand Down Expand Up @@ -366,18 +366,15 @@ bool netplay_wait_and_init_serialization(netplay_t *netplay)
return false;
}

static bool netplay_init_buffers(netplay_t *netplay, unsigned frames)
static bool netplay_init_buffers(netplay_t *netplay)
{
size_t packet_buffer_size;

if (!netplay)
return false;

/* * 2 + 1 because:
* Self sits in the middle,
* Other is allowed to drift as much as 'frames' frames behind
* Read is allowed to drift as much as 'frames' frames ahead */
netplay->buffer_size = frames * 2 + 1;
/* Enough to get ahead or behind by MAX_STALL_FRAMES frames */
netplay->buffer_size = NETPLAY_MAX_STALL_FRAMES + 1;

netplay->buffer = (struct delta_frame*)calloc(netplay->buffer_size,
sizeof(*netplay->buffer));
Expand All @@ -398,7 +395,7 @@ static bool netplay_init_buffers(netplay_t *netplay, unsigned frames)
* @port : Port of server.
* @play_password : Password required to play.
* @spectate_password : Password required to connect.
* @delay_frames : Amount of delay frames.
* @stateless_mode : Shall we use stateless mode?
* @check_frames : Frequency with which to check CRCs.
* @cb : Libretro callbacks.
* @nat_traversal : If true, attempt NAT traversal.
Expand All @@ -412,7 +409,7 @@ static bool netplay_init_buffers(netplay_t *netplay, unsigned frames)
*/
netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
const char *play_password, const char *spectate_password,
unsigned delay_frames, unsigned check_frames,
bool stateless_mode, unsigned check_frames,
const struct retro_callbacks *cb, bool nat_traversal, const char *nick,
uint64_t quirks)
{
Expand All @@ -427,7 +424,7 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
netplay->player_max = 1;
netplay->is_server = server == NULL;
netplay->nat_traversal = netplay->is_server ? nat_traversal : false;
netplay->delay_frames = delay_frames;
netplay->stateless_mode = stateless_mode;
netplay->check_frames = check_frames;
netplay->crc_validity_checked = false;
netplay->crcs_valid = true;
Expand Down Expand Up @@ -458,7 +455,7 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
return NULL;
}

if (!netplay_init_buffers(netplay, delay_frames))
if (!netplay_init_buffers(netplay))
{
free(netplay);
return NULL;
Expand Down
27 changes: 6 additions & 21 deletions network/netplay/netplay_private.h
Expand Up @@ -45,7 +45,8 @@
#define MAX_RETRIES 16
#define RETRY_MS 500

#define NETPLAY_FRAME_RUN_TIME_WINDOW 128
#define NETPLAY_MAX_STALL_FRAMES 60
#define NETPLAY_FRAME_RUN_TIME_WINDOW 120

#define PREV_PTR(x) ((x) == 0 ? netplay->buffer_size - 1 : (x) - 1)
#define NEXT_PTR(x) ((x + 1) % netplay->buffer_size)
Expand Down Expand Up @@ -178,22 +179,6 @@ enum netplay_cmd_mode_reasons
NETPLAY_CMD_MODE_REFUSED_REASON_NO_SLOTS
};

/* These are the configurations sent by NETPLAY_CMD_CFG. */
enum netplay_cmd_cfg
{
/* Nickname */
NETPLAY_CFG_NICK = 0x0001,

/* input.netplay_client_swap_input */
NETPLAY_CFG_SWAP_INPUT = 0x0002,

/* netplay.delay_frames */
NETPLAY_CFG_DELAY_FRAMES = 0x0004,

/* For more than 2 players */
NETPLAY_CFG_PLAYER_SLOT = 0x0008
};

enum rarch_netplay_connection_mode
{
NETPLAY_CONNECTION_NONE = 0,
Expand Down Expand Up @@ -421,8 +406,8 @@ struct netplay
bool local_paused;
bool remote_paused;

/* Old-style stalling (to be removed) */
uint32_t delay_frames;
/* If true, never progress without peer input (stateless/rewindless mode) */
bool stateless_mode;

/* We stall if we're far enough ahead that we couldn't transparently rewind.
* To know if we could transparently rewind, we need to know how long
Expand Down Expand Up @@ -661,7 +646,7 @@ bool netplay_wait_and_init_serialization(netplay_t *netplay);
* @port : Port of server.
* @play_password : Password required to play.
* @spectate_password : Password required to connect.
* @delay_frames : Amount of delay frames.
* @stateless_mode : Shall we run in stateless mode?
* @check_frames : Frequency with which to check CRCs.
* @cb : Libretro callbacks.
* @nat_traversal : If true, attempt NAT traversal.
Expand All @@ -675,7 +660,7 @@ bool netplay_wait_and_init_serialization(netplay_t *netplay);
*/
netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
const char *play_password, const char *spectate_password,
unsigned delay_frames, unsigned check_frames,
bool stateless_mode, unsigned check_frames,
const struct retro_callbacks *cb, bool nat_traversal, const char *nick,
uint64_t quirks);

Expand Down
3 changes: 2 additions & 1 deletion network/netplay/netplay_sync.c
Expand Up @@ -15,6 +15,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

Expand Down Expand Up @@ -203,7 +204,7 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
/* If the core can't serialize properly, we must stall for the
* remote input on EVERY frame, because we can't recover */
netplay->quirks |= NETPLAY_QUIRK_NO_SAVESTATES;
netplay->delay_frames = 0;
netplay->stateless_mode = true;
}

/* If we can't transmit savestates, we must stall until the client is ready */
Expand Down

0 comments on commit f7f6590

Please sign in to comment.