Skip to content

Commit

Permalink
Merge pull request libretro#3607 from GregorR/netplay-savestates
Browse files Browse the repository at this point in the history
Netplay savestate loading frontend changes
  • Loading branch information
inactive123 authored Sep 17, 2016
2 parents da6ad6b + d53373a commit e21662b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
8 changes: 8 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down
23 changes: 18 additions & 5 deletions network/netplay/netplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,25 +1170,38 @@ 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
**/
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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion network/netplay/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e21662b

Please sign in to comment.