diff --git a/audio/audio_driver.c b/audio/audio_driver.c index b9682855d9..f423aa534e 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -807,9 +807,9 @@ void audio_driver_sample(int16_t left, int16_t right) recording_st->driver->push_audio(recording_st->data, &ffemu_data); } - if (!( runloop_st->paused + if (!( (runloop_st->flags & RUNLOOP_FLAG_PAUSED) || !(audio_st->flags & AUDIO_FLAG_ACTIVE) - || !audio_st->output_samples_buf)) + || !(audio_st->output_samples_buf))) audio_driver_flush(audio_st, config_get_ptr()->floats.slowmotion_ratio, config_get_ptr()->bools.audio_fastforward_mute, @@ -855,9 +855,9 @@ size_t audio_driver_sample_batch(const int16_t *data, size_t frames) record_st->driver->push_audio(record_st->data, &ffemu_data); } - if (!( runloop_st->paused + if (!( (runloop_st->flags & RUNLOOP_FLAG_PAUSED) || !(audio_st->flags & AUDIO_FLAG_ACTIVE) - || !audio_st->output_samples_buf)) + || !(audio_st->output_samples_buf))) audio_driver_flush(audio_st, config_get_ptr()->floats.slowmotion_ratio, config_get_ptr()->bools.audio_fastforward_mute, @@ -1574,7 +1574,8 @@ bool audio_driver_disable_callback(void) bool audio_driver_callback(void) { settings_t *settings = config_get_ptr(); - bool runloop_paused = runloop_state_get_ptr()->paused; + uint32_t runloop_flags = runloop_get_flags(); + bool runloop_paused = runloop_flags & RUNLOOP_FLAG_PAUSED; #ifdef HAVE_MENU #ifdef HAVE_NETWORKING bool core_paused = runloop_paused || @@ -1672,9 +1673,9 @@ void audio_driver_frame_is_reverse(void) } if (!( - runloop_st->paused + (runloop_st->flags & RUNLOOP_FLAG_PAUSED) || !(audio_st->flags & AUDIO_FLAG_ACTIVE) - || !audio_st->output_samples_buf)) + || !(audio_st->output_samples_buf))) if (!(audio_st->flags & AUDIO_FLAG_SUSPENDED)) { settings_t *settings = config_get_ptr(); @@ -1825,7 +1826,7 @@ void audio_driver_menu_sample(void) unsigned sample_count = (info->sample_rate / info->fps) * 2; audio_driver_state_t *audio_st = &audio_driver_st; bool check_flush = !( - (runloop_st->paused) + (runloop_st->flags & RUNLOOP_FLAG_PAUSED) || !(audio_st->flags & AUDIO_FLAG_ACTIVE) || !audio_st->output_samples_buf); if ((audio_st->flags & AUDIO_FLAG_SUSPENDED)) diff --git a/command.c b/command.c index d3bda9b43c..9992ff4a04 100644 --- a/command.c +++ b/command.c @@ -814,7 +814,7 @@ bool command_get_status(command_t *cmd, const char* arg) core_info_get_current_core(&core_info); - if (runloop_st->paused) + if (runloop_st->flags & RUNLOOP_FLAG_PAUSED) status = "PAUSED"; if (core_info) system_id = core_info->system_id; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 7702de5e92..a830fb01ac 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -2832,11 +2832,11 @@ VIDEO_FLAG_WIDGETS_FAST_FORWARD; video_info->overlay_behind_menu = false; #endif - video_info->runloop_is_paused = runloop_st->paused; - video_info->runloop_is_slowmotion = runloop_st->flags & RUNLOOP_FLAG_SLOWMOTION; - video_info->fastforward_frameskip = settings->bools.fastforward_frameskip; + video_info->runloop_is_paused = runloop_st->flags & RUNLOOP_FLAG_PAUSED; + video_info->runloop_is_slowmotion = runloop_st->flags & RUNLOOP_FLAG_SLOWMOTION; + video_info->fastforward_frameskip = settings->bools.fastforward_frameskip; - video_info->input_driver_nonblock_state = input_st ? + video_info->input_driver_nonblock_state = input_st ? (input_st->flags & INP_FLAG_NONBLOCKING) : false; video_info->input_driver_grab_mouse_state = (input_st->flags & INP_FLAG_GRAB_MOUSE_STATE); @@ -3630,7 +3630,7 @@ void video_driver_frame(const void *data, unsigned width, runloop_state_t *runloop_st = runloop_state_get_ptr(); const enum retro_pixel_format video_driver_pix_fmt = video_st->pix_fmt; - bool runloop_idle = runloop_st->idle; + bool runloop_idle = runloop_st->flags & RUNLOOP_FLAG_IDLE; bool video_driver_active = video_st->flags & VIDEO_FLAG_ACTIVE; #if defined(HAVE_GFX_WIDGETS) dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr(); diff --git a/retroarch.c b/retroarch.c index ff9282cb52..7540bfd98c 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1571,13 +1571,8 @@ bool command_event(enum event_command cmd, void *data) if (ai_service_pause) { - /* pause on call, unpause on second press. */ - if (!runloop_st->paused) - { - command_event(CMD_EVENT_PAUSE, NULL); - command_event(CMD_EVENT_AI_SERVICE_CALL, NULL); - } - else + /* Unpause on second press */ + if (runloop_st->flags & RUNLOOP_FLAG_PAUSED) { #ifdef HAVE_ACCESSIBILITY bool accessibility_enable = settings->bools.accessibility_enable; @@ -1592,6 +1587,11 @@ bool command_event(enum event_command cmd, void *data) #endif command_event(CMD_EVENT_UNPAUSE, NULL); } + else /* Pause on call */ + { + command_event(CMD_EVENT_PAUSE, NULL); + command_event(CMD_EVENT_AI_SERVICE_CALL, NULL); + } } else { @@ -2662,8 +2662,9 @@ bool command_event(enum event_command cmd, void *data) break; #endif - boolean = runloop_st->paused; - boolean = !boolean; + boolean = ((runloop_st->flags & RUNLOOP_FLAG_PAUSED) > +0); + boolean = !boolean; #ifdef HAVE_ACCESSIBILITY if (is_accessibility_enabled( @@ -2683,7 +2684,10 @@ bool command_event(enum event_command cmd, void *data) } #endif - runloop_st->paused = boolean; + if (boolean) + runloop_st->flags |= RUNLOOP_FLAG_PAUSED; + else + runloop_st->flags &= ~RUNLOOP_FLAG_PAUSED; runloop_pause_checks(); } break; @@ -2694,7 +2698,7 @@ bool command_event(enum event_command cmd, void *data) #endif boolean = false; - runloop_st->paused = boolean; + runloop_st->flags &= ~RUNLOOP_FLAG_PAUSED; runloop_pause_checks(); break; case CMD_EVENT_PAUSE: @@ -2704,7 +2708,7 @@ bool command_event(enum event_command cmd, void *data) #endif boolean = true; - runloop_st->paused = boolean; + runloop_st->flags |= RUNLOOP_FLAG_PAUSED; runloop_pause_checks(); break; case CMD_EVENT_MENU_PAUSE_LIBRETRO: @@ -3404,7 +3408,7 @@ bool command_event(enum event_command cmd, void *data) else #endif { - bool paused = runloop_st->paused; + bool paused = runloop_st->flags & RUNLOOP_FLAG_PAUSED; if (data) paused = *((bool*)data); @@ -3917,9 +3921,9 @@ void emscripten_mainloop(void) bool black_frame_insertion = settings->uints.video_black_frame_insertion; bool input_driver_nonblock_state = input_st ? (input_st->flags & INP_FLAG_NONBLOCKING) : false; - runloop_state_t *runloop_st = runloop_state_get_ptr(); - bool runloop_is_slowmotion = runloop_st->flags & RUNLOOP_FLAG_SLOWMOTION; - bool runloop_is_paused = runloop_st->paused; + uint32_t runloop_flags = runloop_get_flags(); + bool runloop_is_slowmotion = runloop_flags & RUNLOOP_FLAG_SLOWMOTION; + bool runloop_is_paused = runloop_flags & RUNLOOP_FLAG_PAUSED; RWebAudioRecalibrateTime(); @@ -5798,13 +5802,13 @@ bool retroarch_ctl(enum rarch_ctl_state state, void *data) { input_driver_state_t *input_st = input_state_get_ptr(); runloop_st->perfcnt_enable = false; - runloop_st->idle = false; - runloop_st->paused = false; #ifdef HAVE_CONFIGFILE runloop_st->flags &= ~RUNLOOP_FLAG_OVERRIDES_ACTIVE; #endif runloop_st->flags &= ~(RUNLOOP_FLAG_AUTOSAVE | RUNLOOP_FLAG_SLOWMOTION + | RUNLOOP_FLAG_IDLE + | RUNLOOP_FLAG_PAUSED ); runloop_frame_time_free(); runloop_audio_buffer_status_free(); @@ -5817,13 +5821,16 @@ bool retroarch_ctl(enum rarch_ctl_state state, void *data) } break; case RARCH_CTL_IS_IDLE: - return runloop_st->idle; + return ((runloop_st->flags & RUNLOOP_FLAG_IDLE) > 0); case RARCH_CTL_SET_IDLE: { bool *ptr = (bool*)data; if (!ptr) return false; - runloop_st->idle = *ptr; + if (*ptr) + runloop_st->flags |= RUNLOOP_FLAG_IDLE; + else + runloop_st->flags &= ~RUNLOOP_FLAG_IDLE; } break; case RARCH_CTL_SET_PAUSED: @@ -5831,11 +5838,14 @@ bool retroarch_ctl(enum rarch_ctl_state state, void *data) bool *ptr = (bool*)data; if (!ptr) return false; - runloop_st->paused = *ptr; + if (*ptr) + runloop_st->flags |= RUNLOOP_FLAG_PAUSED; + else + runloop_st->flags &= ~RUNLOOP_FLAG_PAUSED; } break; case RARCH_CTL_IS_PAUSED: - return runloop_st->paused; + return ((runloop_st->flags & RUNLOOP_FLAG_PAUSED) > 0); case RARCH_CTL_SET_SHUTDOWN: runloop_st->flags |= RUNLOOP_FLAG_SHUTDOWN_INITIATED; break; diff --git a/runloop.c b/runloop.c index 2eee982648..116934c42e 100644 --- a/runloop.c +++ b/runloop.c @@ -3126,7 +3126,7 @@ bool runloop_environment_cb(unsigned cmd, void *data) audio_state_get_ptr(); bool menu_opened = false; - bool core_paused = runloop_st->paused; + bool core_paused = runloop_st->flags & RUNLOOP_FLAG_PAUSED; bool no_audio = ((audio_st->flags & AUDIO_FLAG_SUSPENDED) || !(audio_st->flags & AUDIO_FLAG_ACTIVE)); float core_fps = (float)video_st->av_info.timing.fps; @@ -5657,8 +5657,8 @@ void runloop_pause_checks(void) presence_userdata_t userdata; #endif runloop_state_t *runloop_st = &runloop_state; - bool is_paused = runloop_st->paused; - bool is_idle = runloop_st->idle; + bool is_paused = runloop_st->flags & RUNLOOP_FLAG_PAUSED; + bool is_idle = runloop_st->flags & RUNLOOP_FLAG_IDLE; #if defined(HAVE_GFX_WIDGETS) video_driver_state_t *video_st = video_state_get_ptr(); dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr(); @@ -6384,7 +6384,7 @@ static bool display_menu_libretro( bool libretro_running, retro_time_t current_time) { - bool runloop_idle = runloop_st->idle; + bool runloop_idle = runloop_st->flags & RUNLOOP_FLAG_IDLE; video_driver_state_t*video_st = video_state_get_ptr(); if ( video_st->poke @@ -6469,7 +6469,7 @@ static enum runloop_state_enum runloop_check_state( uint64_t frame_count = 0; bool focused = true; bool rarch_is_initialized = runloop_st->is_inited; - bool runloop_paused = runloop_st->paused; + bool runloop_paused = runloop_st->flags & RUNLOOP_FLAG_PAUSED; bool pause_nonactive = settings->bools.pause_nonactive; unsigned quit_gamepad_combo = settings->uints.input_quit_gamepad_combo; #ifdef HAVE_MENU @@ -6586,11 +6586,14 @@ MENU_ST_FLAG_IS_BINDING; /* Automatic mouse grab on focus */ if ( settings->bools.input_auto_mouse_grab - && is_focused - && (is_focused != runloop_st->focused) + && (is_focused) + && (is_focused != (((runloop_st->flags & RUNLOOP_FLAG_FOCUSED)) > 0)) && !(input_st->flags & INP_FLAG_GRAB_MOUSE_STATE)) command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); - runloop_st->focused = is_focused; + if (is_focused) + runloop_st->flags |= RUNLOOP_FLAG_FOCUSED; + else + runloop_st->flags &= ~RUNLOOP_FLAG_FOCUSED; #ifdef HAVE_OVERLAY if (settings->bools.input_overlay_enable) @@ -6959,7 +6962,7 @@ MENU_ST_FLAG_IS_BINDING; retroarch_menu_running_finished(false); } - if (focused || !runloop_st->idle) + if (focused || !(runloop_st->flags & RUNLOOP_FLAG_IDLE)) { bool runloop_is_inited = runloop_st->is_inited; #ifdef HAVE_NETWORKING @@ -7004,11 +7007,11 @@ MENU_ST_FLAG_IS_BINDING; menu->userdata, video_st->width, video_st->height, - runloop_st->idle); + runloop_st->flags & RUNLOOP_FLAG_IDLE); } if ( (menu_st->flags & MENU_ST_FLAG_ALIVE) - && !(runloop_st->idle)) + && !(runloop_st->flags & RUNLOOP_FLAG_IDLE)) if (display_menu_libretro(runloop_st, input_st, settings->floats.slowmotion_ratio, libretro_running, current_time)) @@ -7028,14 +7031,14 @@ MENU_ST_FLAG_IS_BINDING; old_input = current_bits; old_action = action; - if (!focused || runloop_st->idle) + if (!focused || (runloop_st->flags & RUNLOOP_FLAG_IDLE)) return RUNLOOP_STATE_POLLED_AND_SLEEP; } else #endif #endif { - if (runloop_st->idle) + if (runloop_st->flags & RUNLOOP_FLAG_IDLE) { cbs->poll_cb(); return RUNLOOP_STATE_POLLED_AND_SLEEP; @@ -7203,8 +7206,10 @@ MENU_ST_FLAG_IS_BINDING; { static int unpaused_frames = 0; + if (runloop_st->flags & RUNLOOP_FLAG_PAUSED) + unpaused_frames = 0; + else /* Frame advance is not allowed when achievement hardcore is active */ - if (!runloop_st->paused) { /* Limit pause to approximately three times per second (depending on core framerate) */ if (unpaused_frames < 20) @@ -7213,8 +7218,6 @@ MENU_ST_FLAG_IS_BINDING; pause_pressed = false; } } - else - unpaused_frames = 0; } else #endif @@ -7223,7 +7226,7 @@ MENU_ST_FLAG_IS_BINDING; trig_frameadvance = frameadvance_pressed && !old_frameadvance; /* FRAMEADVANCE will set us into pause mode. */ - pause_pressed |= !runloop_st->paused + pause_pressed |= (!(runloop_st->flags & RUNLOOP_FLAG_PAUSED)) && trig_frameadvance; } @@ -7244,9 +7247,9 @@ MENU_ST_FLAG_IS_BINDING; old_pause_pressed = pause_pressed; old_frameadvance = frameadvance_pressed; - if (runloop_st->paused) + if (runloop_st->flags & RUNLOOP_FLAG_PAUSED) { - bool toggle = !runloop_st->idle ? true : false; + bool toggle = (!(runloop_st->flags & RUNLOOP_FLAG_IDLE)) ? true : false; HOTKEY_CHECK(RARCH_FULLSCREEN_TOGGLE_KEY, CMD_EVENT_FULLSCREEN_TOGGLE, true, &toggle); @@ -7451,7 +7454,7 @@ MENU_ST_FLAG_IS_BINDING; &runloop_st->current_core, BIT256_GET(current_bits, RARCH_REWIND), settings->uints.rewind_granularity, - runloop_st->paused, + runloop_st->flags & RUNLOOP_FLAG_PAUSED, s, sizeof(s), &t); #if defined(HAVE_GFX_WIDGETS) @@ -7499,7 +7502,7 @@ MENU_ST_FLAG_IS_BINDING; if (runloop_st->flags & RUNLOOP_FLAG_SLOWMOTION) { if (settings->uints.video_black_frame_insertion) - if (!runloop_st->idle) + if (!(runloop_st->flags & RUNLOOP_FLAG_IDLE)) video_driver_cached_frame(); #if defined(HAVE_GFX_WIDGETS) @@ -7669,10 +7672,10 @@ int runloop_iterate(void) #else bool menu_pause_libretro = settings->bools.menu_pause_libretro; #endif - bool core_paused = runloop_st->paused || -(menu_pause_libretro && (menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE)); + bool core_paused = (runloop_st->flags & +RUNLOOP_FLAG_PAUSED) || (menu_pause_libretro && (menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE)); #else - bool core_paused = runloop_st->paused; + bool core_paused = (runloop_st->flags & RUNLOOP_FLAG_PAUSED); #endif float slowmotion_ratio = settings->floats.slowmotion_ratio; #ifdef HAVE_CHEEVOS @@ -7697,7 +7700,8 @@ int runloop_iterate(void) * Limits frame time if fast forward ratio throttle is enabled. */ retro_usec_t runloop_last_frame_time = runloop_st->frame_time_last; retro_time_t current = current_time; - bool is_locked_fps = (runloop_st->paused + bool is_locked_fps = ( + (runloop_st->flags & RUNLOOP_FLAG_PAUSED) || (input_st->flags & INP_FLAG_NONBLOCKING)) | !!recording_st->data; retro_time_t delta = (!runloop_last_frame_time || is_locked_fps) @@ -7726,7 +7730,7 @@ int runloop_iterate(void) unsigned audio_buf_occupancy = 0; bool audio_buf_underrun = false; - if (!( runloop_st->paused + if (!( (runloop_st->flags & RUNLOOP_FLAG_PAUSED) || !(audio_st->flags & AUDIO_FLAG_ACTIVE) || !(audio_st->output_samples_buf)) && audio_st->current_audio->write_avail diff --git a/runloop.h b/runloop.h index 3fae73857d..92a237329a 100644 --- a/runloop.h +++ b/runloop.h @@ -159,7 +159,10 @@ enum runloop_flags RUNLOOP_FLAG_RUNAHEAD_SECONDARY_CORE_AVAILABLE = (1 << 23), RUNLOOP_FLAG_RUNAHEAD_FORCE_INPUT_DIRTY = (1 << 24), RUNLOOP_FLAG_SLOWMOTION = (1 << 25), - RUNLOOP_FLAG_FASTMOTION = (1 << 26) + RUNLOOP_FLAG_FASTMOTION = (1 << 26), + RUNLOOP_FLAG_PAUSED = (1 << 27), + RUNLOOP_FLAG_IDLE = (1 << 28), + RUNLOOP_FLAG_FOCUSED = (1 << 29) }; struct runloop @@ -296,9 +299,6 @@ struct runloop bool is_inited; bool missing_bios; bool force_nonblock; - bool paused; - bool idle; - bool focused; bool perfcnt_enable; }; diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index 43a2590ebf..3bd0780c18 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -545,7 +545,7 @@ bool take_screenshot( bool savestate, bool has_valid_framebuffer, bool fullpath, bool use_thread) { - runloop_state_t *runloop_st = runloop_state_get_ptr(); + uint32_t runloop_flags = runloop_get_flags(); settings_t *settings = config_get_ptr(); bool video_gpu_screenshot = settings->bools.video_gpu_screenshot; bool is_paused = false; @@ -557,13 +557,10 @@ bool take_screenshot( /* Avoid GPU screenshots with savestates */ if (supports_viewport_read && video_gpu_screenshot && !savestate) - prefer_viewport_read = true; + prefer_viewport_read = true; - if (runloop_st) - { - is_paused = runloop_st->paused; - is_idle = runloop_st->idle; - } + is_paused = runloop_flags & RUNLOOP_FLAG_PAUSED; + is_idle = runloop_flags & RUNLOOP_FLAG_IDLE; /* No way to infer screenshot directory. */ if ( string_is_empty(screenshot_dir) diff --git a/tasks/task_translation.c b/tasks/task_translation.c index 36c30ecfec..8a705caa64 100644 --- a/tasks/task_translation.c +++ b/tasks/task_translation.c @@ -53,7 +53,7 @@ static void task_auto_translate_handler(retro_task_t *task) { int *mode_ptr = (int*)task->user_data; - runloop_state_t *runloop_st = runloop_state_get_ptr(); + uint32_t runloop_flags = runloop_get_flags(); access_state_t *access_st = access_state_get_ptr(); #ifdef HAVE_ACCESSIBILITY settings_t *settings = config_get_ptr(); @@ -91,7 +91,7 @@ task_finished: if (*mode_ptr == 1 || *mode_ptr == 2) { - bool was_paused = runloop_st->paused; + bool was_paused = runloop_flags & RUNLOOP_FLAG_PAUSED; command_event(CMD_EVENT_AI_SERVICE_CALL, &was_paused); } if (task->user_data) @@ -157,11 +157,11 @@ static void handle_translation_cb( char* auto_string = NULL; char* key_string = NULL; settings_t* settings = config_get_ptr(); - runloop_state_t *runloop_st = runloop_state_get_ptr(); + uint32_t runloop_flags = runloop_get_flags(); #ifdef HAVE_ACCESSIBILITY input_driver_state_t *input_st = input_state_get_ptr(); #endif - bool was_paused = runloop_st->paused; + bool was_paused = runloop_flags & RUNLOOP_FLAG_PAUSED; video_driver_state_t *video_st = video_state_get_ptr(); const enum retro_pixel_format