1
0
mirror of https://github.com/libretro/RetroArch synced 2025-03-26 20:37:10 +00:00

When we replay, resimulate input so that it doesn't judder between

remote states
This commit is contained in:
Gregor Richards 2016-09-24 08:12:08 -04:00
parent 83be6daa93
commit fcd57801bd
3 changed files with 18 additions and 7 deletions

@ -554,13 +554,17 @@ static int poll_input(netplay_t *netplay, bool block)
return 0;
}
/* TODO: Somewhat better prediction. :P */
static void simulate_input(netplay_t *netplay)
/**
* netplay_simulate_input:
* @netplay : pointer to netplay object
* @sim_ptr : frame index for which to simulate input
*
* "Simulate" input by assuming it hasn't changed since the last read input.
*/
void netplay_simulate_input(netplay_t *netplay, uint32_t sim_ptr)
{
size_t ptr = netplay->self_ptr;
size_t prev = PREV_PTR(netplay->read_ptr);
memcpy(netplay->buffer[ptr].simulated_input_state,
memcpy(netplay->buffer[sim_ptr].simulated_input_state,
netplay->buffer[prev].real_input_state,
sizeof(netplay->buffer[prev].real_input_state));
}
@ -603,7 +607,7 @@ static bool netplay_poll(netplay_t *netplay)
/* Simulate the input if we don't have real input */
if (!netplay->buffer[netplay->self_ptr].have_remote)
simulate_input(netplay);
netplay_simulate_input(netplay, netplay->self_ptr);
/* Consider stalling */
switch (netplay->stall) {

@ -214,9 +214,14 @@ static void netplay_net_post_frame(netplay_t *netplay)
serial_info.size = netplay->state_size;
serial_info.data_const = NULL;
/* Remember the current state */
core_serialize(&serial_info);
if (netplay->replay_frame_count < netplay->read_frame_count)
netplay_handle_frame_hash(netplay, ptr);
netplay_handle_frame_hash(netplay, ptr);
/* Simulate this frame's input */
if (netplay->replay_frame_count >= netplay->read_frame_count)
netplay_simulate_input(netplay, netplay->replay_ptr);
#if defined(HAVE_THREADS)
autosave_lock();

@ -177,6 +177,8 @@ struct netplay_callbacks* netplay_get_cbs_net(void);
struct netplay_callbacks* netplay_get_cbs_spectate(void);
void netplay_simulate_input(netplay_t *netplay, uint32_t sim_ptr);
void netplay_log_connection(const struct sockaddr_storage *their_addr,
unsigned slot, const char *nick);