Simplify core_serialize_size and core_serialize_size_special

This commit is contained in:
libretroadmin 2023-06-16 17:20:27 +02:00
parent c4b99031f0
commit fc06e2f84f
9 changed files with 50 additions and 71 deletions

View File

@ -688,7 +688,6 @@ bool command_show_osd_msg(command_t *cmd, const char* arg)
bool command_load_state_slot(command_t *cmd, const char *arg)
{
char state_path[16384];
retro_ctx_size_info_t info;
char reply[128] = "";
unsigned int slot = (unsigned int)strtoul(arg, NULL, 10);
bool savestates_enabled = core_info_current_supports_savestate();
@ -697,10 +696,11 @@ bool command_load_state_slot(command_t *cmd, const char *arg)
snprintf(reply, sizeof(reply) - 1, "LOAD_STATE_SLOT %d", slot);
if (savestates_enabled)
{
size_t info_size;
runloop_get_savestate_path(state_path, sizeof(state_path), slot);
core_serialize_size(&info);
savestates_enabled = (info.size > 0);
info_size = core_serialize_size();
savestates_enabled = (info_size > 0);
}
if (savestates_enabled)
{
@ -718,7 +718,6 @@ bool command_play_replay_slot(command_t *cmd, const char *arg)
{
#ifdef HAVE_BSV_MOVIE
char replay_path[16384];
retro_ctx_size_info_t info;
char reply[128] = "";
unsigned int slot = (unsigned int)strtoul(arg, NULL, 10);
bool savestates_enabled = core_info_current_supports_savestate();
@ -726,15 +725,17 @@ bool command_play_replay_slot(command_t *cmd, const char *arg)
replay_path[0] = '\0';
if (savestates_enabled)
{
size_t info_size;
runloop_get_replay_path(replay_path, sizeof(replay_path), slot);
core_serialize_size(&info);
savestates_enabled = (info.size > 0);
info_size = core_serialize_size();
savestates_enabled = (info_size > 0);
}
if (savestates_enabled)
{
ret = movie_start_playback(input_state_get_ptr(), replay_path);
if (ret) {
if (ret)
{
input_driver_state_t *input_st = input_state_get_ptr();
task_queue_wait(NULL,NULL);
if(input_st->bsv_movie_state_handle)
@ -1924,7 +1925,6 @@ void command_event_remove_current_config(enum override_type type)
bool command_event_main_state(unsigned cmd)
{
retro_ctx_size_info_t info;
char msg[128];
char state_path[16384];
settings_t *settings = config_get_ptr();
@ -1936,11 +1936,12 @@ bool command_event_main_state(unsigned cmd)
if (savestates_enabled)
{
size_t info_size;
runloop_get_current_savestate_path(state_path,
sizeof(state_path));
core_serialize_size(&info);
savestates_enabled = (info.size > 0);
info_size = core_serialize_size();
savestates_enabled = (info_size > 0);
}
/* TODO: Load state should act in one of three ways:

4
core.h
View File

@ -40,8 +40,8 @@ void core_run(void);
void core_reset(void);
bool core_serialize_size(retro_ctx_size_info_t *info);
bool core_serialize_size_special(retro_ctx_size_info_t *info);
size_t core_serialize_size(void);
size_t core_serialize_size_special(void);
uint64_t core_serialization_quirks(void);

View File

@ -5052,21 +5052,18 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
/* Maybe record checkpoint */
if (checkpoint_interval != 0 && handle->frame_ptr > 0 && (handle->frame_ptr % (checkpoint_interval*60) == 0))
{
retro_ctx_size_info_t info;
retro_ctx_serialize_info_t serial_info;
uint8_t *st;
uint64_t size;
uint8_t frame_tok = REPLAY_TOKEN_CHECKPOINT_FRAME;
core_serialize_size(&info);
size = swap_if_big64(info.size);
st = (uint8_t*)malloc(info.size);
size_t info_size = core_serialize_size();
uint64_t size = swap_if_big64(info_size);
uint8_t *st = (uint8_t*)malloc(info_size);
serial_info.data = st;
serial_info.size = info.size;
serial_info.size = info_size;
core_serialize(&serial_info);
/* "next frame is a checkpoint" */
intfstream_write(handle->file, (uint8_t *)(&frame_tok), sizeof(uint8_t));
intfstream_write(handle->file, &size, sizeof(uint64_t));
intfstream_write(handle->file, st, info.size);
intfstream_write(handle->file, st, info_size);
free(st);
}
else

View File

@ -6739,16 +6739,15 @@ static bool netplay_init_socket_buffers(netplay_t *netplay)
static bool netplay_init_serialization(netplay_t *netplay)
{
size_t i;
retro_ctx_size_info_t info = {0};
size_t i, info_size;
if (netplay->state_size)
return true;
core_serialize_size_special(&info);
if (!info.size)
info_size = core_serialize_size_special();
if (!info_size)
return false;
netplay->state_size = info.size;
netplay->state_size = info_size;
for (i = 0; i < netplay->buffer_size; i++)
{

View File

@ -225,11 +225,6 @@ typedef struct retro_ctx_serialize_info
size_t size;
} retro_ctx_serialize_info_t;
typedef struct retro_ctx_size_info
{
size_t size;
} retro_ctx_size_info_t;
typedef struct retro_callbacks
{
retro_video_refresh_t frame_cb;

View File

@ -1025,12 +1025,10 @@ static void runahead_error(runloop_state_t *runloop_st)
static bool runahead_create(runloop_state_t *runloop_st)
{
/* get savestate size and allocate buffer */
retro_ctx_size_info_t info;
video_driver_state_t *video_st = video_state_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr();
size_t info_size = core_serialize_size_special();
core_serialize_size_special(&info);
runahead_save_state_list_init(runloop_st, info.size);
runahead_save_state_list_init(runloop_st, info_size);
if (video_st->flags & VIDEO_FLAG_ACTIVE)
video_st->flags |= VIDEO_FLAG_RUNAHEAD_IS_ACTIVE;
else
@ -1364,18 +1362,18 @@ static int16_t preempt_input_state(unsigned port,
static const char* preempt_allocate(runloop_state_t *runloop_st,
const uint8_t frames)
{
preempt_t *preempt = (preempt_t*)calloc(1, sizeof(preempt_t));
retro_ctx_size_info_t info;
uint8_t i;
size_t info_size;
preempt_t *preempt = (preempt_t*)calloc(1, sizeof(preempt_t));
if (!(runloop_st->preempt_data = preempt))
return msg_hash_to_str(MSG_PREEMPT_FAILED_TO_ALLOCATE);
core_serialize_size_special(&info);
if (!info.size)
info_size = core_serialize_size_special();
if (!info_size)
return msg_hash_to_str(MSG_PREEMPT_CORE_DOES_NOT_SUPPORT_SAVESTATES);
preempt->state_size = info.size;
preempt->state_size = info_size;
preempt->frames = frames;
for (i = 0; i < frames; i++)

View File

@ -7693,27 +7693,21 @@ bool core_serialize_special(retro_ctx_serialize_info_t *info)
return ret;
}
bool core_serialize_size(retro_ctx_size_info_t *info)
size_t core_serialize_size(void)
{
runloop_state_t *runloop_st = &runloop_state;
if (!info)
return false;
info->size = runloop_st->current_core.retro_serialize_size();
return true;
return runloop_st->current_core.retro_serialize_size();
}
bool core_serialize_size_special(retro_ctx_size_info_t *info)
size_t core_serialize_size_special(void)
{
size_t val;
runloop_state_t *runloop_st = &runloop_state;
if (!info)
return false;
runloop_st->flags |= RUNLOOP_FLAG_REQUEST_SPECIAL_SAVESTATE;
info->size = runloop_st->current_core.retro_serialize_size();
val = runloop_st->current_core.retro_serialize_size();
runloop_st->flags &= ~RUNLOOP_FLAG_REQUEST_SPECIAL_SAVESTATE;
return true;
return val;
}
uint64_t core_serialization_quirks(void)

View File

@ -108,7 +108,7 @@ static bool bsv_movie_init_playback(
if (state_size)
{
retro_ctx_size_info_t info;
size_t info_size;
retro_ctx_serialize_info_t serial_info;
uint8_t *buf = (uint8_t*)malloc(state_size);
@ -123,13 +123,13 @@ static bool bsv_movie_init_playback(
RARCH_ERR("%s\n", msg_hash_to_str(MSG_COULD_NOT_READ_STATE_FROM_MOVIE));
return false;
}
core_serialize_size( &info);
info_size = core_serialize_size();
/* For cores like dosbox, the reported size is not always
correct. So we just give a warning if they don't match up. */
serial_info.data_const = handle->state;
serial_info.size = state_size;
core_unserialize(&serial_info);
if (info.size != state_size)
if (info_size != state_size)
{
RARCH_WARN("%s\n",
msg_hash_to_str(MSG_MOVIE_FORMAT_DIFFERENT_SERIALIZER_VERSION));
@ -144,7 +144,7 @@ static bool bsv_movie_init_playback(
static bool bsv_movie_init_record(
bsv_movie_t *handle, const char *path)
{
retro_ctx_size_info_t info;
size_t info_size;
time_t t = time(NULL);
time_t time_lil = swap_if_big64(t);
uint32_t state_size = 0;
@ -168,9 +168,9 @@ static bool bsv_movie_init_record(
header[VERSION_INDEX] = REPLAY_FORMAT_VERSION;
header[CRC_INDEX] = swap_if_big32(content_crc);
core_serialize_size(&info);
info_size = core_serialize_size();
state_size = (unsigned)info.size;
state_size = (unsigned)info_size;
header[STATE_SIZE_INDEX] = swap_if_big32(state_size);
handle->identifier = (int64_t)t;

View File

@ -622,13 +622,12 @@ static void task_save_handler_finished(retro_task_t *task,
static size_t content_get_rastate_size(rastate_size_info_t* size, bool rewind)
{
retro_ctx_size_info_t info;
core_serialize_size(&info);
if (!info.size)
size_t info_size = core_serialize_size();
if (!info_size)
return 0;
size->coremem_size = info.size;
size->coremem_size = info_size;
/* 8-byte identifier, 8-byte block header, content, 8-byte terminator */
size->total_size = 8 + 8 + CONTENT_ALIGN_SIZE(info.size) + 8;
size->total_size = 8 + 8 + CONTENT_ALIGN_SIZE(info_size) + 8;
#ifdef HAVE_CHEEVOS
/* 8-byte block header + content */
if ((size->cheevos_size = rcheevos_get_serialize_size()) > 0)
@ -1601,7 +1600,6 @@ static void task_push_load_and_save_state(const char *path, void *data,
bool content_save_state(const char *path, bool save_to_disk, bool autosave)
{
size_t serial_size;
retro_ctx_size_info_t info;
void *data = NULL;
if (!core_info_current_supports_savestate())
@ -1611,11 +1609,10 @@ bool content_save_state(const char *path, bool save_to_disk, bool autosave)
return false;
}
core_serialize_size(&info);
serial_size = core_serialize_size();
if (info.size == 0)
if (serial_size == 0)
return false;
serial_size = info.size;
if (!save_state_in_background)
{
@ -2045,7 +2042,6 @@ bool content_load_state_from_ram(void)
**/
bool content_save_state_to_ram(void)
{
retro_ctx_size_info_t info;
void *data = NULL;
size_t serial_size;
@ -2056,11 +2052,10 @@ bool content_save_state_to_ram(void)
return false;
}
core_serialize_size(&info);
serial_size = core_serialize_size();
if (info.size == 0)
if (serial_size == 0)
return false;
serial_size = info.size;
if (!save_state_in_background)
{