Start moving rewind code to rewind.c

This commit is contained in:
twinaphex 2015-11-30 22:25:13 +01:00
parent 6b92167050
commit 0db7cda264
9 changed files with 108 additions and 104 deletions

View File

@ -481,7 +481,7 @@ void audio_driver_set_nonblocking_state(bool enable)
**/
static bool audio_driver_flush(const int16_t *data, size_t samples)
{
bool is_slowmotion, is_paused;
bool is_slowmotion;
static struct retro_perf_counter audio_convert_s16 = {0};
static struct retro_perf_counter audio_convert_float = {0};
static struct retro_perf_counter audio_dsp = {0};
@ -495,9 +495,7 @@ static bool audio_driver_flush(const int16_t *data, size_t samples)
recording_push_audio(data, samples);
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, &is_paused);
if (is_paused || settings->audio.mute_enable)
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL) || settings->audio.mute_enable)
return true;
if (!audio_driver_active || !audio_driver_data.data)
return false;

View File

@ -1199,15 +1199,11 @@ bool event_command(enum event_command cmd)
event_init_remapping();
break;
case EVENT_CMD_REWIND_DEINIT:
if (!global)
break;
#ifdef HAVE_NETPLAY
if (driver->netplay_data)
return false;
#endif
if (global->rewind.state)
state_manager_free(global->rewind.state);
global->rewind.state = NULL;
state_manager_event_deinit();
break;
case EVENT_CMD_REWIND_INIT:
if (!driver->netplay_data)
@ -1436,9 +1432,7 @@ bool event_command(enum event_command cmd)
#endif
break;
case EVENT_CMD_PAUSE_CHECKS:
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, &boolean);
if (boolean)
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
{
RARCH_LOG("%s\n", msg_hash_to_str(MSG_PAUSED));
event_command(EVENT_CMD_AUDIO_STOP);
@ -1453,7 +1447,7 @@ bool event_command(enum event_command cmd)
}
break;
case EVENT_CMD_PAUSE_TOGGLE:
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, &boolean);
boolean = runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
boolean = !boolean;
runloop_ctl(RUNLOOP_CTL_SET_PAUSED, &boolean);
event_command(EVENT_CMD_PAUSE_CHECKS);

View File

@ -1840,7 +1840,7 @@ static bool gl_frame(void *data, const void *frame,
#endif
#endif
runloop_ctl(RUNLOOP_CTL_IS_SLOWMOTION, &is_slowmotion);
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, &is_paused);
is_paused = runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
/* Disable BFI during fast forward, slow-motion,
* and pause to prevent flicker. */

View File

@ -432,12 +432,10 @@ static void thread_loop(void *data)
static bool thread_alive(void *data)
{
bool ret, is_paused;
bool ret;
thread_video_t *thr = (thread_video_t*)data;
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, &is_paused);
if (is_paused)
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
{
thread_packet_t pkt = { CMD_ALIVE };
thread_send_and_wait(thr, &pkt);

View File

@ -236,7 +236,6 @@ error:
static void android_input_poll_main_cmd(void)
{
bool is_paused;
int8_t cmd;
struct android_app *android_app = (struct android_app*)g_android;
rarch_system_info_t *system = rarch_system_info_get_ptr();
@ -273,9 +272,7 @@ static void android_input_poll_main_cmd(void)
scond_broadcast(android_app->cond);
slock_unlock(android_app->mutex);
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, &is_paused);
if (is_paused)
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
event_command(EVENT_CMD_REINIT);
break;

View File

@ -98,6 +98,8 @@ repeat {
size thisstart;
#endif
static bool frame_is_reversed;
size_t state_manager_raw_maxsize(size_t uncomp)
{
/* bytes covered by a compressed block */
@ -617,7 +619,6 @@ void init_rewind(void)
state_manager_push_do(global->rewind.state);
}
static bool frame_is_reversed;
bool state_manager_frame_is_reversed(void)
{
@ -628,3 +629,87 @@ void state_manager_set_frame_is_reversed(bool value)
{
frame_is_reversed = value;
}
void state_manager_event_deinit(void)
{
global_t *global = global_get_ptr();
if (!global)
return;
if (global->rewind.state)
state_manager_free(global->rewind.state);
global->rewind.state = NULL;
}
/**
* check_rewind:
* @pressed : was rewind key pressed or held?
*
* Checks if rewind toggle/hold was being pressed and/or held.
**/
void state_manager_check_rewind(bool pressed)
{
static bool first = true;
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
if (state_manager_frame_is_reversed())
{
audio_driver_ctl(RARCH_AUDIO_CTL_FRAME_IS_REVERSE, NULL);
state_manager_set_frame_is_reversed(false);
}
if (first)
{
first = false;
return;
}
if (!global->rewind.state)
return;
if (pressed)
{
const void *buf = NULL;
if (state_manager_pop(global->rewind.state, &buf))
{
state_manager_set_frame_is_reversed(true);
audio_driver_ctl(RARCH_AUDIO_CTL_SETUP_REWIND, NULL);
rarch_main_msg_queue_push_new(MSG_REWINDING, 0,
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL) ? 1 : 30, true);
core.retro_unserialize(buf, global->rewind.size);
if (global->bsv.movie)
bsv_movie_frame_rewind(global->bsv.movie);
}
else
rarch_main_msg_queue_push_new(MSG_REWIND_REACHED_END,
0, 30, true);
}
else
{
static unsigned cnt = 0;
cnt = (cnt + 1) % (settings->rewind_granularity ?
settings->rewind_granularity : 1); /* Avoid possible SIGFPE. */
if ((cnt == 0) || global->bsv.movie)
{
static struct retro_perf_counter rewind_serialize = {0};
void *state = NULL;
state_manager_push_where(global->rewind.state, &state);
rarch_perf_init(&rewind_serialize, "rewind_serialize");
retro_perf_start(&rewind_serialize);
core.retro_serialize(state, global->rewind.size);
retro_perf_stop(&rewind_serialize);
state_manager_push_do(global->rewind.state);
}
}
retro_set_rewind_callbacks();
}

View File

@ -72,6 +72,16 @@ bool state_manager_frame_is_reversed(void);
void state_manager_set_frame_is_reversed(bool value);
void state_manager_event_deinit(void);
/**
* check_rewind:
* @pressed : was rewind key pressed or held?
*
* Checks if rewind toggle/hold was being pressed and/or held.
**/
void state_manager_check_rewind(bool pressed);
#ifdef __cplusplus
}
#endif

View File

@ -291,78 +291,6 @@ static void check_stateslots(settings_t *settings,
RARCH_LOG("%s\n", msg);
}
/**
* check_rewind:
* @pressed : was rewind key pressed or held?
*
* Checks if rewind toggle/hold was being pressed and/or held.
**/
static void check_rewind(settings_t *settings,
global_t *global, bool pressed)
{
static bool first = true;
if (state_manager_frame_is_reversed())
{
audio_driver_ctl(RARCH_AUDIO_CTL_FRAME_IS_REVERSE, NULL);
state_manager_set_frame_is_reversed(false);
}
if (first)
{
first = false;
return;
}
if (!global->rewind.state)
return;
if (pressed)
{
const void *buf = NULL;
if (state_manager_pop(global->rewind.state, &buf))
{
state_manager_set_frame_is_reversed(true);
audio_driver_ctl(RARCH_AUDIO_CTL_SETUP_REWIND, NULL);
rarch_main_msg_queue_push_new(MSG_REWINDING, 0,
main_is_paused ? 1 : 30, true);
core.retro_unserialize(buf, global->rewind.size);
if (global->bsv.movie)
bsv_movie_frame_rewind(global->bsv.movie);
}
else
rarch_main_msg_queue_push_new(MSG_REWIND_REACHED_END,
0, 30, true);
}
else
{
static unsigned cnt = 0;
cnt = (cnt + 1) % (settings->rewind_granularity ?
settings->rewind_granularity : 1); /* Avoid possible SIGFPE. */
if ((cnt == 0) || global->bsv.movie)
{
static struct retro_perf_counter rewind_serialize = {0};
void *state = NULL;
state_manager_push_where(global->rewind.state, &state);
rarch_perf_init(&rewind_serialize, "rewind_serialize");
retro_perf_start(&rewind_serialize);
core.retro_serialize(state, global->rewind.size);
retro_perf_stop(&rewind_serialize);
state_manager_push_do(global->rewind.state);
}
}
retro_set_rewind_callbacks();
}
#define SHADER_EXT_GLSL 0x7c976537U
#define SHADER_EXT_GLSLP 0x0f840c87U
#define SHADER_EXT_CG 0x0059776fU
@ -559,7 +487,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
else if (cmd->load_state_pressed)
event_command(EVENT_CMD_LOAD_STATE);
check_rewind(settings, global, cmd->rewind_pressed);
state_manager_check_rewind(cmd->rewind_pressed);
runloop_ctl(RUNLOOP_CTL_CHECK_SLOWMOTION, &cmd->slowmotion_pressed);
@ -779,13 +707,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
}
break;
case RUNLOOP_CTL_IS_PAUSED:
{
bool *ptr = (bool*)data;
if (!ptr)
return false;
*ptr = main_is_paused;
}
break;
return main_is_paused;
case RUNLOOP_CTL_MSG_QUEUE_DEINIT:
rarch_main_msg_queue_free();
break;

View File

@ -268,7 +268,7 @@ bool take_screenshot(void)
msg = msg_hash_to_str(MSG_FAILED_TO_TAKE_SCREENSHOT);
}
runloop_ctl(RUNLOOP_CTL_IS_PAUSED, &is_paused);
is_paused = runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
rarch_main_msg_queue_push(msg, 1, is_paused ? 1 : 180, true);