diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 6c3066f8a2..6c6c82bffa 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -303,6 +303,11 @@ static bool netplay_poll(void) break; } + case NETPLAY_STALL_SPECTATOR_WAIT: + if (netplay_data->unread_frame_count > netplay_data->self_frame_count) + netplay_data->stall = NETPLAY_STALL_NONE; + break; + case NETPLAY_STALL_INPUT_LATENCY: /* Just let it recalculate momentarily */ netplay_data->stall = NETPLAY_STALL_NONE; @@ -374,6 +379,16 @@ static bool netplay_poll(void) } } + + /* If we're a spectator, are we ahead at all? */ + if (!netplay_data->is_server && + (netplay_data->self_mode == NETPLAY_CONNECTION_SPECTATING || + netplay_data->self_mode == NETPLAY_CONNECTION_SLAVE) && + netplay_data->unread_frame_count <= netplay_data->self_frame_count) + { + netplay_data->stall = NETPLAY_STALL_SPECTATOR_WAIT; + netplay_data->stall_time = cpu_features_get_time_usec(); + } } /* If we're stalling, consider disconnection */ diff --git a/network/netplay/netplay_private.h b/network/netplay/netplay_private.h index 956a4e5147..cbd7a999a5 100644 --- a/network/netplay/netplay_private.h +++ b/network/netplay/netplay_private.h @@ -215,9 +215,21 @@ enum rarch_netplay_connection_mode enum rarch_netplay_stall_reason { NETPLAY_STALL_NONE = 0, + + /* We're so far ahead that we can't read more data without overflowing the + * buffer */ NETPLAY_STALL_RUNNING_FAST, + + /* We're in spectator or slave mode and are running ahead at all */ + NETPLAY_STALL_SPECTATOR_WAIT, + + /* Our actual execution is catching up with latency-adjusted input frames */ NETPLAY_STALL_INPUT_LATENCY, + + /* The server asked us to stall */ NETPLAY_STALL_SERVER_REQUESTED, + + /* We have no connection and must have one to proceed */ NETPLAY_STALL_NO_CONNECTION };