Moving Netplay pre- and post-frame behavior into core_run

This (mostly) prevents other paths from accidentally side-stepping
Netplay. Netplay itself now sets an in_netplay variable to avoid
self-recursion in its own core_run calls.
This commit is contained in:
Gregor Richards 2016-10-04 13:40:07 -04:00
parent e5970e8095
commit 71873e8c97
3 changed files with 41 additions and 26 deletions

View File

@ -368,6 +368,14 @@ bool core_unload_game(void)
bool core_run(void)
{
#ifdef HAVE_NETWORKING
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_PRE_FRAME, NULL))
{
/* Paused due to Netplay */
return true;
}
#endif
switch (core_poll_type)
{
case POLL_TYPE_EARLY:
@ -384,6 +392,11 @@ bool core_run(void)
core.retro_run();
if (core_poll_type == POLL_TYPE_LATE && !core_input_polled)
input_poll();
#ifdef HAVE_NETWORKING
netplay_driver_ctl(RARCH_NETPLAY_CTL_POST_FRAME, NULL);
#endif
return true;
}

View File

@ -56,6 +56,9 @@ static bool netplay_is_client = false;
/* Used while Netplay is running */
static netplay_t *netplay_data = NULL;
/* Used to avoid recursive netplay calls */
static bool in_netplay = false;
static int init_tcp_connection(const struct addrinfo *res,
bool server, bool spectate,
struct sockaddr *other_addr, socklen_t addr_size)
@ -1373,6 +1376,12 @@ bool init_netplay(bool is_spectate, const char *server, unsigned port)
bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
{
bool ret = true;
if (in_netplay)
return true;
in_netplay = true;
if (!netplay_data)
{
switch (state)
@ -1380,7 +1389,7 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
case RARCH_NETPLAY_CTL_ENABLE_SERVER:
netplay_enabled = true;
netplay_is_client = false;
return true;
goto done;
case RARCH_NETPLAY_CTL_ENABLE_CLIENT:
netplay_enabled = true;
@ -1389,16 +1398,18 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
case RARCH_NETPLAY_CTL_DISABLE:
netplay_enabled = false;
return true;
goto done;
case RARCH_NETPLAY_CTL_IS_ENABLED:
return netplay_enabled;
ret = netplay_enabled;
goto done;
case RARCH_NETPLAY_CTL_IS_DATA_INITED:
return false;
ret = false;
goto done;
default:
return true;
goto done;
}
}
@ -1407,16 +1418,18 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
case RARCH_NETPLAY_CTL_ENABLE_SERVER:
case RARCH_NETPLAY_CTL_ENABLE_CLIENT:
case RARCH_NETPLAY_CTL_IS_DATA_INITED:
return true;
goto done;
case RARCH_NETPLAY_CTL_DISABLE:
return false;
ret = false;
goto done;
case RARCH_NETPLAY_CTL_IS_ENABLED:
return true;
goto done;
case RARCH_NETPLAY_CTL_POST_FRAME:
netplay_post_frame(netplay_data);
break;
case RARCH_NETPLAY_CTL_PRE_FRAME:
return netplay_pre_frame(netplay_data);
ret = netplay_pre_frame(netplay_data);
goto done;
case RARCH_NETPLAY_CTL_FLIP_PLAYERS:
{
bool *state = (bool*)data;
@ -1441,11 +1454,14 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
netplay_load_savestate(netplay_data, (retro_ctx_serialize_info_t*)data, true);
break;
case RARCH_NETPLAY_CTL_DISCONNECT:
return netplay_disconnect(netplay_data);
ret = netplay_disconnect(netplay_data);
goto done;
default:
case RARCH_NETPLAY_CTL_NONE:
break;
ret = false;
}
return false;
done:
in_netplay = false;
return ret;
}

View File

@ -1330,16 +1330,6 @@ int runloop_iterate(unsigned *sleep_ms)
autosave_lock();
#ifdef HAVE_NETWORKING
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_PRE_FRAME, NULL))
{
/* Paused due to Netplay */
core_poll();
*sleep_ms = 10;
return 1;
}
#endif
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
bsv_movie_ctl(BSV_MOVIE_CTL_SET_FRAME_START, NULL);
@ -1379,10 +1369,6 @@ int runloop_iterate(unsigned *sleep_ms)
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
bsv_movie_ctl(BSV_MOVIE_CTL_SET_FRAME_END, NULL);
#ifdef HAVE_NETWORKING
netplay_driver_ctl(RARCH_NETPLAY_CTL_POST_FRAME, NULL);
#endif
autosave_unlock();
if (!settings->fastforward_ratio)