This commit is contained in:
twinaphex 2020-01-28 15:14:29 +01:00
parent 646eba5a92
commit 399f039b9e

View File

@ -123,25 +123,18 @@ static bool netplay_can_poll(netplay_t *netplay)
* *
* Returns: true (1) if successful, otherwise false (0). * Returns: true (1) if successful, otherwise false (0).
*/ */
static bool get_self_input_state(netplay_t *netplay) static bool get_self_input_state(netplay_t *netplay, struct delta_frame *ptr)
{ {
unsigned i; unsigned i;
struct delta_frame *ptr = &netplay->buffer[netplay->self_ptr];
netplay_input_state_t istate = NULL; netplay_input_state_t istate = NULL;
uint32_t devices, used_devices = 0, devi, dev_type, local_device; uint32_t devi, dev_type;
uint32_t devices = netplay->self_devices;
if (!netplay_delta_frame_ready(netplay, ptr, netplay->self_frame_count)) uint32_t used_devices = 0;
return false;
/* We've already read this frame! */
if (ptr->have_local)
return true;
devices = netplay->self_devices;
used_devices = 0;
for (devi = 0; devi < MAX_INPUT_DEVICES; devi++) for (devi = 0; devi < MAX_INPUT_DEVICES; devi++)
{ {
uint32_t local_device;
if (!(devices & (1 << devi))) if (!(devices & (1 << devi)))
continue; continue;
@ -160,17 +153,20 @@ static bool get_self_input_state(netplay_t *netplay)
local_device = 0; local_device = 0;
used_devices |= (1 << local_device); used_devices |= (1 << local_device);
istate = netplay_input_state_for(&ptr->real_input[devi], /* If we're a slave, we write our own input to MAX_CLIENTS
/* If we're a slave, we write our own input to MAX_CLIENTS to keep it separate */ * to keep it separate */
(netplay->self_mode==NETPLAY_CONNECTION_SLAVE)?MAX_CLIENTS:netplay->self_client_num, if (!(istate = netplay_input_state_for(&ptr->real_input[devi],
(netplay->self_mode == NETPLAY_CONNECTION_SLAVE)
? MAX_CLIENTS
: netplay->self_client_num,
netplay_expected_input_size(netplay, 1 << devi), netplay_expected_input_size(netplay, 1 << devi),
true, false); true, false)))
if (!istate)
continue; /* FIXME: More severe? */ continue; /* FIXME: More severe? */
/* First frame we always give zero input since relying on /* First frame we always give zero input since relying on
* input from first frame screws up when we use -F 0. */ * input from first frame screws up when we use -F 0. */
if (!input_driver_is_libretro_input_blocked() && netplay->self_frame_count > 0) if (!input_driver_is_libretro_input_blocked()
&& netplay->self_frame_count > 0)
{ {
uint32_t *state = istate->data; uint32_t *state = istate->data;
retro_input_state_t cb = netplay->cbs.state_cb; retro_input_state_t cb = netplay->cbs.state_cb;
@ -289,20 +285,23 @@ bool init_netplay_deferred(const char* server, unsigned port)
static bool netplay_poll(netplay_t *netplay) static bool netplay_poll(netplay_t *netplay)
{ {
int res; int res;
uint32_t client;
size_t i; size_t i;
uint32_t client;
struct delta_frame *ptr = &netplay->buffer[netplay->self_ptr];
netplay->can_poll = false; netplay->can_poll = false;
if (!get_self_input_state(netplay)) if (netplay_delta_frame_ready(netplay, ptr, netplay->self_frame_count))
if (!ptr->have_local) /* if true, we have already read this frame */
if (!get_self_input_state(netplay, ptr))
goto catastrophe; goto catastrophe;
/* If we're not connected, we're done */ /* If we're not connected, we're done */
if (netplay->self_mode == NETPLAY_CONNECTION_NONE) if (netplay->self_mode == NETPLAY_CONNECTION_NONE)
return true; return true;
/* Read Netplay input, block if we're configured to stall for input every /* Read Netplay input, block if we're configured
* frame */ * to stall for input every frame */
netplay_update_unread_ptr(netplay); netplay_update_unread_ptr(netplay);
if (netplay->stateless_mode && if (netplay->stateless_mode &&
(netplay->connected_players>1) && (netplay->connected_players>1) &&
@ -932,11 +931,7 @@ bool netplay_command(netplay_t* netplay, struct netplay_connection *connection,
static void netplay_frontend_paused(netplay_t *netplay, bool paused) static void netplay_frontend_paused(netplay_t *netplay, bool paused)
{ {
size_t i; size_t i;
uint32_t paused_ct; uint32_t paused_ct = 0;
/* Nothing to do if we already knew this */
if (netplay->local_paused == paused)
return;
netplay->local_paused = paused; netplay->local_paused = paused;
@ -944,22 +939,26 @@ static void netplay_frontend_paused(netplay_t *netplay, bool paused)
* paused, then we must tell them that we're unpaused, as from their * paused, then we must tell them that we're unpaused, as from their
* perspective we are. If more than one other connection is paused, then our * perspective we are. If more than one other connection is paused, then our
* status as proxy means we are NOT unpaused to either of them. */ * status as proxy means we are NOT unpaused to either of them. */
paused_ct = 0;
for (i = 0; i < netplay->connections_size; i++) for (i = 0; i < netplay->connections_size; i++)
{ {
struct netplay_connection *connection = &netplay->connections[i]; struct netplay_connection *connection = &netplay->connections[i];
if (connection->active && connection->paused) if (connection->active && connection->paused)
paused_ct++; paused_ct++;
} }
if (paused_ct > 1) if (paused_ct > 1)
return; return;
/* Send our unpaused status. Must send manually because we must immediately /* Send our unpaused status. Must send manually because
* flush the buffer: If we're paused, we won't be polled. */ * we must immediately flush the buffer: If we're paused,
* we won't be polled. */
for (i = 0; i < netplay->connections_size; i++) for (i = 0; i < netplay->connections_size; i++)
{ {
struct netplay_connection *connection = &netplay->connections[i]; struct netplay_connection *connection = &netplay->connections[i];
if (connection->active && connection->mode >= NETPLAY_CONNECTION_CONNECTED)
if ( connection->active &&
connection->mode >= NETPLAY_CONNECTION_CONNECTED)
{ {
if (paused) if (paused)
netplay_send_raw_cmd(netplay, connection, NETPLAY_CMD_PAUSE, netplay_send_raw_cmd(netplay, connection, NETPLAY_CMD_PAUSE,
@ -968,8 +967,10 @@ static void netplay_frontend_paused(netplay_t *netplay, bool paused)
netplay_send_raw_cmd(netplay, connection, NETPLAY_CMD_RESUME, netplay_send_raw_cmd(netplay, connection, NETPLAY_CMD_RESUME,
NULL, 0); NULL, 0);
/* We're not going to be polled, so we need to flush this command now */ /* We're not going to be polled, so we need to
netplay_send_flush(&connection->send_packet_buffer, connection->fd, true); * flush this command now */
netplay_send_flush(&connection->send_packet_buffer,
connection->fd, true);
} }
} }
} }
@ -1201,10 +1202,17 @@ void netplay_load_savestate(netplay_t *netplay,
/* Record it in our own buffer */ /* Record it in our own buffer */
if (save || !serial_info) if (save || !serial_info)
{ {
if (netplay_delta_frame_ready(netplay, if (!netplay_delta_frame_ready(netplay,
&netplay->buffer[netplay->run_ptr], netplay->run_frame_count)) &netplay->buffer[netplay->run_ptr], netplay->run_frame_count))
return; /* FIXME: This is a critical failure! */
if (serial_info)
{ {
if (!serial_info) if (serial_info->size <= netplay->state_size)
memcpy(netplay->buffer[netplay->run_ptr].state,
serial_info->data_const, serial_info->size);
}
else
{ {
tmp_serial_info.size = netplay->state_size; tmp_serial_info.size = netplay->state_size;
tmp_serial_info.data = netplay->buffer[netplay->run_ptr].state; tmp_serial_info.data = netplay->buffer[netplay->run_ptr].state;
@ -1213,16 +1221,6 @@ void netplay_load_savestate(netplay_t *netplay,
tmp_serial_info.data_const = tmp_serial_info.data; tmp_serial_info.data_const = tmp_serial_info.data;
serial_info = &tmp_serial_info; serial_info = &tmp_serial_info;
} }
else
{
if (serial_info->size <= netplay->state_size)
memcpy(netplay->buffer[netplay->run_ptr].state,
serial_info->data_const, serial_info->size);
}
}
/* FIXME: This is a critical failure! */
else
return;
} }
/* Don't send it if we're expected to be desynced */ /* Don't send it if we're expected to be desynced */
@ -1279,7 +1277,8 @@ static void netplay_core_reset(netplay_t *netplay)
* *
* Get the preferred share mode * Get the preferred share mode
*/ */
uint8_t netplay_settings_share_mode(unsigned share_digital, unsigned share_analog) uint8_t netplay_settings_share_mode(
unsigned share_digital, unsigned share_analog)
{ {
if (share_digital || share_analog) if (share_digital || share_analog)
{ {
@ -1570,9 +1569,11 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
netplay_toggle_play_spectate(netplay); netplay_toggle_play_spectate(netplay);
break; break;
case RARCH_NETPLAY_CTL_PAUSE: case RARCH_NETPLAY_CTL_PAUSE:
if (!netplay->local_paused)
netplay_frontend_paused(netplay, true); netplay_frontend_paused(netplay, true);
break; break;
case RARCH_NETPLAY_CTL_UNPAUSE: case RARCH_NETPLAY_CTL_UNPAUSE:
if (netplay->local_paused)
netplay_frontend_paused(netplay, false); netplay_frontend_paused(netplay, false);
break; break;
case RARCH_NETPLAY_CTL_LOAD_SAVESTATE: case RARCH_NETPLAY_CTL_LOAD_SAVESTATE: