Support for catching up if the netplay peer is ahead of us.

This commit is contained in:
Gregor Richards 2016-12-15 11:04:05 -05:00
parent 4e01481b39
commit bade067d9a
5 changed files with 19 additions and 0 deletions

View File

@ -43,6 +43,7 @@ enum rarch_netplay_ctl_state
RARCH_NETPLAY_CTL_IS_DATA_INITED, RARCH_NETPLAY_CTL_IS_DATA_INITED,
RARCH_NETPLAY_CTL_PAUSE, RARCH_NETPLAY_CTL_PAUSE,
RARCH_NETPLAY_CTL_UNPAUSE, RARCH_NETPLAY_CTL_UNPAUSE,
RARCH_NETPLAY_CTL_CATCH_UP,
RARCH_NETPLAY_CTL_LOAD_SAVESTATE, RARCH_NETPLAY_CTL_LOAD_SAVESTATE,
RARCH_NETPLAY_CTL_DISCONNECT RARCH_NETPLAY_CTL_DISCONNECT
}; };

View File

@ -927,6 +927,9 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
case RARCH_NETPLAY_CTL_UNPAUSE: case RARCH_NETPLAY_CTL_UNPAUSE:
netplay_frontend_paused(netplay_data, false); netplay_frontend_paused(netplay_data, false);
break; break;
case RARCH_NETPLAY_CTL_CATCH_UP:
ret = netplay_data->catch_up;
break;
case RARCH_NETPLAY_CTL_LOAD_SAVESTATE: case RARCH_NETPLAY_CTL_LOAD_SAVESTATE:
netplay_load_savestate(netplay_data, (retro_ctx_serialize_info_t*)data, true); netplay_load_savestate(netplay_data, (retro_ctx_serialize_info_t*)data, true);
break; break;

View File

@ -409,6 +409,9 @@ struct netplay
enum rarch_netplay_stall_reason stall; enum rarch_netplay_stall_reason stall;
retro_time_t stall_time; retro_time_t stall_time;
/* Opposite of stalling, should we be catching up? */
bool catch_up;
/* Frequency with which to check CRCs */ /* Frequency with which to check CRCs */
uint32_t check_frames; uint32_t check_frames;
}; };

View File

@ -347,6 +347,7 @@ void netplay_sync_post_frame(netplay_t *netplay)
{ {
netplay->other_frame_count = netplay->self_frame_count; netplay->other_frame_count = netplay->self_frame_count;
netplay->other_ptr = netplay->self_ptr; netplay->other_ptr = netplay->self_ptr;
netplay->catch_up = false;
return; return;
} }
@ -454,6 +455,12 @@ void netplay_sync_post_frame(netplay_t *netplay)
netplay->force_rewind = false; netplay->force_rewind = false;
} }
/* If we're behind, try to catch up */
if (netplay->self_frame_count < netplay->unread_frame_count - 2)
netplay->catch_up = true;
else
netplay->catch_up = false;
/* If we're supposed to stall, rewind (we shouldn't get this far if we're /* If we're supposed to stall, rewind (we shouldn't get this far if we're
* stalled, so this is a last resort) */ * stalled, so this is a last resort) */
if (netplay->stall) if (netplay->stall)

View File

@ -1226,6 +1226,11 @@ int runloop_iterate(unsigned *sleep_ms)
if (!settings->fastforward_ratio) if (!settings->fastforward_ratio)
return 0; return 0;
#ifdef HAVE_NETWORKING
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_CATCH_UP, NULL))
return 0;
#endif
end: end:
current = cpu_features_get_time_usec(); current = cpu_features_get_time_usec();