Renaming input_ptr/input_frame_count back to self_.

This commit is contained in:
Gregor Richards 2017-01-20 14:28:18 -05:00
parent 4ff8982355
commit 2ea3936d16
6 changed files with 63 additions and 58 deletions

View File

@ -42,6 +42,10 @@ In general, other ≤ unread and other ≤ self. In all likelihood, unread ≤ s
but it is both possible and supported for the remote host to get ahead of the
local host.
There is an additional location, run, used when input latency is desired. In
that case, self points to where input is being read, and run points to the
frame actually being executed. Run is purely local.
The server has a slightly more complicated job as it can handle multiple
clients, however it is not vastly more complicated: For each connection which
is playing (i.e., has a controller), it maintains a per-player unread frame,

View File

@ -106,10 +106,10 @@ static bool netplay_can_poll(netplay_t *netplay)
static bool get_self_input_state(netplay_t *netplay)
{
uint32_t state[WORDS_PER_INPUT] = {0, 0, 0};
struct delta_frame *ptr = &netplay->buffer[netplay->input_ptr];
struct delta_frame *ptr = &netplay->buffer[netplay->self_ptr];
size_t i;
if (!netplay_delta_frame_ready(netplay, ptr, netplay->input_frame_count))
if (!netplay_delta_frame_ready(netplay, ptr, netplay->self_frame_count))
return false;
if (ptr->have_local)
@ -118,7 +118,7 @@ static bool get_self_input_state(netplay_t *netplay)
return true;
}
if (!input_driver_is_libretro_input_blocked() && netplay->input_frame_count > 0)
if (!input_driver_is_libretro_input_blocked() && netplay->self_frame_count > 0)
{
/* First frame we always give zero input since relying on
* input from first frame screws up when we use -F 0. */
@ -264,7 +264,7 @@ static bool netplay_poll(void)
case NETPLAY_STALL_RUNNING_FAST:
{
if (netplay_data->unread_frame_count + NETPLAY_MAX_STALL_FRAMES - 2
> netplay_data->input_frame_count)
> netplay_data->self_frame_count)
{
netplay_data->stall = NETPLAY_STALL_NONE;
for (i = 0; i < netplay_data->connections_size; i++)
@ -312,7 +312,7 @@ static bool netplay_poll(void)
/* Have we not reat enough latency frames? */
if (netplay_data->self_mode == NETPLAY_CONNECTION_PLAYING &&
netplay_data->connected_players &&
netplay_data->run_frame_count + netplay_data->input_latency_frames > netplay_data->input_frame_count)
netplay_data->run_frame_count + netplay_data->input_latency_frames > netplay_data->self_frame_count)
{
netplay_data->stall = NETPLAY_STALL_INPUT_LATENCY;
netplay_data->stall_time = 0;
@ -320,7 +320,7 @@ static bool netplay_poll(void)
/* Are we too far ahead? */
if (netplay_data->unread_frame_count + NETPLAY_MAX_STALL_FRAMES
<= netplay_data->input_frame_count)
<= netplay_data->self_frame_count)
{
netplay_data->stall = NETPLAY_STALL_RUNNING_FAST;
netplay_data->stall_time = cpu_features_get_time_usec();
@ -546,7 +546,7 @@ static void netplay_flip_users(netplay_t *netplay)
{
/* Must be in the future because we may have
* already sent this frame's data */
uint32_t flip_frame = netplay->input_frame_count + 1;
uint32_t flip_frame = netplay->self_frame_count + 1;
uint32_t flip_frame_net = htonl(flip_frame);
size_t i;
@ -777,8 +777,8 @@ void netplay_load_savestate(netplay_t *netplay,
/* Wherever we're inputting, that's where we consider our state to be loaded
* (FIXME: Need to be more careful about saving it?) */
netplay->run_ptr = netplay->input_ptr;
netplay->run_frame_count = netplay->input_frame_count;
netplay->run_ptr = netplay->self_ptr;
netplay->run_frame_count = netplay->self_frame_count;
/* Record it in our own buffer */
if (save || !serial_info)
@ -866,7 +866,7 @@ static void netplay_toggle_play_spectate(netplay_t *netplay)
uint32_t payload[2];
char msg[512];
const char *dmsg = NULL;
payload[0] = htonl(netplay->input_frame_count);
payload[0] = htonl(netplay->self_frame_count);
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING)
{
/* Mark us as no longer playing */

View File

@ -518,7 +518,7 @@ bool netplay_handshake_sync(netplay_t *netplay, struct netplay_connection *conne
cmd[0] = htonl(NETPLAY_CMD_SYNC);
cmd[1] = htonl(3*sizeof(uint32_t) + MAX_USERS*sizeof(uint32_t) +
NETPLAY_NICK_LEN + mem_info.size);
cmd[2] = htonl(netplay->input_frame_count);
cmd[2] = htonl(netplay->self_frame_count);
connected_players = netplay->connected_players;
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING)
connected_players |= 1<<netplay->self_player;
@ -904,7 +904,7 @@ bool netplay_handshake_pre_sync(netplay_t *netplay,
netplay->flip_frame = flip_frame;
/* Set our frame counters as requested */
netplay->input_frame_count = netplay->run_frame_count =
netplay->self_frame_count = netplay->run_frame_count =
netplay->other_frame_count = netplay->unread_frame_count =
netplay->server_frame_count = new_frame_count;
for (i = 0; i < netplay->buffer_size; i++)
@ -912,7 +912,7 @@ bool netplay_handshake_pre_sync(netplay_t *netplay,
struct delta_frame *ptr = &netplay->buffer[i];
ptr->used = false;
if (i == netplay->input_ptr)
if (i == netplay->self_ptr)
{
/* Clear out any current data but still use this frame */
if (!netplay_delta_frame_ready(netplay, ptr, 0))
@ -928,8 +928,8 @@ bool netplay_handshake_pre_sync(netplay_t *netplay,
{
if (connected_players & (1<<i))
{
netplay->read_ptr[i] = netplay->input_ptr;
netplay->read_frame_count[i] = netplay->input_frame_count;
netplay->read_ptr[i] = netplay->self_ptr;
netplay->read_frame_count[i] = netplay->self_frame_count;
}
}

View File

@ -38,7 +38,7 @@ static void print_state(netplay_t *netplay)
#define APPEND(out) cur += snprintf out
#define M msg + cur, sizeof(msg) - cur
APPEND((M, "NETPLAY: S:%u U:%u O:%u", netplay->input_frame_count, netplay->unread_frame_count, netplay->other_frame_count));
APPEND((M, "NETPLAY: S:%u U:%u O:%u", netplay->self_frame_count, netplay->unread_frame_count, netplay->other_frame_count));
if (!netplay->is_server)
APPEND((M, " H:%u", netplay->server_frame_count));
for (player = 0; player < MAX_USERS; player++)
@ -204,7 +204,7 @@ static bool send_input_frame(netplay_t *netplay,
bool netplay_send_cur_input(netplay_t *netplay,
struct netplay_connection *connection)
{
struct delta_frame *dframe = &netplay->buffer[netplay->input_ptr];
struct delta_frame *dframe = &netplay->buffer[netplay->self_ptr];
uint32_t player;
if (netplay->is_server)
@ -220,7 +220,7 @@ bool netplay_send_cur_input(netplay_t *netplay,
if (dframe->have_real[player])
{
if (!send_input_frame(netplay, connection, NULL,
netplay->input_frame_count, player,
netplay->self_frame_count, player,
dframe->real_input_state[player]))
return false;
}
@ -230,7 +230,7 @@ bool netplay_send_cur_input(netplay_t *netplay,
/* If we're not playing, send a NOINPUT */
if (netplay->self_mode != NETPLAY_CONNECTION_PLAYING)
{
uint32_t payload = htonl(netplay->input_frame_count);
uint32_t payload = htonl(netplay->self_frame_count);
if (!netplay_send_raw_cmd(netplay, connection, NETPLAY_CMD_NOINPUT,
&payload, sizeof(payload)))
return false;
@ -242,7 +242,7 @@ bool netplay_send_cur_input(netplay_t *netplay,
if (netplay->self_mode == NETPLAY_CONNECTION_PLAYING)
{
if (!send_input_frame(netplay, connection, NULL,
netplay->input_frame_count,
netplay->self_frame_count,
(netplay->is_server ? NETPLAY_CMD_INPUT_BIT_SERVER : 0) | netplay->self_player,
dframe->self_state))
return false;
@ -505,7 +505,7 @@ static bool netplay_get_cmd(netplay_t *netplay,
if (netplay->is_server)
{
/* Forward it on if it's past data*/
if (dframe->frame <= netplay->input_frame_count)
if (dframe->frame <= netplay->self_frame_count)
send_input_frame(netplay, NULL, connection, buffer[0],
player, dframe->real_input_state[player]);
}
@ -585,7 +585,7 @@ static bool netplay_get_cmd(netplay_t *netplay,
/* Force a rewind to assure the flip happens: This just prevents us
* from skipping other past the flip because our prediction was
* correct */
if (flip_frame < netplay->input_frame_count)
if (flip_frame < netplay->self_frame_count)
netplay->force_rewind = true;
RARCH_LOG("%s.\n", msg_hash_to_str(MSG_NETPLAY_USERS_HAS_FLIPPED));
@ -638,7 +638,7 @@ static bool netplay_get_cmd(netplay_t *netplay,
{
uint32_t payload[2];
uint32_t player = 0;
payload[0] = htonl(netplay->input_frame_count + 1);
payload[0] = htonl(netplay->self_frame_count + 1);
if (!netplay->is_server)
{
@ -695,8 +695,8 @@ static bool netplay_get_cmd(netplay_t *netplay,
netplay_send_raw_cmd(netplay, connection, NETPLAY_CMD_MODE, payload, sizeof(payload));
/* And expect their data */
netplay->read_ptr[player] = NEXT_PTR(netplay->input_ptr);
netplay->read_frame_count[player] = netplay->input_frame_count + 1;
netplay->read_ptr[player] = NEXT_PTR(netplay->self_ptr);
netplay->read_frame_count[player] = netplay->self_frame_count + 1;
break;
}
@ -734,7 +734,7 @@ static bool netplay_get_cmd(netplay_t *netplay,
frame = ntohl(payload[0]);
/* We're changing past input, so must replay it */
if (frame < netplay->input_frame_count)
if (frame < netplay->self_frame_count)
netplay->force_rewind = true;
mode = ntohl(payload[1]);
@ -767,16 +767,16 @@ static bool netplay_get_cmd(netplay_t *netplay,
netplay->self_player = player;
/* Fix up current frame info */
if (frame <= netplay->input_frame_count)
if (frame <= netplay->self_frame_count)
{
/* It wanted past frames, better send 'em! */
START(netplay->server_ptr);
while (dframe->used && dframe->frame <= netplay->input_frame_count)
while (dframe->used && dframe->frame <= netplay->self_frame_count)
{
memcpy(dframe->real_input_state[player], dframe->self_state, sizeof(dframe->self_state));
dframe->have_real[player] = true;
send_input_frame(netplay, connection, NULL, dframe->frame, player, dframe->self_state);
if (dframe->frame == netplay->input_frame_count) break;
if (dframe->frame == netplay->self_frame_count) break;
NEXT();
}
@ -786,8 +786,8 @@ static bool netplay_get_cmd(netplay_t *netplay,
uint32_t frame_count;
/* It wants future frames, make sure we don't capture or send intermediate ones */
START(netplay->input_ptr);
frame_count = netplay->input_frame_count;
START(netplay->self_ptr);
frame_count = netplay->self_frame_count;
while (true)
{
if (!dframe->used)
@ -1143,10 +1143,10 @@ static bool netplay_get_cmd(netplay_t *netplay,
* will make the other side unhappy. */
netplay->run_ptr = PREV_PTR(netplay->read_ptr[connection->player]);
netplay->run_frame_count = frame - 1;
if (frame > netplay->input_frame_count)
if (frame > netplay->self_frame_count)
{
netplay->input_ptr = netplay->run_ptr;
netplay->input_frame_count = netplay->run_frame_count;
netplay->self_ptr = netplay->run_ptr;
netplay->self_frame_count = netplay->run_frame_count;
}
}
@ -1353,7 +1353,7 @@ int netplay_poll_net_input(netplay_t *netplay, bool block)
*/
bool netplay_flip_port(netplay_t *netplay)
{
size_t frame = netplay->input_frame_count;
size_t frame = netplay->self_frame_count;
if (netplay->flip_frame == 0)
return false;

View File

@ -359,10 +359,11 @@ struct netplay
size_t packet_buffer_size;
/* The frame we're currently inputting */
size_t input_ptr;
uint32_t input_frame_count;
size_t self_ptr;
uint32_t self_frame_count;
/* The frame we're currently running */
/* The frame we're currently running, which may be behind the frame we're
* currently inputting if we're using input latency */
size_t run_ptr;
uint32_t run_frame_count;

View File

@ -42,8 +42,8 @@ void netplay_update_unread_ptr(netplay_t *netplay)
if (netplay->is_server && !netplay->connected_players)
{
/* Nothing at all to read! */
netplay->unread_ptr = netplay->input_ptr;
netplay->unread_frame_count = netplay->input_frame_count;
netplay->unread_ptr = netplay->self_ptr;
netplay->unread_frame_count = netplay->self_frame_count;
}
else
@ -203,13 +203,13 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
{
/* Bring our running frame and input frames into parity so we don't
* send old info */
if (netplay->run_ptr != netplay->input_ptr)
if (netplay->run_ptr != netplay->self_ptr)
{
memcpy(netplay->buffer[netplay->input_ptr].state,
memcpy(netplay->buffer[netplay->self_ptr].state,
netplay->buffer[netplay->run_ptr].state,
netplay->state_size);
netplay->run_ptr = netplay->input_ptr;
netplay->run_frame_count = netplay->input_frame_count;
netplay->run_ptr = netplay->self_ptr;
netplay->run_frame_count = netplay->self_frame_count;
}
/* Send this along to the other side */
@ -372,20 +372,20 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
netplay->run_frame_count++;
}
/* We've finished an input frame even if we're stalling, unless we're too
* far ahead of ourselves */
if (netplay->input_frame_count < netplay->run_frame_count + netplay->input_latency_frames)
/* We've finished an input frame even if we're stalling */
if ((!stalled || netplay->stall == NETPLAY_STALL_INPUT_LATENCY) &&
netplay->self_frame_count < netplay->run_frame_count + netplay->input_latency_frames)
{
netplay->input_ptr = NEXT_PTR(netplay->input_ptr);
netplay->input_frame_count++;
netplay->self_ptr = NEXT_PTR(netplay->self_ptr);
netplay->self_frame_count++;
}
/* Only relevant if we're connected */
if ((netplay->is_server && !netplay->connected_players) ||
(netplay->self_mode < NETPLAY_CONNECTION_CONNECTED))
{
netplay->other_frame_count = netplay->input_frame_count;
netplay->other_ptr = netplay->input_ptr;
netplay->other_frame_count = netplay->self_frame_count;
netplay->other_ptr = netplay->self_ptr;
/* FIXME: Duplication */
if (netplay->catch_up)
{
@ -539,7 +539,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
if (netplay->catch_up)
{
/* Are we caught up? */
if (netplay->input_frame_count >= lo_frame_count)
if (netplay->self_frame_count >= lo_frame_count)
{
netplay->catch_up = false;
input_driver_unset_nonblock_state();
@ -549,7 +549,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
}
else if (!stalled)
{
if (netplay->input_frame_count + 2 < lo_frame_count)
if (netplay->self_frame_count + 2 < lo_frame_count)
{
/* Are we falling behind? */
netplay->catch_up = true;
@ -557,7 +557,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
driver_set_nonblock_state();
}
else if (netplay->input_frame_count + 2 < hi_frame_count)
else if (netplay->self_frame_count + 2 < hi_frame_count)
{
size_t i;
@ -573,16 +573,16 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
player = connection->player;
/* Are they ahead? */
if (netplay->input_frame_count + 2 < netplay->read_frame_count[player])
if (netplay->self_frame_count + 2 < netplay->read_frame_count[player])
{
/* Tell them to stall */
if (connection->stall_frame + NETPLAY_MAX_REQ_STALL_FREQUENCY <
netplay->input_frame_count)
netplay->self_frame_count)
{
connection->stall_frame = netplay->input_frame_count;
connection->stall_frame = netplay->self_frame_count;
netplay_cmd_stall(netplay, connection,
netplay->read_frame_count[player] -
netplay->input_frame_count + 1);
netplay->self_frame_count + 1);
}
}
}