Use CORE_CTL_RETRO_SERIALIZE_SIZE everywhere

This commit is contained in:
twinaphex 2016-01-27 07:09:30 +01:00
parent a4bfd9046c
commit 57d19b21b5
5 changed files with 37 additions and 12 deletions

View File

@ -840,6 +840,7 @@ static void event_load_state(const char *path, char *s, size_t len)
static void event_main_state(unsigned cmd) static void event_main_state(unsigned cmd)
{ {
retro_ctx_size_info_t info;
char path[PATH_MAX_LENGTH] = {0}; char path[PATH_MAX_LENGTH] = {0};
char msg[128] = {0}; char msg[128] = {0};
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
@ -854,7 +855,9 @@ static void event_main_state(unsigned cmd)
else else
strlcpy(path, global->name.savestate, sizeof(path)); strlcpy(path, global->name.savestate, sizeof(path));
if (core.retro_serialize_size()) core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
if (info.size)
{ {
switch (cmd) switch (cmd)
{ {

14
movie.c
View File

@ -22,6 +22,7 @@
#include <retro_endianness.h> #include <retro_endianness.h>
#include "movie.h" #include "movie.h"
#include "libretro_version_1.h"
#include "content.h" #include "content.h"
#include "general.h" #include "general.h"
#include "msg_hash.h" #include "msg_hash.h"
@ -103,6 +104,8 @@ static bool init_playback(bsv_movie_t *handle, const char *path)
if (state_size) if (state_size)
{ {
retro_ctx_size_info_t info;
handle->state = (uint8_t*)malloc(state_size); handle->state = (uint8_t*)malloc(state_size);
handle->state_size = state_size; handle->state_size = state_size;
if (!handle->state) if (!handle->state)
@ -114,7 +117,9 @@ static bool init_playback(bsv_movie_t *handle, const char *path)
return false; return false;
} }
if (core.retro_serialize_size() == state_size) core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
if (info.size == state_size)
core.retro_unserialize(handle->state, state_size); core.retro_unserialize(handle->state, state_size);
else else
RARCH_WARN("Movie format seems to have a different serializer version. Will most likely fail.\n"); RARCH_WARN("Movie format seems to have a different serializer version. Will most likely fail.\n");
@ -127,6 +132,7 @@ static bool init_playback(bsv_movie_t *handle, const char *path)
static bool init_record(bsv_movie_t *handle, const char *path) static bool init_record(bsv_movie_t *handle, const char *path)
{ {
retro_ctx_size_info_t info;
uint32_t state_size; uint32_t state_size;
uint32_t header[4] = {0}; uint32_t header[4] = {0};
uint32_t *content_crc_ptr = NULL; uint32_t *content_crc_ptr = NULL;
@ -144,7 +150,11 @@ static bool init_record(bsv_movie_t *handle, const char *path)
* BSV1 in a HEX editor, big-endian. */ * BSV1 in a HEX editor, big-endian. */
header[MAGIC_INDEX] = swap_if_little32(BSV_MAGIC); header[MAGIC_INDEX] = swap_if_little32(BSV_MAGIC);
header[CRC_INDEX] = swap_if_big32(*content_crc_ptr); header[CRC_INDEX] = swap_if_big32(*content_crc_ptr);
state_size = core.retro_serialize_size();
core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
state_size = info.size;
header[STATE_SIZE_INDEX] = swap_if_big32(state_size); header[STATE_SIZE_INDEX] = swap_if_big32(state_size);
fwrite(header, 4, sizeof(uint32_t), handle->file); fwrite(header, 4, sizeof(uint32_t), handle->file);

View File

@ -62,14 +62,17 @@ bool np_send_nickname(netplay_t *netplay, int fd)
uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic) uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic)
{ {
retro_ctx_size_info_t info;
uint32_t *content_crc_ptr; uint32_t *content_crc_ptr;
uint32_t *header, bsv_header[4] = {0}; uint32_t *header, bsv_header[4] = {0};
size_t serialize_size = core.retro_serialize_size(); size_t serialize_size, header_size;
size_t header_size = sizeof(bsv_header) + serialize_size;
*size = header_size; core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
header = (uint32_t*)malloc(header_size); serialize_size = info.size;
header_size = sizeof(bsv_header) + serialize_size;
*size = header_size;
header = (uint32_t*)malloc(header_size);
if (!header) if (!header)
return NULL; return NULL;
@ -92,6 +95,7 @@ uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic)
bool np_bsv_parse_header(const uint32_t *header, uint32_t magic) bool np_bsv_parse_header(const uint32_t *header, uint32_t magic)
{ {
retro_ctx_size_info_t info;
uint32_t *content_crc_ptr; uint32_t *content_crc_ptr;
uint32_t in_crc, in_magic, in_state_size; uint32_t in_crc, in_magic, in_state_size;
uint32_t in_bsv = swap_if_little32(header[MAGIC_INDEX]); uint32_t in_bsv = swap_if_little32(header[MAGIC_INDEX]);
@ -121,11 +125,13 @@ bool np_bsv_parse_header(const uint32_t *header, uint32_t magic)
return false; return false;
} }
core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
in_state_size = swap_if_big32(header[STATE_SIZE_INDEX]); in_state_size = swap_if_big32(header[STATE_SIZE_INDEX]);
if (in_state_size != core.retro_serialize_size()) if (in_state_size != info.size)
{ {
RARCH_ERR("Serialization size mismatch, got 0x%x, expected 0x%x.\n", RARCH_ERR("Serialization size mismatch, got 0x%x, expected 0x%x.\n",
(unsigned)in_state_size, (unsigned)core.retro_serialize_size()); (unsigned)in_state_size, (unsigned)info.size);
return false; return false;
} }

View File

@ -94,6 +94,7 @@ static void netplay_net_post_frame(netplay_t *netplay)
static bool netplay_net_init_buffers(netplay_t *netplay) static bool netplay_net_init_buffers(netplay_t *netplay)
{ {
unsigned i; unsigned i;
retro_ctx_size_info_t info;
if (!netplay) if (!netplay)
return false; return false;
@ -104,7 +105,9 @@ static bool netplay_net_init_buffers(netplay_t *netplay)
if (!netplay->buffer) if (!netplay->buffer)
return false; return false;
netplay->state_size = core.retro_serialize_size(); core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
netplay->state_size = info.size;
for (i = 0; i < netplay->buffer_size; i++) for (i = 0; i < netplay->buffer_size; i++)
{ {

View File

@ -618,6 +618,7 @@ static void state_manager_capacity(state_manager_t *state,
void init_rewind(void) void init_rewind(void)
{ {
retro_ctx_size_info_t info;
void *state = NULL; void *state = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -630,7 +631,9 @@ void init_rewind(void)
return; return;
} }
rewind_state.size = core.retro_serialize_size(); core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
rewind_state.size = info.size;
if (!rewind_state.size) if (!rewind_state.size)
{ {