Use flags for state_manager_rewind_state

This commit is contained in:
libretroadmin 2022-11-16 15:13:34 +01:00
parent 5e9e5177ec
commit 0b71407b62
3 changed files with 62 additions and 36 deletions

View File

@ -325,7 +325,7 @@ runloop_state_t *runloop_state_get_ptr(void)
#ifdef HAVE_REWIND #ifdef HAVE_REWIND
bool state_manager_frame_is_reversed(void) bool state_manager_frame_is_reversed(void)
{ {
return runloop_state.rewind_st.frame_is_reversed; return (runloop_state.rewind_st.flags & STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED) > 0;
} }
#endif #endif
@ -3134,7 +3134,8 @@ bool runloop_environment_cb(unsigned cmd, void *data)
float core_fps = (float)video_st->av_info.timing.fps; float core_fps = (float)video_st->av_info.timing.fps;
#ifdef HAVE_REWIND #ifdef HAVE_REWIND
if (runloop_st->rewind_st.frame_is_reversed) if (runloop_st->rewind_st.flags
& STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED)
{ {
throttle_state->mode = RETRO_THROTTLE_REWINDING; throttle_state->mode = RETRO_THROTTLE_REWINDING;
throttle_state->rate = 0.0f; throttle_state->rate = 0.0f;
@ -7543,7 +7544,8 @@ static enum runloop_state_enum runloop_check_state(
#ifdef HAVE_REWIND #ifdef HAVE_REWIND
struct state_manager_rewind_state struct state_manager_rewind_state
*rewind_st = &runloop_st->rewind_st; *rewind_st = &runloop_st->rewind_st;
if (rewind_st->frame_is_reversed) if (rewind_st->flags
& STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED)
runloop_msg_queue_push( runloop_msg_queue_push(
msg_hash_to_str(MSG_SLOW_MOTION_REWIND), 1, 1, false, NULL, msg_hash_to_str(MSG_SLOW_MOTION_REWIND), 1, 1, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);

View File

@ -584,16 +584,18 @@ void state_manager_event_init(
core_info_t *core_info = NULL; core_info_t *core_info = NULL;
void *state = NULL; void *state = NULL;
if (!rewind_st || if ( !rewind_st
rewind_st->init_attempted || || (rewind_st->flags & STATE_MGR_REWIND_ST_FLAG_INIT_ATTEMPTED)
rewind_st->state) || rewind_st->state)
return; return;
rewind_st->size = 0; rewind_st->size = 0;
rewind_st->frame_is_reversed = false; rewind_st->flags &= ~(
rewind_st->init_attempted = true; STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED
rewind_st->hotkey_was_checked = false; | STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_CHECKED
rewind_st->hotkey_was_pressed = false; | STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED
);
rewind_st->flags |= STATE_MGR_REWIND_ST_FLAG_INIT_ATTEMPTED;
/* We cannot initialise the rewind buffer /* We cannot initialise the rewind buffer
* unless the core info struct for the current * unless the core info struct for the current
@ -650,9 +652,10 @@ void state_manager_event_deinit(
if (!rewind_st) if (!rewind_st)
return; return;
restore_callbacks = rewind_st->init_attempted && restore_callbacks =
rewind_st->state && (rewind_st->flags & STATE_MGR_REWIND_ST_FLAG_INIT_ATTEMPTED)
current_core; && (rewind_st->state)
&& (current_core);
if (rewind_st->state) if (rewind_st->state)
{ {
@ -662,10 +665,12 @@ void state_manager_event_deinit(
rewind_st->state = NULL; rewind_st->state = NULL;
rewind_st->size = 0; rewind_st->size = 0;
rewind_st->frame_is_reversed = false; rewind_st->flags &= ~(
rewind_st->init_attempted = false; STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED
rewind_st->hotkey_was_checked = false; | STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_CHECKED
rewind_st->hotkey_was_pressed = false; | STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED
| STATE_MGR_REWIND_ST_FLAG_INIT_ATTEMPTED
);
/* Restore regular (non-rewind) core audio /* Restore regular (non-rewind) core audio
* callbacks if required */ * callbacks if required */
@ -697,35 +702,40 @@ bool state_manager_check_rewind(
bool was_reversed = false; bool was_reversed = false;
#endif #endif
if (!rewind_st || if ( !rewind_st
!rewind_st->init_attempted) || (!(rewind_st->flags & STATE_MGR_REWIND_ST_FLAG_INIT_ATTEMPTED)))
return false; return false;
if (!rewind_st->hotkey_was_checked) if (!(rewind_st->flags & STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_CHECKED))
{ {
rewind_st->hotkey_was_checked = true; rewind_st->flags |= STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_CHECKED;
return false; return false;
} }
if (!rewind_st->state) if (!rewind_st->state)
{ {
if ((pressed && !rewind_st->hotkey_was_pressed) && if ((pressed
!core_info_current_supports_rewind()) && (!(rewind_st->flags
& STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED)))
&& !core_info_current_supports_rewind())
runloop_msg_queue_push(msg_hash_to_str(MSG_REWIND_UNSUPPORTED), runloop_msg_queue_push(msg_hash_to_str(MSG_REWIND_UNSUPPORTED),
1, 100, false, NULL, 1, 100, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
rewind_st->hotkey_was_pressed = pressed; if (pressed)
rewind_st->flags |= STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED;
else
rewind_st->flags &= ~STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED;
return false; return false;
} }
if (rewind_st->frame_is_reversed) if (rewind_st->flags & STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED)
{ {
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
was_reversed = true; was_reversed = true;
#endif #endif
audio_driver_frame_is_reverse(); audio_driver_frame_is_reverse();
rewind_st->frame_is_reversed = false; rewind_st->flags &= ~STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED;
} }
if (pressed) if (pressed)
@ -740,7 +750,7 @@ bool state_manager_check_rewind(
netplay_driver_ctl(RARCH_NETPLAY_CTL_DESYNC_PUSH, NULL); netplay_driver_ctl(RARCH_NETPLAY_CTL_DESYNC_PUSH, NULL);
#endif #endif
rewind_st->frame_is_reversed = true; rewind_st->flags |= STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED;
audio_driver_setup_rewind(); audio_driver_setup_rewind();
@ -802,14 +812,23 @@ bool state_manager_check_rewind(
if (current_core) if (current_core)
{ {
if (current_core->retro_set_audio_sample) if (current_core->retro_set_audio_sample)
current_core->retro_set_audio_sample(rewind_st->frame_is_reversed ? current_core->retro_set_audio_sample(
audio_driver_sample_rewind : audio_driver_sample); (rewind_st->flags
& STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED)
? audio_driver_sample_rewind
: audio_driver_sample);
if (current_core->retro_set_audio_sample_batch) if (current_core->retro_set_audio_sample_batch)
current_core->retro_set_audio_sample_batch(rewind_st->frame_is_reversed ? current_core->retro_set_audio_sample_batch(
audio_driver_sample_batch_rewind : audio_driver_sample_batch); ( rewind_st->flags
& STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED)
? audio_driver_sample_batch_rewind
: audio_driver_sample_batch);
} }
rewind_st->hotkey_was_pressed = pressed; if (pressed)
rewind_st->flags |= STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED;
else
rewind_st->flags &= ~STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED;
return ret; return ret;
} }

View File

@ -57,15 +57,20 @@ struct state_manager
typedef struct state_manager state_manager_t; typedef struct state_manager state_manager_t;
enum state_manager_rewind_st_flags
{
STATE_MGR_REWIND_ST_FLAG_FRAME_IS_REVERSED = (1 << 0),
STATE_MGR_REWIND_ST_FLAG_INIT_ATTEMPTED = (1 << 1),
STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_CHECKED = (1 << 2),
STATE_MGR_REWIND_ST_FLAG_HOTKEY_WAS_PRESSED = (1 << 3)
};
struct state_manager_rewind_state struct state_manager_rewind_state
{ {
/* Rewind support. */ /* Rewind support. */
state_manager_t *state; state_manager_t *state;
size_t size; size_t size;
bool frame_is_reversed; uint8_t flags;
bool init_attempted;
bool hotkey_was_checked;
bool hotkey_was_pressed;
}; };
bool state_manager_frame_is_reversed(void); bool state_manager_frame_is_reversed(void);