Merge pull request #13117 from libretro/move-runloop

Move state to runloop state
This commit is contained in:
Autechre 2021-10-15 14:05:46 +02:00 committed by GitHub
commit 527eb86655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 834 additions and 780 deletions

View File

@ -1590,7 +1590,7 @@ bool audio_driver_callback(void)
bool audio_driver_has_callback(void)
{
return audio_driver_st.callback.callback;
return audio_driver_st.callback.callback != NULL;
}
static INLINE bool audio_driver_alive(void)

View File

@ -2435,3 +2435,31 @@ bool video_driver_texture_unload(uintptr_t *id)
*id = 0;
return true;
}
/**
* video_driver_cached_frame:
*
* Renders the current video frame.
**/
void video_driver_cached_frame(void)
{
runloop_state_t *runloop_st = runloop_state_get_ptr();
recording_state_t *recording_st= recording_state_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr();
void *recording = recording_st->data;
struct retro_callbacks *cbs = &runloop_st->retro_ctx;
/* Cannot allow recording when pushing duped frames. */
recording_st->data = NULL;
if (runloop_st->current_core.inited)
cbs->frame_cb(
(video_st->frame_cache_data != RETRO_HW_FRAME_BUFFER_VALID)
? video_st->frame_cache_data
: NULL,
video_st->frame_cache_width,
video_st->frame_cache_height,
video_st->frame_cache_pitch);
recording_st->data = recording;
}

View File

@ -34,6 +34,8 @@
#include <wiiu/os/energy.h>
#endif
#include "../audio/audio_driver.h"
#include "menu_driver.h"
#include "menu_cbs.h"
#include "../driver.h"
@ -2681,9 +2683,7 @@ int menu_shader_manager_clear_num_passes(struct video_shader *shader)
shader->passes = 0;
#ifdef HAVE_MENU
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
#endif
video_shader_resolve_parameters(shader);
@ -6849,3 +6849,162 @@ void menu_driver_toggle(
*key_event = *frontend_key_event;
}
}
void retroarch_menu_running(void)
{
runloop_state_t *runloop_st = runloop_state_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr();
settings_t *settings = config_get_ptr();
input_driver_state_t *input_st = input_state_get_ptr();
#ifdef HAVE_OVERLAY
bool input_overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu;
#endif
#ifdef HAVE_AUDIOMIXER
bool audio_enable_menu = settings->bools.audio_enable_menu;
bool audio_enable_menu_bgm = settings->bools.audio_enable_menu_bgm;
#endif
struct menu_state *menu_st = &menu_driver_state;
menu_handle_t *menu = menu_st->driver_data;
menu_input_t *menu_input = &menu_st->input_state;
if (menu)
{
if (menu->driver_ctx && menu->driver_ctx->toggle)
menu->driver_ctx->toggle(menu->userdata, true);
menu_st->alive = true;
menu_driver_toggle(
video_st->current_video,
video_st->data,
menu,
menu_input,
settings,
menu_st->alive,
#ifdef HAVE_OVERLAY
input_st->overlay_ptr &&
input_st->overlay_ptr->alive,
#else
false,
#endif
&runloop_st->key_event,
&runloop_st->frontend_key_event,
true);
}
/* Prevent stray input (for a single frame) */
menu_st->input_driver_flushing_input = 1;
#ifdef HAVE_AUDIOMIXER
if (audio_enable_menu && audio_enable_menu_bgm)
audio_driver_mixer_play_menu_sound_looped(AUDIO_MIXER_SYSTEM_SLOT_BGM);
#endif
/* Ensure that game focus mode is disabled when
* running the menu (note: it is not currently
* possible for game focus to be enabled at this
* point, but must safeguard against future changes) */
if (input_st->game_focus_state.enabled)
{
enum input_game_focus_cmd_type game_focus_cmd = GAME_FOCUS_CMD_OFF;
command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, &game_focus_cmd);
}
/* Ensure that menu screensaver is disabled when
* first switching to the menu */
if (menu_st->screensaver_active)
{
menu_ctx_environment_t menu_environ;
menu_environ.type = MENU_ENVIRON_DISABLE_SCREENSAVER;
menu_environ.data = NULL;
menu_st->screensaver_active = false;
menu_driver_ctl(RARCH_MENU_CTL_ENVIRONMENT, &menu_environ);
}
menu_st->input_last_time_us = cpu_features_get_time_usec();
#ifdef HAVE_OVERLAY
if (input_overlay_hide_in_menu)
command_event(CMD_EVENT_OVERLAY_DEINIT, NULL);
#endif
}
void retroarch_menu_running_finished(bool quit)
{
runloop_state_t *runloop_st = runloop_state_get_ptr();
video_driver_state_t*video_st = video_state_get_ptr();
settings_t *settings = config_get_ptr();
input_driver_state_t *input_st = input_state_get_ptr();
struct menu_state *menu_st = &menu_driver_state;
menu_handle_t *menu = menu_st->driver_data;
menu_input_t *menu_input = &menu_st->input_state;
if (menu)
{
if (menu->driver_ctx && menu->driver_ctx->toggle)
menu->driver_ctx->toggle(menu->userdata, false);
menu_st->alive = false;
menu_driver_toggle(
video_st->current_video,
video_st->data,
menu,
menu_input,
settings,
menu_st->alive,
#ifdef HAVE_OVERLAY
input_st->overlay_ptr &&
input_st->overlay_ptr->alive,
#else
false,
#endif
&runloop_st->key_event,
&runloop_st->frontend_key_event,
false);
}
/* Prevent stray input
* (for a single frame) */
menu_st->input_driver_flushing_input = 1;
if (!quit)
{
#ifdef HAVE_AUDIOMIXER
/* Stop menu background music before we exit the menu */
if ( settings &&
settings->bools.audio_enable_menu &&
settings->bools.audio_enable_menu_bgm
)
audio_driver_mixer_stop_stream(AUDIO_MIXER_SYSTEM_SLOT_BGM);
#endif
/* Enable game focus mode, if required */
if (runloop_st->current_core_type != CORE_TYPE_DUMMY)
{
enum input_auto_game_focus_type auto_game_focus_type = settings ?
(enum input_auto_game_focus_type)settings->uints.input_auto_game_focus :
AUTO_GAME_FOCUS_OFF;
if ((auto_game_focus_type == AUTO_GAME_FOCUS_ON) ||
((auto_game_focus_type == AUTO_GAME_FOCUS_DETECT) &&
input_st->game_focus_state.core_requested))
{
enum input_game_focus_cmd_type game_focus_cmd = GAME_FOCUS_CMD_ON;
command_event(CMD_EVENT_GAME_FOCUS_TOGGLE, &game_focus_cmd);
}
}
}
/* Ensure that menu screensaver is disabled when
* switching off the menu */
if (menu_st->screensaver_active)
{
menu_ctx_environment_t menu_environ;
menu_environ.type = MENU_ENVIRON_DISABLE_SCREENSAVER;
menu_environ.data = NULL;
menu_st->screensaver_active = false;
menu_driver_ctl(RARCH_MENU_CTL_ENVIRONMENT, &menu_environ);
}
video_driver_set_texture_enable(false, false);
#ifdef HAVE_OVERLAY
if (!quit)
if (settings && settings->bools.input_overlay_hide_in_menu)
input_overlay_init();
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -83,7 +83,7 @@ void retroarch_override_setting_unset(enum rarch_override_setting enum_idx, void
bool retroarch_override_setting_is_set(enum rarch_override_setting enum_idx, void *data);
void retroarch_set_current_core_type(
void runloop_set_current_core_type(
enum rarch_core_type type, bool explicitly_set);
const char* retroarch_get_shader_preset(void);

View File

@ -490,14 +490,6 @@ enum
RA_OPT_LOAD_MENU_ON_ERROR
};
enum poll_type_override_t
{
POLL_TYPE_OVERRIDE_DONTCARE = 0,
POLL_TYPE_OVERRIDE_EARLY,
POLL_TYPE_OVERRIDE_NORMAL,
POLL_TYPE_OVERRIDE_LATE
};
typedef void *(*constructor_t)(void);
typedef void (*destructor_t )(void*);
@ -510,10 +502,6 @@ typedef struct my_list_t
int size;
} my_list;
#ifdef HAVE_RUNAHEAD
typedef bool(*runahead_load_state_function)(const void*, size_t);
#endif
#ifdef HAVE_DISCORD
/* The Discord API specifies these variables:
- userId --------- char[24] - the userId of the player asking to join
@ -549,8 +537,6 @@ typedef struct discord_state discord_state_t;
struct rarch_state
{
retro_time_t libretro_core_runtime_last;
retro_time_t libretro_core_runtime_usec;
struct global g_extern; /* retro_time_t alignment */
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
rarch_timer_t shader_delay_timer; /* int64_t alignment */
@ -558,22 +544,12 @@ struct rarch_state
#ifdef HAVE_DISCORD
discord_state_t discord_st; /* int64_t alignment */
#endif
struct retro_core_t current_core; /* uint64_t alignment */
#if defined(HAVE_RUNAHEAD)
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
struct retro_core_t secondary_core; /* uint64_t alignment */
#endif
#endif
#ifdef HAVE_RUNAHEAD
uint64_t runahead_last_frame_count;
#endif
struct retro_camera_callback camera_cb; /* uint64_t alignment */
struct string_list *subsystem_fullpaths;
bool *load_no_content_hook;
#if defined(HAVE_RUNAHEAD)
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
char *secondary_library_path;
@ -627,20 +603,6 @@ struct rarch_state
[SUBSYSTEM_MAX_SUBSYSTEM_ROMS]; /* ptr alignment */
content_state_t content_st; /* ptr alignment */
retro_input_state_t input_state_callback_original; /* ptr alignment */
#ifdef HAVE_RUNAHEAD
function_t retro_reset_callback_original; /* ptr alignment */
function_t original_retro_deinit; /* ptr alignment */
function_t original_retro_unload; /* ptr alignment */
runahead_load_state_function
retro_unserialize_callback_original; /* ptr alignment */
#endif
struct retro_callbacks retro_ctx; /* ptr alignment */
#if defined(HAVE_RUNAHEAD)
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
struct retro_callbacks secondary_callbacks; /* ptr alignment */
#endif
#endif
#ifdef HAVE_NETWORKING
struct netplay_room netplay_host_room; /* ptr alignment */
#endif
@ -651,9 +613,6 @@ struct rarch_state
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
dylib_t secondary_lib_handle; /* ptr alignment */
#endif
#endif
#ifdef HAVE_RUNAHEAD
size_t runahead_save_state_size;
#endif
@ -685,7 +644,6 @@ struct rarch_state
#ifdef HAVE_THREAD_STORAGE
sthread_tls_t rarch_tls; /* unsigned alignment */
#endif
unsigned fastforward_after_frames;
#ifdef HAVE_NETWORKING
unsigned server_port_deferred;
@ -694,15 +652,12 @@ struct rarch_state
unsigned perf_ptr_rarch;
unsigned perf_ptr_libretro;
enum rarch_core_type current_core_type;
enum rarch_core_type explicit_current_core_type;
#if defined(HAVE_COMMAND)
enum cmd_source_t lastcmd_source;
#endif
#if defined(HAVE_RUNAHEAD)
enum rarch_core_type last_core_type;
#endif
enum poll_type_override_t core_poll_type_override;
retro_bits_t has_set_libretro_device; /* uint32_t alignment */
@ -745,7 +700,6 @@ struct rarch_state
#endif
bool has_set_username;
bool rarch_error_on_init;
bool has_set_core;
bool has_set_verbosity;
bool has_set_libretro;
bool has_set_libretro_directory;
@ -761,9 +715,6 @@ struct rarch_state
#endif
bool has_set_log_to_file;
bool rarch_is_inited;
bool rarch_is_sram_load_disabled;
bool rarch_is_sram_save_disabled;
bool rarch_use_sram;
bool rarch_ups_pref;
bool rarch_bps_pref;
bool rarch_ips_pref;
@ -771,9 +722,6 @@ struct rarch_state
bool rarch_patch_blocked;
#endif
bool ignore_environment_cb;
bool core_set_shared_context;
#ifdef HAVE_ACCESSIBILITY
/* Is text-to-speech accessibility turned on? */
bool accessibility_enabled;
@ -793,10 +741,7 @@ struct rarch_state
#ifdef HAVE_RUNAHEAD
bool runahead_save_state_size_known;
bool request_fast_savestate;
bool input_is_dirty;
#endif
#if defined(HAVE_NETWORKING)
bool has_set_netplay_mode;
bool has_set_netplay_ip_address;

View File

@ -53,9 +53,7 @@ static void retro_frame_null(const void *data, unsigned width,
unsigned height, size_t pitch);
static void retro_run_null(void);
static void retro_input_poll_null(void);
static void runloop_apply_fastmotion_override(
struct rarch_state *p_rarch, runloop_state_t *p_runloop,
settings_t *settings);
static void runloop_apply_fastmotion_override(runloop_state_t *p_runloop, settings_t *settings);
static void uninit_libretro_symbols(
struct rarch_state *p_rarch,
@ -77,9 +75,8 @@ static void drivers_init(struct rarch_state *p_rarch,
int flags,
bool verbosity_enabled);
static bool core_load(struct rarch_state *p_rarch,
unsigned poll_type_behavior);
static bool core_unload_game(struct rarch_state *p_rarch);
static bool core_load(unsigned poll_type_behavior);
static bool core_unload_game(void);
static bool retroarch_environment_cb(unsigned cmd, void *data);

View File

@ -24,6 +24,7 @@
#include <boolean.h>
#include <retro_inline.h>
#include <retro_common_api.h>
#include <dynamic/dylib.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -33,6 +34,7 @@
#include <rthreads/rthreads.h>
#endif
#include "dynamic.h"
#include "core_option_manager.h"
enum runloop_state_enum
@ -44,6 +46,15 @@ enum runloop_state_enum
RUNLOOP_STATE_QUIT
};
enum poll_type_override_t
{
POLL_TYPE_OVERRIDE_DONTCARE = 0,
POLL_TYPE_OVERRIDE_EARLY,
POLL_TYPE_OVERRIDE_NORMAL,
POLL_TYPE_OVERRIDE_LATE
};
typedef struct runloop_ctx_msg_info
{
const char *msg;
@ -84,13 +95,39 @@ typedef struct core_options_callbacks
retro_core_options_update_display_callback_t update_display;
} core_options_callbacks_t;
#ifdef HAVE_RUNAHEAD
typedef bool(*runahead_load_state_function)(const void*, size_t);
#endif
struct runloop
{
retro_time_t core_runtime_last;
retro_time_t core_runtime_usec;
retro_time_t frame_limit_minimum_time;
retro_time_t frame_limit_last_time;
retro_usec_t frame_time_last; /* int64_t alignment */
retro_usec_t frame_time_last; /* int64_t alignment */
msg_queue_t msg_queue; /* ptr alignment */
struct retro_core_t current_core; /* uint64_t alignment */
#if defined(HAVE_RUNAHEAD)
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
struct retro_core_t secondary_core; /* uint64_t alignment */
#endif
#endif
bool *load_no_content_hook;
struct retro_callbacks retro_ctx; /* ptr alignment */
msg_queue_t msg_queue; /* ptr alignment */
retro_input_state_t input_state_callback_original; /* ptr alignment */
#ifdef HAVE_RUNAHEAD
function_t retro_reset_callback_original; /* ptr alignment */
function_t original_retro_deinit; /* ptr alignment */
function_t original_retro_unload; /* ptr alignment */
runahead_load_state_function
retro_unserialize_callback_original; /* ptr alignment */
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
struct retro_callbacks secondary_callbacks; /* ptr alignment */
#endif
#endif
#ifdef HAVE_THREADS
slock_t *msg_queue_lock;
#endif
@ -108,8 +145,12 @@ struct runloop
unsigned pending_windowed_scale;
unsigned max_frames;
unsigned audio_latency;
unsigned fastforward_after_frames;
fastmotion_overrides_t fastmotion_override; /* float alignment */
enum rarch_core_type current_core_type;
enum rarch_core_type explicit_current_core_type;
enum poll_type_override_t core_poll_type_override;
bool missing_bios;
bool force_nonblock;
@ -137,7 +178,14 @@ struct runloop
#endif
#ifdef HAVE_RUNAHEAD
bool has_variable_update;
bool input_is_dirty;
#endif
bool is_sram_load_disabled;
bool is_sram_save_disabled;
bool use_sram;
bool ignore_environment_cb;
bool core_set_shared_context;
bool has_set_core;
};
typedef struct runloop runloop_state_t;

View File

@ -2061,7 +2061,7 @@ bool task_push_start_current_core(content_ctx_info_t *content_info)
/* Preliminary stuff that has to be done before we
* load the actual content. Can differ per mode. */
retroarch_set_current_core_type(CORE_TYPE_PLAIN, true);
runloop_set_current_core_type(CORE_TYPE_PLAIN, true);
/* Load content */
if (firmware_update_status(&content_ctx))
@ -2122,7 +2122,7 @@ bool task_push_load_new_core(
/* Preliminary stuff that has to be done before we
* load the actual content. Can differ per mode. */
retroarch_set_current_core_type(type, true);
runloop_set_current_core_type(type, true);
return true;
}
@ -2448,7 +2448,7 @@ bool task_push_start_builtin_core(
/* Preliminary stuff that has to be done before we
* load the actual content. Can differ per mode. */
retroarch_set_current_core_type(type, true);
runloop_set_current_core_type(type, true);
/* Load content */
if (!task_load_content_internal(content_info, true, false, false))