mirror of
https://github.com/libretro/RetroArch
synced 2025-04-25 09:02:44 +00:00
(Replay/BSV) Fix issue #15083, and some other style nits
This commit is contained in:
parent
2b7c722c11
commit
60dc768f78
@ -4693,8 +4693,9 @@ static int16_t input_state_device(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_BSV_MOVIE
|
#ifdef HAVE_BSV_MOVIE
|
||||||
void bsv_movie_handle_clear_key_events(bsv_movie_t*);
|
/* Forward declaration */
|
||||||
void bsv_movie_free(bsv_movie_t*);
|
void bsv_movie_free(bsv_movie_t*);
|
||||||
|
|
||||||
void bsv_movie_deinit(input_driver_state_t *input_st)
|
void bsv_movie_deinit(input_driver_state_t *input_st)
|
||||||
{
|
{
|
||||||
if (input_st->bsv_movie_state_handle)
|
if (input_st->bsv_movie_state_handle)
|
||||||
@ -4757,12 +4758,15 @@ void bsv_movie_frame_rewind(void)
|
|||||||
intfstream_seek(handle->file, (int)handle->min_file_pos, SEEK_SET);
|
intfstream_seek(handle->file, (int)handle->min_file_pos, SEEK_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void bsv_movie_handle_clear_key_events(bsv_movie_t *movie)
|
|
||||||
|
/* Zero out key events when playing back or recording */
|
||||||
|
static void bsv_movie_handle_clear_key_events(bsv_movie_t *movie)
|
||||||
{
|
{
|
||||||
/* zero out key events when playing back or recording */
|
movie->key_event_count = 0;
|
||||||
movie->key_event_count=0;
|
|
||||||
}
|
}
|
||||||
void bsv_movie_handle_push_key_event(bsv_movie_t *movie, uint8_t down, uint16_t mod, uint32_t code, uint32_t character)
|
|
||||||
|
void bsv_movie_handle_push_key_event(bsv_movie_t *movie,
|
||||||
|
uint8_t down, uint16_t mod, uint32_t code, uint32_t character)
|
||||||
{
|
{
|
||||||
bsv_key_data_t data;
|
bsv_key_data_t data;
|
||||||
data.down = down;
|
data.down = down;
|
||||||
@ -4782,26 +4786,26 @@ void bsv_movie_finish_rewind(input_driver_state_t *input_st)
|
|||||||
handle->first_rewind = !handle->did_rewind;
|
handle->first_rewind = !handle->did_rewind;
|
||||||
handle->did_rewind = false;
|
handle->did_rewind = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bsv_movie_next_frame(input_driver_state_t *input_st)
|
void bsv_movie_next_frame(input_driver_state_t *input_st)
|
||||||
{
|
{
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
unsigned checkpoint_interval = settings->uints.replay_checkpoint_interval;
|
unsigned checkpoint_interval = settings->uints.replay_checkpoint_interval;
|
||||||
bsv_movie_t *handle = input_st->bsv_movie_state_handle;
|
bsv_movie_t *handle = input_st->bsv_movie_state_handle;
|
||||||
if (!handle)
|
|
||||||
return;
|
if (!handle || state_manager_frame_is_reversed())
|
||||||
if (state_manager_frame_is_reversed())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_RECORDING)
|
if (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_RECORDING)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
/* write key events, frame is over */
|
/* write key events, frame is over */
|
||||||
intfstream_write(handle->file, &(handle->key_event_count), 1);
|
intfstream_write(handle->file, &(handle->key_event_count), 1);
|
||||||
for(i = 0; i < handle->key_event_count; i++)
|
for (i = 0; i < handle->key_event_count; i++)
|
||||||
{
|
|
||||||
intfstream_write(handle->file, &(handle->key_events[i]), sizeof(bsv_key_data_t));
|
intfstream_write(handle->file, &(handle->key_events[i]), sizeof(bsv_key_data_t));
|
||||||
}
|
|
||||||
bsv_movie_handle_clear_key_events(handle);
|
bsv_movie_handle_clear_key_events(handle);
|
||||||
/* maybe record checkpoint */
|
|
||||||
|
/* Maybe record checkpoint */
|
||||||
if (checkpoint_interval != 0 && handle->frame_ptr > 0 && (handle->frame_ptr % (checkpoint_interval*60) == 0))
|
if (checkpoint_interval != 0 && handle->frame_ptr > 0 && (handle->frame_ptr % (checkpoint_interval*60) == 0))
|
||||||
{
|
{
|
||||||
retro_ctx_size_info_t info;
|
retro_ctx_size_info_t info;
|
||||||
@ -4810,14 +4814,14 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
|
|||||||
uint64_t size;
|
uint64_t size;
|
||||||
uint8_t frame_tok = REPLAY_TOKEN_CHECKPOINT_FRAME;
|
uint8_t frame_tok = REPLAY_TOKEN_CHECKPOINT_FRAME;
|
||||||
core_serialize_size(&info);
|
core_serialize_size(&info);
|
||||||
size = info.size;
|
size = swap_if_big64(info.size);
|
||||||
st = (uint8_t*)malloc(info.size);
|
st = (uint8_t*)malloc(info.size);
|
||||||
serial_info.data = st;
|
serial_info.data = st;
|
||||||
serial_info.size = info.size;
|
serial_info.size = info.size;
|
||||||
core_serialize(&serial_info);
|
core_serialize(&serial_info);
|
||||||
/* "next frame is a checkpoint" */
|
/* "next frame is a checkpoint" */
|
||||||
intfstream_write(handle->file, (uint8_t *)(&frame_tok), sizeof(uint8_t));
|
intfstream_write(handle->file, (uint8_t *)(&frame_tok), sizeof(uint8_t));
|
||||||
intfstream_write(handle->file, &(swap_if_big64(size)), sizeof(uint64_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);
|
free(st);
|
||||||
}
|
}
|
||||||
@ -4828,6 +4832,7 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
|
|||||||
intfstream_write(handle->file, (uint8_t *)(&frame_tok), sizeof(uint8_t));
|
intfstream_write(handle->file, (uint8_t *)(&frame_tok), sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_PLAYBACK)
|
if (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_PLAYBACK)
|
||||||
{
|
{
|
||||||
/* read next key events, a frame happened for sure? but don't apply them yet */
|
/* read next key events, a frame happened for sure? but don't apply them yet */
|
||||||
@ -4838,7 +4843,7 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
|
|||||||
if (intfstream_read(handle->file, &(handle->key_event_count), 1) == 1)
|
if (intfstream_read(handle->file, &(handle->key_event_count), 1) == 1)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < handle->key_event_count; i++)
|
for (i = 0; i < handle->key_event_count; i++)
|
||||||
{
|
{
|
||||||
if (intfstream_read(handle->file, &(handle->key_events[i]), sizeof(bsv_key_data_t)) != sizeof(bsv_key_data_t))
|
if (intfstream_read(handle->file, &(handle->key_events[i]), sizeof(bsv_key_data_t)) != sizeof(bsv_key_data_t))
|
||||||
{
|
{
|
||||||
@ -4856,6 +4861,7 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
|
|||||||
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
uint8_t next_frame_type=REPLAY_TOKEN_INVALID;
|
uint8_t next_frame_type=REPLAY_TOKEN_INVALID;
|
||||||
if (intfstream_read(handle->file, (uint8_t *)(&next_frame_type), sizeof(uint8_t)) != sizeof(uint8_t))
|
if (intfstream_read(handle->file, (uint8_t *)(&next_frame_type), sizeof(uint8_t)) != sizeof(uint8_t))
|
||||||
@ -4865,34 +4871,33 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
|
|||||||
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(next_frame_type == REPLAY_TOKEN_REGULAR_FRAME)
|
else if (next_frame_type == REPLAY_TOKEN_REGULAR_FRAME)
|
||||||
{
|
{
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
}
|
}
|
||||||
else if(next_frame_type == REPLAY_TOKEN_CHECKPOINT_FRAME)
|
else if (next_frame_type == REPLAY_TOKEN_CHECKPOINT_FRAME)
|
||||||
{
|
{
|
||||||
uint64_t size;
|
uint64_t size;
|
||||||
|
uint8_t *st;
|
||||||
|
retro_ctx_serialize_info_t serial_info;
|
||||||
|
|
||||||
if (intfstream_read(handle->file, &(size), sizeof(uint64_t)) != sizeof(uint64_t))
|
if (intfstream_read(handle->file, &(size), sizeof(uint64_t)) != sizeof(uint64_t))
|
||||||
{
|
{
|
||||||
RARCH_ERR("[Replay] Replay ran out of frames\n");
|
RARCH_ERR("[Replay] Replay ran out of frames\n");
|
||||||
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
retro_ctx_serialize_info_t serial_info;
|
|
||||||
uint8_t *st;
|
|
||||||
size = swap_if_big64(size);
|
size = swap_if_big64(size);
|
||||||
st = (uint8_t*)malloc(size);
|
st = (uint8_t*)malloc(size);
|
||||||
if(intfstream_read(handle->file, st, size) != size)
|
if (intfstream_read(handle->file, st, size) != size)
|
||||||
{
|
{
|
||||||
RARCH_ERR("[Replay] Replay checkpoint truncated\n");
|
RARCH_ERR("[Replay] Replay checkpoint truncated\n");
|
||||||
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
input_st->bsv_movie_state.flags |= BSV_FLAG_MOVIE_END;
|
||||||
free(st);
|
free(st);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
serial_info.data_const = st;
|
serial_info.data_const = st;
|
||||||
serial_info.size = size;
|
serial_info.size = size;
|
||||||
core_unserialize(&serial_info);
|
core_unserialize(&serial_info);
|
||||||
@ -4900,16 +4905,14 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
handle->frame_pos[handle->frame_ptr] = intfstream_tell(handle->file);
|
handle->frame_pos[handle->frame_ptr] = intfstream_tell(handle->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t replay_get_serialize_size(void)
|
size_t replay_get_serialize_size(void)
|
||||||
{
|
{
|
||||||
input_driver_state_t *input_st = input_state_get_ptr();
|
input_driver_state_t *input_st = input_state_get_ptr();
|
||||||
if (input_st->bsv_movie_state.flags & (BSV_FLAG_MOVIE_RECORDING | BSV_FLAG_MOVIE_PLAYBACK))
|
if (input_st->bsv_movie_state.flags & (BSV_FLAG_MOVIE_RECORDING | BSV_FLAG_MOVIE_PLAYBACK))
|
||||||
return sizeof(int32_t)+intfstream_tell(input_st->bsv_movie_state_handle->file);
|
return sizeof(int32_t)+intfstream_tell(input_st->bsv_movie_state_handle->file);
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4936,39 +4939,43 @@ bool replay_get_serialized_data(void* buffer)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool replay_set_serialized_data(void* buf)
|
bool replay_set_serialized_data(void* buf)
|
||||||
{
|
{
|
||||||
uint8_t *buffer = buf;
|
uint8_t *buffer = buf;
|
||||||
input_driver_state_t *input_st = input_state_get_ptr();
|
input_driver_state_t *input_st = input_state_get_ptr();
|
||||||
bool playback = input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_PLAYBACK;
|
bool playback = input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_PLAYBACK;
|
||||||
bool recording = input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_RECORDING;
|
bool recording = input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_RECORDING;
|
||||||
|
|
||||||
/* If there is no current replay, ignore this entirely.
|
/* If there is no current replay, ignore this entirely.
|
||||||
TODO: Later, consider loading up the replay and allow the user to continue it? or would that be better done from the replay hotkeys? */
|
TODO/FIXME: Later, consider loading up the replay
|
||||||
|
and allow the user to continue it?
|
||||||
|
Or would that be better done from the replay hotkeys?
|
||||||
|
*/
|
||||||
if(!(playback || recording))
|
if(!(playback || recording))
|
||||||
return true;
|
return true;
|
||||||
if (buffer == NULL)
|
|
||||||
|
if (!buffer)
|
||||||
{
|
{
|
||||||
if (recording)
|
if (recording)
|
||||||
{
|
{
|
||||||
const char *load_fail_str =
|
const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_FAILED_INCOMPAT);
|
||||||
msg_hash_to_str(MSG_REPLAY_LOAD_STATE_FAILED_INCOMPAT);
|
runloop_msg_queue_push(str,
|
||||||
runloop_msg_queue_push(load_fail_str,
|
|
||||||
1, 180, true,
|
1, 180, true,
|
||||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
|
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
|
||||||
RARCH_ERR("[Replay] %s.\n", load_fail_str);
|
RARCH_ERR("[Replay] %s.\n", str);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playback)
|
if (playback)
|
||||||
{
|
{
|
||||||
const char *load_warn_str =
|
const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_HALT_INCOMPAT);
|
||||||
msg_hash_to_str(MSG_REPLAY_LOAD_STATE_HALT_INCOMPAT);
|
runloop_msg_queue_push(str,
|
||||||
runloop_msg_queue_push(load_warn_str,
|
|
||||||
1, 180, true,
|
1, 180, true,
|
||||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
|
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
|
||||||
RARCH_WARN("[Replay] %s.\n", load_warn_str);
|
RARCH_WARN("[Replay] %s.\n", str);
|
||||||
movie_stop(input_st);
|
movie_stop(input_st);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -4979,17 +4986,22 @@ bool replay_set_serialized_data(void* buf)
|
|||||||
int64_t identifier = swap_if_big64(*identifier_spot);
|
int64_t identifier = swap_if_big64(*identifier_spot);
|
||||||
int32_t handle_idx = intfstream_tell(input_st->bsv_movie_state_handle->file);
|
int32_t handle_idx = intfstream_tell(input_st->bsv_movie_state_handle->file);
|
||||||
bool is_compatible = identifier == input_st->bsv_movie_state_handle->identifier;
|
bool is_compatible = identifier == input_st->bsv_movie_state_handle->identifier;
|
||||||
|
|
||||||
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 the replay; otherwise
|
||||||
halt playback and go to that state normally. */
|
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! */
|
|
||||||
/* TODO: figure out what to do about rewinding across load */
|
This can truncate the current recording, so beware!
|
||||||
|
|
||||||
|
TODO/FIXME: Figure out what to do about rewinding across load
|
||||||
|
*/
|
||||||
if (loaded_len > handle_idx)
|
if (loaded_len > handle_idx)
|
||||||
{
|
{
|
||||||
/* TODO: Really, to be very careful, we should be
|
/* TODO: Really, to be very careful, we should be
|
||||||
@ -5005,29 +5017,27 @@ bool replay_set_serialized_data(void* buf)
|
|||||||
{
|
{
|
||||||
if (recording)
|
if (recording)
|
||||||
{
|
{
|
||||||
const char *load_fail_str =
|
const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_FAILED_INCOMPAT);
|
||||||
msg_hash_to_str(MSG_REPLAY_LOAD_STATE_FAILED_INCOMPAT);
|
runloop_msg_queue_push(str,
|
||||||
runloop_msg_queue_push(load_fail_str,
|
|
||||||
1, 180, true,
|
1, 180, true,
|
||||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
|
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
|
||||||
RARCH_ERR("[Replay] %s.\n", load_fail_str);
|
RARCH_ERR("[Replay] %s.\n", str);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playback)
|
if (playback)
|
||||||
{
|
{
|
||||||
const char *load_warn_str =
|
const char *str = msg_hash_to_str(MSG_REPLAY_LOAD_STATE_HALT_INCOMPAT);
|
||||||
msg_hash_to_str(MSG_REPLAY_LOAD_STATE_HALT_INCOMPAT);
|
runloop_msg_queue_push(str,
|
||||||
runloop_msg_queue_push(load_warn_str,
|
|
||||||
1, 180, true,
|
1, 180, true,
|
||||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
|
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
|
||||||
RARCH_WARN("[Replay] %s.\n", load_warn_str);
|
RARCH_WARN("[Replay] %s.\n", str);
|
||||||
movie_stop(input_st);
|
movie_stop(input_st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void input_driver_poll(void)
|
void input_driver_poll(void)
|
||||||
@ -5493,7 +5503,7 @@ void input_driver_poll(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
bsv_key_data_t k;
|
bsv_key_data_t k;
|
||||||
for(i = 0; i < input_st->bsv_movie_state_handle->key_event_count; i++)
|
for (i = 0; i < input_st->bsv_movie_state_handle->key_event_count; i++)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
rcheevos_pause_hardcore();
|
rcheevos_pause_hardcore();
|
||||||
@ -6108,7 +6118,7 @@ void input_driver_collect_system_input(input_driver_state_t *input_st,
|
|||||||
int i;
|
int i;
|
||||||
/* Update compound 'current_bits' record
|
/* Update compound 'current_bits' record
|
||||||
* Note: Only digital inputs are considered */
|
* Note: Only digital inputs are considered */
|
||||||
for(i = 0; i < sizeof(current_bits->data) / sizeof(current_bits->data[0]); i++)
|
for (i = 0; i < sizeof(current_bits->data) / sizeof(current_bits->data[0]); i++)
|
||||||
current_bits->data[i] |= loop_bits->data[i];
|
current_bits->data[i] |= loop_bits->data[i];
|
||||||
}
|
}
|
||||||
else if (!all_users_control_menu)
|
else if (!all_users_control_menu)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user