change some replay file seeks to seek+truncates in record mode

This commit is contained in:
Joseph C. Osborn 2024-06-18 09:15:31 -07:00 committed by LibretroAdmin
parent 42f066a842
commit 6104a9ad86
1 changed files with 15 additions and 8 deletions

View File

@ -5640,6 +5640,7 @@ void bsv_movie_frame_rewind(void)
{ {
input_driver_state_t *input_st = &input_driver_st; input_driver_state_t *input_st = &input_driver_st;
bsv_movie_t *handle = input_st->bsv_movie_state_handle; bsv_movie_t *handle = input_st->bsv_movie_state_handle;
bool recording = (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_RECORDING) ? true : false;
if (!handle) if (!handle)
return; return;
@ -5652,6 +5653,8 @@ void bsv_movie_frame_rewind(void)
/* If we're at the beginning... */ /* If we're at the beginning... */
handle->frame_ptr = 0; handle->frame_ptr = 0;
intfstream_seek(handle->file, (int)handle->min_file_pos, SEEK_SET); intfstream_seek(handle->file, (int)handle->min_file_pos, SEEK_SET);
if (recording)
intfstream_truncate(handle->file, (int)handle->min_file_pos);
} }
else else
{ {
@ -5663,8 +5666,9 @@ void bsv_movie_frame_rewind(void)
* plus another. */ * plus another. */
handle->frame_ptr = (handle->frame_ptr - handle->frame_ptr = (handle->frame_ptr -
(handle->first_rewind ? 1 : 2)) & handle->frame_mask; (handle->first_rewind ? 1 : 2)) & handle->frame_mask;
intfstream_seek(handle->file, intfstream_seek(handle->file, (int)handle->frame_pos[handle->frame_ptr], SEEK_SET);
(int)handle->frame_pos[handle->frame_ptr], SEEK_SET); if (recording)
intfstream_truncate(handle->file, (int)handle->frame_pos[handle->frame_ptr]);
} }
if (intfstream_tell(handle->file) <= (long)handle->min_file_pos) if (intfstream_tell(handle->file) <= (long)handle->min_file_pos)
@ -5679,6 +5683,7 @@ void bsv_movie_frame_rewind(void)
* the starting point. Nice and easy. */ * the starting point. Nice and easy. */
intfstream_seek(handle->file, 4 * sizeof(uint32_t), SEEK_SET); intfstream_seek(handle->file, 4 * sizeof(uint32_t), SEEK_SET);
intfstream_truncate(handle->file, 4 * sizeof(uint32_t));
serial_info.data = handle->state; serial_info.data = handle->state;
serial_info.size = handle->state_size; serial_info.size = handle->state_size;
@ -5936,17 +5941,14 @@ bool replay_set_serialized_data(void* buf)
if (is_compatible) if (is_compatible)
{ {
/* If the state is part of this replay, go back to that state /* If the state is part of this replay, go back to that state
and rewind the replay; otherwise and rewind/fast forward the replay.
halt playback and go to that state normally.
If the savestate movie is after the current replay If the savestate movie is after the current replay
length we can replace the current replay data with it, length we can replace the current replay data with it,
but if it's earlier we can rewind the replay to the but if it's earlier we can rewind the replay to the
savestate movie time point. savestate movie time point.
This can truncate the current recording, so beware! This can truncate the current replay if we're in recording mode.
TODO/FIXME: Figure out what to do about rewinding across load
*/ */
if (loaded_len > handle_idx) if (loaded_len > handle_idx)
{ {
@ -5957,10 +5959,15 @@ bool replay_set_serialized_data(void* buf)
intfstream_write(input_st->bsv_movie_state_handle->file, buffer+sizeof(int32_t), loaded_len); intfstream_write(input_st->bsv_movie_state_handle->file, buffer+sizeof(int32_t), loaded_len);
} }
else else
{
intfstream_seek(input_st->bsv_movie_state_handle->file, loaded_len, SEEK_SET); intfstream_seek(input_st->bsv_movie_state_handle->file, loaded_len, SEEK_SET);
if (recording)
intfstream_truncate(input_st->bsv_movie_state_handle->file, loaded_len);
}
} }
else else
{ {
/* otherwise, if recording do not allow the load */
if (recording) if (recording)
{ {
const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_FAILED_INCOMPAT); const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_FAILED_INCOMPAT);
@ -5970,7 +5977,7 @@ bool replay_set_serialized_data(void* buf)
RARCH_ERR("[Replay] %s.\n", str); RARCH_ERR("[Replay] %s.\n", str);
return false; return false;
} }
/* if in playback, halt playback and go to that state normally */
if (playback) if (playback)
{ {
const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_HALT_INCOMPAT); const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_HALT_INCOMPAT);