Skip to content

Commit

Permalink
Netplay netpacket connection flow improvements (#15986)
Browse files Browse the repository at this point in the history
- Allow starting netplay host while a netpacket core is running without restart
- Allow connecting to a host while a netpacket core is running without restart
- Avoid clients getting stuck in connection loop if the host has the content paused while a client connects by automatically unpausing
  • Loading branch information
schellingb authored Dec 9, 2023
1 parent 26918b2 commit f029b41
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
9 changes: 8 additions & 1 deletion menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -7701,7 +7701,14 @@ static void action_ok_netplay_enable_client_hostname_cb(void *userdata,
{
if (!string_is_empty(line))
{
if (!task_push_netplay_content_reload(line))
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE, NULL))
{
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
command_event(CMD_EVENT_NETPLAY_INIT_DIRECT, (void*)line);
menu_input_dialog_end();
retroarch_menu_running_finished(false);
}
else if (!task_push_netplay_content_reload(line))
{
#ifdef HAVE_DYNAMIC
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
Expand Down
2 changes: 1 addition & 1 deletion network/netplay/netplay_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ enum rarch_netplay_ctl_state
RARCH_NETPLAY_CTL_KICK_CLIENT,
RARCH_NETPLAY_CTL_BAN_CLIENT,
RARCH_NETPLAY_CTL_SET_CORE_PACKET_INTERFACE,
RARCH_NETPLAY_CTL_SKIP_NETPLAY_CALLBACKS,
RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE,
RARCH_NETPLAY_CTL_ALLOW_TIMESKIP
};

Expand Down
14 changes: 11 additions & 3 deletions network/netplay/netplay_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -9242,9 +9242,17 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
break;

case RARCH_NETPLAY_CTL_PAUSE:
if ( netplay
&& (!(netplay->local_paused)))
if (netplay && !netplay->local_paused)
netplay_frontend_paused(netplay, true);

if (netplay && netplay->modus == NETPLAY_MODUS_CORE_PACKET_INTERFACE)
{
/* handle new connections while paused, unpause on connect */
if (!netplay_sync_pre_frame(netplay))
netplay_disconnect(netplay);
else if (netplay_have_any_active_connection(netplay))
command_event(CMD_EVENT_UNPAUSE, NULL);
}
break;

case RARCH_NETPLAY_CTL_UNPAUSE:
Expand Down Expand Up @@ -9372,7 +9380,7 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
}
break;

case RARCH_NETPLAY_CTL_SKIP_NETPLAY_CALLBACKS:
case RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE:
ret = (net_st->core_netpacket_interface != NULL);
break;

Expand Down
7 changes: 6 additions & 1 deletion retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3958,7 +3958,12 @@ bool command_event(enum event_command cmd, void *data)
break;
case CMD_EVENT_NETPLAY_ENABLE_HOST:
{
if (!task_push_netplay_content_reload(NULL))
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE, NULL))
{
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_SERVER, NULL);
command_event(CMD_EVENT_NETPLAY_INIT, NULL);
}
else if (!task_push_netplay_content_reload(NULL))
{
#ifdef HAVE_DYNAMIC
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
Expand Down
4 changes: 2 additions & 2 deletions runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -7445,7 +7445,7 @@ bool core_set_netplay_callbacks(void)
{
runloop_state_t *runloop_st = &runloop_state;

if (netplay_driver_ctl(RARCH_NETPLAY_CTL_SKIP_NETPLAY_CALLBACKS, NULL))
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE, NULL))
return true;

/* Force normal poll type for netplay. */
Expand Down Expand Up @@ -8031,7 +8031,7 @@ void runloop_path_set_redirect(settings_t *settings,
/* Special save directory for netplay clients. */
if ( netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)
&& !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER, NULL)
&& !netplay_driver_ctl(RARCH_NETPLAY_CTL_SKIP_NETPLAY_CALLBACKS, NULL))
&& !netplay_driver_ctl(RARCH_NETPLAY_CTL_USE_CORE_PACKET_INTERFACE, NULL))
{
fill_pathname_join(new_savefile_dir, new_savefile_dir, ".netplay",
sizeof(new_savefile_dir));
Expand Down

0 comments on commit f029b41

Please sign in to comment.