mirror of
https://github.com/libretro/RetroArch
synced 2025-03-25 07:43:52 +00:00
Refactor is_paused
This commit is contained in:
parent
74ee9b05f3
commit
ccac72f1e7
@ -616,7 +616,7 @@ bool audio_driver_flush(const int16_t *data, size_t samples)
|
|||||||
driver->recording->push_audio(driver->recording_data, &ffemu_data);
|
driver->recording->push_audio(driver->recording_data, &ffemu_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global->is_paused || settings->audio.mute_enable)
|
if (rarch_main_is_paused() || settings->audio.mute_enable)
|
||||||
return true;
|
return true;
|
||||||
if (!driver->audio_active || !audio_data.data)
|
if (!driver->audio_active || !audio_data.data)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1424,7 +1424,7 @@ bool event_command(enum event_command cmd)
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case EVENT_CMD_PAUSE_CHECKS:
|
case EVENT_CMD_PAUSE_CHECKS:
|
||||||
if (global->is_paused)
|
if (rarch_main_is_paused())
|
||||||
{
|
{
|
||||||
RARCH_LOG("%s\n", msg_hash_to_str(MSG_PAUSED));
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_PAUSED));
|
||||||
event_command(EVENT_CMD_AUDIO_STOP);
|
event_command(EVENT_CMD_AUDIO_STOP);
|
||||||
@ -1439,15 +1439,15 @@ bool event_command(enum event_command cmd)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EVENT_CMD_PAUSE_TOGGLE:
|
case EVENT_CMD_PAUSE_TOGGLE:
|
||||||
global->is_paused = !global->is_paused;
|
rarch_main_set_pause(!rarch_main_is_paused());
|
||||||
event_command(EVENT_CMD_PAUSE_CHECKS);
|
event_command(EVENT_CMD_PAUSE_CHECKS);
|
||||||
break;
|
break;
|
||||||
case EVENT_CMD_UNPAUSE:
|
case EVENT_CMD_UNPAUSE:
|
||||||
global->is_paused = false;
|
rarch_main_set_pause(false);
|
||||||
event_command(EVENT_CMD_PAUSE_CHECKS);
|
event_command(EVENT_CMD_PAUSE_CHECKS);
|
||||||
break;
|
break;
|
||||||
case EVENT_CMD_PAUSE:
|
case EVENT_CMD_PAUSE:
|
||||||
global->is_paused = true;
|
rarch_main_set_pause(true);
|
||||||
event_command(EVENT_CMD_PAUSE_CHECKS);
|
event_command(EVENT_CMD_PAUSE_CHECKS);
|
||||||
break;
|
break;
|
||||||
case EVENT_CMD_MENU_PAUSE_LIBRETRO:
|
case EVENT_CMD_MENU_PAUSE_LIBRETRO:
|
||||||
|
@ -1715,7 +1715,7 @@ static bool gl_frame(void *data, const void *frame,
|
|||||||
* and pause to prevent flicker. */
|
* and pause to prevent flicker. */
|
||||||
if (settings->video.black_frame_insertion &&
|
if (settings->video.black_frame_insertion &&
|
||||||
!driver->nonblock_state && !global->is_slowmotion
|
!driver->nonblock_state && !global->is_slowmotion
|
||||||
&& !global->is_paused)
|
&& !rarch_main_is_paused())
|
||||||
{
|
{
|
||||||
gfx_ctx_swap_buffers(gl);
|
gfx_ctx_swap_buffers(gl);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
@ -431,9 +431,8 @@ static bool thread_alive(void *data)
|
|||||||
{
|
{
|
||||||
bool ret;
|
bool ret;
|
||||||
thread_video_t *thr = (thread_video_t*)data;
|
thread_video_t *thr = (thread_video_t*)data;
|
||||||
global_t *global = global_get_ptr();
|
|
||||||
|
|
||||||
if (global->is_paused)
|
if (rarch_main_is_paused())
|
||||||
{
|
{
|
||||||
thread_packet_t pkt = { CMD_ALIVE };
|
thread_packet_t pkt = { CMD_ALIVE };
|
||||||
thread_send_and_wait(thr, &pkt);
|
thread_send_and_wait(thr, &pkt);
|
||||||
|
@ -295,7 +295,6 @@ static void engine_handle_cmd(void)
|
|||||||
{
|
{
|
||||||
int8_t cmd;
|
int8_t cmd;
|
||||||
struct android_app *android_app = (struct android_app*)g_android;
|
struct android_app *android_app = (struct android_app*)g_android;
|
||||||
global_t *global = global_get_ptr();
|
|
||||||
driver_t *driver = driver_get_ptr();
|
driver_t *driver = driver_get_ptr();
|
||||||
rarch_system_info_t *system = rarch_system_info_get_ptr();
|
rarch_system_info_t *system = rarch_system_info_get_ptr();
|
||||||
|
|
||||||
@ -331,7 +330,7 @@ static void engine_handle_cmd(void)
|
|||||||
scond_broadcast(android_app->cond);
|
scond_broadcast(android_app->cond);
|
||||||
slock_unlock(android_app->mutex);
|
slock_unlock(android_app->mutex);
|
||||||
|
|
||||||
if (global->is_paused)
|
if (rarch_main_is_paused())
|
||||||
event_command(EVENT_CMD_REINIT);
|
event_command(EVENT_CMD_REINIT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -358,7 +357,7 @@ static void engine_handle_cmd(void)
|
|||||||
if (!system->shutdown)
|
if (!system->shutdown)
|
||||||
{
|
{
|
||||||
RARCH_LOG("Pausing RetroArch.\n");
|
RARCH_LOG("Pausing RetroArch.\n");
|
||||||
global->is_paused = true;
|
rarch_main_set_paused(true);
|
||||||
rarch_main_set_idle(true);
|
rarch_main_set_idle(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -388,7 +387,7 @@ static void engine_handle_cmd(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case APP_CMD_GAINED_FOCUS:
|
case APP_CMD_GAINED_FOCUS:
|
||||||
global->is_paused = false;
|
rarch_main_set_paused(false);
|
||||||
rarch_main_set_idle(false);
|
rarch_main_set_idle(false);
|
||||||
|
|
||||||
if ((android_app->sensor_state_mask
|
if ((android_app->sensor_state_mask
|
||||||
|
38
runloop.c
38
runloop.c
@ -45,6 +45,7 @@
|
|||||||
static struct global g_extern;
|
static struct global g_extern;
|
||||||
|
|
||||||
static bool main_is_idle;
|
static bool main_is_idle;
|
||||||
|
static bool main_is_paused;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check_pause:
|
* check_pause:
|
||||||
@ -57,18 +58,17 @@ static bool main_is_idle;
|
|||||||
* Returns: true if libretro pause key was toggled, otherwise false.
|
* Returns: true if libretro pause key was toggled, otherwise false.
|
||||||
**/
|
**/
|
||||||
static bool check_pause(driver_t *driver, settings_t *settings,
|
static bool check_pause(driver_t *driver, settings_t *settings,
|
||||||
global_t *global,
|
|
||||||
bool pause_pressed, bool frameadvance_pressed)
|
bool pause_pressed, bool frameadvance_pressed)
|
||||||
{
|
{
|
||||||
static bool old_focus = true;
|
static bool old_focus = true;
|
||||||
bool focus = true;
|
bool focus = true;
|
||||||
enum event_command cmd = EVENT_CMD_NONE;
|
enum event_command cmd = EVENT_CMD_NONE;
|
||||||
bool old_is_paused = global ? global->is_paused : false;
|
bool old_is_paused = main_is_paused;
|
||||||
const video_driver_t *video = driver ? (const video_driver_t*)driver->video :
|
const video_driver_t *video = driver ? (const video_driver_t*)driver->video :
|
||||||
NULL;
|
NULL;
|
||||||
|
|
||||||
/* FRAMEADVANCE will set us into pause mode. */
|
/* FRAMEADVANCE will set us into pause mode. */
|
||||||
pause_pressed |= !global->is_paused && frameadvance_pressed;
|
pause_pressed |= !main_is_paused && frameadvance_pressed;
|
||||||
|
|
||||||
if (settings->pause_nonactive)
|
if (settings->pause_nonactive)
|
||||||
focus = video->focus(driver->video_data);
|
focus = video->focus(driver->video_data);
|
||||||
@ -85,7 +85,7 @@ static bool check_pause(driver_t *driver, settings_t *settings,
|
|||||||
if (cmd != EVENT_CMD_NONE)
|
if (cmd != EVENT_CMD_NONE)
|
||||||
event_command(cmd);
|
event_command(cmd);
|
||||||
|
|
||||||
if (global->is_paused == old_is_paused)
|
if (main_is_paused == old_is_paused)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -187,7 +187,7 @@ static void check_rewind(settings_t *settings,
|
|||||||
audio_driver_setup_rewind();
|
audio_driver_setup_rewind();
|
||||||
|
|
||||||
rarch_main_msg_queue_push_new(MSG_REWINDING, 0,
|
rarch_main_msg_queue_push_new(MSG_REWINDING, 0,
|
||||||
global->is_paused ? 1 : 30, true);
|
main_is_paused ? 1 : 30, true);
|
||||||
pretro_unserialize(buf, global->rewind.size);
|
pretro_unserialize(buf, global->rewind.size);
|
||||||
|
|
||||||
if (global->bsv.movie)
|
if (global->bsv.movie)
|
||||||
@ -449,7 +449,7 @@ static int do_pre_state_checks(settings_t *settings,
|
|||||||
if (cmd->overlay_next_pressed)
|
if (cmd->overlay_next_pressed)
|
||||||
event_command(EVENT_CMD_OVERLAY_NEXT);
|
event_command(EVENT_CMD_OVERLAY_NEXT);
|
||||||
|
|
||||||
if (!global->is_paused || menu_driver_alive())
|
if (!main_is_paused || menu_driver_alive())
|
||||||
{
|
{
|
||||||
if (cmd->fullscreen_toggle)
|
if (cmd->fullscreen_toggle)
|
||||||
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
|
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
|
||||||
@ -481,7 +481,6 @@ static int do_netplay_state_checks(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int do_pause_state_checks(
|
static int do_pause_state_checks(
|
||||||
global_t *global,
|
|
||||||
bool pause_pressed,
|
bool pause_pressed,
|
||||||
bool frameadvance_pressed,
|
bool frameadvance_pressed,
|
||||||
bool fullscreen_toggle_pressed,
|
bool fullscreen_toggle_pressed,
|
||||||
@ -489,7 +488,7 @@ static int do_pause_state_checks(
|
|||||||
{
|
{
|
||||||
bool check_is_oneshot = frameadvance_pressed || rewind_pressed;
|
bool check_is_oneshot = frameadvance_pressed || rewind_pressed;
|
||||||
|
|
||||||
if (!global->is_paused)
|
if (!main_is_paused)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (fullscreen_toggle_pressed)
|
if (fullscreen_toggle_pressed)
|
||||||
@ -537,11 +536,10 @@ static int do_state_checks(driver_t *driver, settings_t *settings,
|
|||||||
cmd->fullscreen_toggle);
|
cmd->fullscreen_toggle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
check_pause(driver, settings, global,
|
check_pause(driver, settings,
|
||||||
cmd->pause_pressed, cmd->frameadvance_pressed);
|
cmd->pause_pressed, cmd->frameadvance_pressed);
|
||||||
|
|
||||||
if (do_pause_state_checks(
|
if (do_pause_state_checks(
|
||||||
global,
|
|
||||||
cmd->pause_pressed,
|
cmd->pause_pressed,
|
||||||
cmd->frameadvance_pressed,
|
cmd->frameadvance_pressed,
|
||||||
cmd->fullscreen_toggle,
|
cmd->fullscreen_toggle,
|
||||||
@ -634,7 +632,7 @@ static void rarch_update_frame_time(driver_t *driver, settings_t *settings,
|
|||||||
{
|
{
|
||||||
retro_time_t curr_time = rarch_get_time_usec();
|
retro_time_t curr_time = rarch_get_time_usec();
|
||||||
retro_time_t delta = curr_time - system->frame_time_last;
|
retro_time_t delta = curr_time - system->frame_time_last;
|
||||||
bool is_locked_fps = global->is_paused || driver->nonblock_state;
|
bool is_locked_fps = main_is_paused || driver->nonblock_state;
|
||||||
|
|
||||||
is_locked_fps |= !!driver->recording_data;
|
is_locked_fps |= !!driver->recording_data;
|
||||||
|
|
||||||
@ -791,13 +789,13 @@ static INLINE retro_input_t input_keys_pressed(driver_t *driver,
|
|||||||
*
|
*
|
||||||
* Returns: always true (1).
|
* Returns: always true (1).
|
||||||
**/
|
**/
|
||||||
static bool input_flush(retro_input_t *input, global_t *global)
|
static bool input_flush(retro_input_t *input)
|
||||||
{
|
{
|
||||||
*input = 0;
|
*input = 0;
|
||||||
|
|
||||||
/* If core was paused before entering menu, evoke
|
/* If core was paused before entering menu, evoke
|
||||||
* pause toggle to wake it up. */
|
* pause toggle to wake it up. */
|
||||||
if (global->is_paused)
|
if (main_is_paused)
|
||||||
BIT64_SET(*input, RARCH_PAUSE_TOGGLE);
|
BIT64_SET(*input, RARCH_PAUSE_TOGGLE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -871,11 +869,11 @@ global_t *global_get_ptr(void)
|
|||||||
void rarch_main_state_free(void)
|
void rarch_main_state_free(void)
|
||||||
{
|
{
|
||||||
main_is_idle = false;
|
main_is_idle = false;
|
||||||
|
main_is_paused = false;
|
||||||
g_extern.ui_companion_is_on_foreground = false;
|
g_extern.ui_companion_is_on_foreground = false;
|
||||||
g_extern.frames.limit.minimum_time = 0.0;
|
g_extern.frames.limit.minimum_time = 0.0;
|
||||||
g_extern.frames.limit.last_time = 0.0;
|
g_extern.frames.limit.last_time = 0.0;
|
||||||
g_extern.is_slowmotion = false;
|
g_extern.is_slowmotion = false;
|
||||||
g_extern.is_paused = false;
|
|
||||||
g_extern.max_frames = 0;
|
g_extern.max_frames = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -914,11 +912,21 @@ void rarch_main_clear_state(void)
|
|||||||
rarch_main_global_free();
|
rarch_main_global_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rarch_main_set_pause(unsigned enable)
|
||||||
|
{
|
||||||
|
main_is_paused = enable;
|
||||||
|
}
|
||||||
|
|
||||||
void rarch_main_set_idle(unsigned enable)
|
void rarch_main_set_idle(unsigned enable)
|
||||||
{
|
{
|
||||||
main_is_idle = enable;
|
main_is_idle = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool rarch_main_is_paused(void)
|
||||||
|
{
|
||||||
|
return main_is_paused;
|
||||||
|
}
|
||||||
|
|
||||||
bool rarch_main_is_idle(void)
|
bool rarch_main_is_idle(void)
|
||||||
{
|
{
|
||||||
return main_is_idle;
|
return main_is_idle;
|
||||||
@ -1031,7 +1039,7 @@ int rarch_main_iterate(void)
|
|||||||
last_input = input;
|
last_input = input;
|
||||||
|
|
||||||
if (driver->flushing_input)
|
if (driver->flushing_input)
|
||||||
driver->flushing_input = (input) ? input_flush(&input, global) : false;
|
driver->flushing_input = (input) ? input_flush(&input) : false;
|
||||||
|
|
||||||
trigger_input = input & ~old_input;
|
trigger_input = input & ~old_input;
|
||||||
|
|
||||||
|
@ -55,7 +55,6 @@ typedef struct global
|
|||||||
} frames;
|
} frames;
|
||||||
|
|
||||||
bool is_slowmotion;
|
bool is_slowmotion;
|
||||||
bool is_paused;
|
|
||||||
unsigned max_frames;
|
unsigned max_frames;
|
||||||
|
|
||||||
bool verbosity;
|
bool verbosity;
|
||||||
@ -344,6 +343,10 @@ FILE *rarch_main_log_file(void);
|
|||||||
|
|
||||||
bool rarch_main_is_idle(void);
|
bool rarch_main_is_idle(void);
|
||||||
|
|
||||||
|
bool rarch_main_is_paused(void);
|
||||||
|
|
||||||
|
void rarch_main_set_pause(unsigned enable);
|
||||||
|
|
||||||
void rarch_main_set_idle(unsigned enable);
|
void rarch_main_set_idle(unsigned enable);
|
||||||
|
|
||||||
void rarch_main_state_free(void);
|
void rarch_main_state_free(void);
|
||||||
|
@ -330,9 +330,9 @@ bool take_screenshot(void)
|
|||||||
msg = msg_hash_to_str(MSG_FAILED_TO_TAKE_SCREENSHOT);
|
msg = msg_hash_to_str(MSG_FAILED_TO_TAKE_SCREENSHOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
rarch_main_msg_queue_push(msg, 1, global->is_paused ? 1 : 180, true);
|
rarch_main_msg_queue_push(msg, 1, rarch_main_is_paused() ? 1 : 180, true);
|
||||||
|
|
||||||
if (global->is_paused)
|
if (rarch_main_is_paused())
|
||||||
video_driver_cached_frame();
|
video_driver_cached_frame();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -46,8 +46,8 @@ static void rarch_enable_ui(void)
|
|||||||
{
|
{
|
||||||
global_t *global = global_get_ptr();
|
global_t *global = global_get_ptr();
|
||||||
|
|
||||||
global->is_paused = true;
|
|
||||||
global->ui_companion_is_on_foreground = true;
|
global->ui_companion_is_on_foreground = true;
|
||||||
|
rarch_main_set_paused(true);
|
||||||
rarch_main_set_idle(true);
|
rarch_main_set_idle(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ static void rarch_disable_ui(void)
|
|||||||
{
|
{
|
||||||
global_t *global = global_get_ptr();
|
global_t *global = global_get_ptr();
|
||||||
|
|
||||||
global->is_paused = false;
|
|
||||||
global->ui_companion_is_on_foreground = false;
|
global->ui_companion_is_on_foreground = false;
|
||||||
|
rarch_main_set_paused(false);
|
||||||
rarch_main_set_idle(false);
|
rarch_main_set_idle(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ static void rarch_draw(void)
|
|||||||
{
|
{
|
||||||
global_t *global = global_get_ptr();
|
global_t *global = global_get_ptr();
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
bool iterate = iterate_observer && !global->is_paused;
|
bool iterate = iterate_observer && !(rarch_main_is_paused());
|
||||||
|
|
||||||
if (iterate)
|
if (iterate)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user