From d53373a5cb8b3e0f6ba909a3972d9b4088865908 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Sat, 17 Sep 2016 11:24:23 -0400 Subject: [PATCH] Netplay savestate loading frontend changes Support for the frontend to inform Netplay when a savestate has been loaded, so Netplay can in turn inform the peer. --- command.c | 8 ++++++++ network/netplay/netplay.c | 23 ++++++++++++++++++----- network/netplay/netplay.h | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/command.c b/command.c index ca4402a8a5ac..c5332f9b7cba 100644 --- a/command.c +++ b/command.c @@ -1713,6 +1713,10 @@ static void command_event_load_state(const char *path, char *s, size_t len) return; } +#ifdef HAVE_NETPLAY + netplay_driver_ctl(RARCH_NETPLAY_CTL_LOAD_SAVESTATE, NULL); +#endif + if (settings->state_slot < 0) snprintf(s, len, "%s #-1 (auto).", msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT)); @@ -1740,6 +1744,10 @@ static void command_event_undo_load_state(char *s, size_t len) return; } +#ifdef HAVE_NETPLAY + netplay_driver_ctl(RARCH_NETPLAY_CTL_LOAD_SAVESTATE, NULL); +#endif + strlcpy(s, msg_hash_to_str(MSG_UNDID_LOAD_STATE), len); } diff --git a/network/netplay/netplay.c b/network/netplay/netplay.c index 8ae9e7a11d32..8f2c2bd6160b 100644 --- a/network/netplay/netplay.c +++ b/network/netplay/netplay.c @@ -1170,7 +1170,7 @@ void netplay_frontend_paused(netplay_t *netplay, bool paused) /** * netplay_load_savestate * @netplay : pointer to netplay object - * @serial_info : the savestate being loaded + * @serial_info : the savestate being loaded, NULL means "load it yourself" * @save : whether to save the provided serial_info into the frame buffer * * Inform Netplay of a savestate load and send it to the other side @@ -1178,17 +1178,30 @@ void netplay_frontend_paused(netplay_t *netplay, bool paused) void netplay_load_savestate(netplay_t *netplay, retro_ctx_serialize_info_t *serial_info, bool save) { uint32_t header[3]; + retro_ctx_serialize_info_t tmp_serial_info; if (!netplay->has_connection) return; /* Record it in our own buffer */ - if (save && netplay_delta_frame_ready(netplay, &netplay->buffer[netplay->self_ptr], netplay->self_frame_count)) + if ((save || !serial_info) && netplay_delta_frame_ready(netplay, &netplay->buffer[netplay->self_ptr], netplay->self_frame_count)) { - if (serial_info->size <= netplay->state_size) + if (!serial_info) { - memcpy(netplay->buffer[netplay->self_ptr].state, - serial_info->data_const, serial_info->size); + tmp_serial_info.size = netplay->state_size; + tmp_serial_info.data = netplay->buffer[netplay->self_ptr].state; + if (!core_serialize(&tmp_serial_info)) + return; + tmp_serial_info.data_const = tmp_serial_info.data; + serial_info = &tmp_serial_info; + } + else + { + if (serial_info->size <= netplay->state_size) + { + memcpy(netplay->buffer[netplay->self_ptr].state, + serial_info->data_const, serial_info->size); + } } } diff --git a/network/netplay/netplay.h b/network/netplay/netplay.h index ecac020d5580..a2bb44efba3e 100644 --- a/network/netplay/netplay.h +++ b/network/netplay/netplay.h @@ -187,7 +187,7 @@ void netplay_frontend_paused(netplay_t *netplay, bool paused); /** * netplay_load_savestate * @netplay : pointer to netplay object - * @serial_info : the savestate being loaded + * @serial_info : the savestate being loaded, NULL means "load it yourself" * @save : whether to save the provided serial_info into the frame buffer * * Inform Netplay of a savestate load and send it to the other side