Move more state to runloop_state (#13124)

* Move more state to runloop state

* remove unused variable

* Cleanup

* Move more state to runloop_state

* Remove unused variable

* Cleanups

* move input_remapping functions over to input_driver.c

* Some buildfixes
This commit is contained in:
Autechre 2021-10-18 15:23:22 +02:00 committed by GitHub
parent 47a6df871a
commit 514534f99b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 579 additions and 634 deletions

View File

@ -4698,8 +4698,7 @@ void bsv_movie_frame_rewind(void)
}
}
bool bsv_movie_init(struct rarch_state *p_rarch,
input_driver_state_t *input_st)
bool bsv_movie_init(input_driver_state_t *input_st)
{
bsv_movie_t *state = NULL;
if (input_st->bsv_movie_state.movie_start_playback)
@ -5103,3 +5102,159 @@ const hid_driver_t *input_hid_init_first(void)
return NULL;
}
#endif
void input_remapping_cache_global_config(void)
{
unsigned i;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
for (i = 0; i < MAX_USERS; i++)
{
global->old_analog_dpad_mode[i] = settings->uints.input_analog_dpad_mode[i];
global->old_libretro_device[i] = settings->uints.input_libretro_device[i];
}
global->old_analog_dpad_mode_set = true;
global->old_libretro_device_set = true;
}
void input_remapping_enable_global_config_restore(void)
{
global_t *global = global_get_ptr();
global->remapping_cache_active = true;
}
void input_remapping_restore_global_config(bool clear_cache)
{
unsigned i;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
if (!global->remapping_cache_active)
goto end;
for (i = 0; i < MAX_USERS; i++)
{
if (global->old_analog_dpad_mode_set &&
(settings->uints.input_analog_dpad_mode[i] !=
global->old_analog_dpad_mode[i]))
configuration_set_uint(settings,
settings->uints.input_analog_dpad_mode[i],
global->old_analog_dpad_mode[i]);
if (global->old_libretro_device_set &&
(settings->uints.input_libretro_device[i] !=
global->old_libretro_device[i]))
configuration_set_uint(settings,
settings->uints.input_libretro_device[i],
global->old_libretro_device[i]);
}
end:
if (clear_cache)
{
global->old_analog_dpad_mode_set = false;
global->old_libretro_device_set = false;
global->remapping_cache_active = false;
}
}
void input_remapping_update_port_map(void)
{
unsigned i, j;
settings_t *settings = config_get_ptr();
unsigned port_map_index[MAX_USERS] = {0};
/* First pass: 'reset' port map */
for (i = 0; i < MAX_USERS; i++)
for (j = 0; j < (MAX_USERS + 1); j++)
settings->uints.input_remap_port_map[i][j] = MAX_USERS;
/* Second pass: assign port indices from
* 'input_remap_ports' */
for (i = 0; i < MAX_USERS; i++)
{
unsigned remap_port = settings->uints.input_remap_ports[i];
if (remap_port < MAX_USERS)
{
/* 'input_remap_port_map' provides a list of
* 'physical' ports for each 'virtual' port
* sampled in input_state().
* (Note: in the following explanation, port
* index starts from 0, rather than the frontend
* display convention of 1)
* For example - the following remap configuration
* will map input devices 0+1 to port 0, and input
* device 2 to port 1
* > input_remap_ports[0] = 0;
* input_remap_ports[1] = 0;
* input_remap_ports[2] = 1;
* This gives a port map of:
* > input_remap_port_map[0] = { 0, 1, MAX_USERS, ... };
* input_remap_port_map[1] = { 2, MAX_USERS, ... }
* input_remap_port_map[2] = { MAX_USERS, ... }
* ...
* A port map value of MAX_USERS indicates the end
* of the 'physical' port list */
settings->uints.input_remap_port_map[remap_port]
[port_map_index[remap_port]] = i;
port_map_index[remap_port]++;
}
}
}
void input_remapping_deinit(void)
{
global_t *global = global_get_ptr();
runloop_state_t *runloop_st = runloop_state_get_ptr();
if (global->name.remapfile)
free(global->name.remapfile);
global->name.remapfile = NULL;
runloop_st->remaps_core_active = false;
runloop_st->remaps_content_dir_active = false;
runloop_st->remaps_game_active = false;
}
void input_remapping_set_defaults(bool clear_cache)
{
unsigned i, j;
settings_t *settings = config_get_ptr();
for (i = 0; i < MAX_USERS; i++)
{
/* Button/keyboard remaps */
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
{
const struct retro_keybind *keybind = &input_config_binds[i][j];
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j],
keybind ? keybind->id : RARCH_UNMAPPED);
configuration_set_uint(settings,
settings->uints.input_keymapper_ids[i][j], RETROK_UNKNOWN);
}
/* Analog stick remaps */
for (j = RARCH_FIRST_CUSTOM_BIND; j < (RARCH_FIRST_CUSTOM_BIND + 8); j++)
configuration_set_uint(settings,
settings->uints.input_remap_ids[i][j], j);
/* Controller port remaps */
configuration_set_uint(settings,
settings->uints.input_remap_ports[i], i);
}
/* Need to call 'input_remapping_update_port_map()'
* whenever 'settings->uints.input_remap_ports'
* is modified */
input_remapping_update_port_map();
/* Restore 'global' settings that were cached on
* the last core init
* > Prevents remap changes from 'bleeding through'
* into the main config file */
input_remapping_restore_global_config(clear_cache);
}

View File

@ -981,8 +981,7 @@ int16_t input_state_device(
#ifdef HAVE_BSV_MOVIE
void bsv_movie_frame_rewind(void);
bool bsv_movie_init(struct rarch_state *p_rarch,
input_driver_state_t *input_st);
bool bsv_movie_init(input_driver_state_t *input_st);
void bsv_movie_deinit(input_driver_state_t *input_st);

File diff suppressed because it is too large Load Diff

View File

@ -76,10 +76,10 @@ input_st->bsv_movie_state.eof_exit)
#if HAVE_DYNAMIC
#define RUNAHEAD_RUN_SECONDARY(p_rarch) \
if (!secondary_core_run_use_last_input(p_rarch)) \
p_rarch->runahead_secondary_core_available = false
runloop_st->runahead_secondary_core_available = false
#endif
#define RUNAHEAD_RESUME_VIDEO(p_rarch) \
#define RUNAHEAD_RESUME_VIDEO(video_st) \
if (video_st->runahead_is_active) \
video_st->active = true; \
else \
@ -490,18 +490,6 @@ enum
RA_OPT_LOAD_MENU_ON_ERROR
};
typedef void *(*constructor_t)(void);
typedef void (*destructor_t )(void*);
typedef struct my_list_t
{
void **data;
constructor_t constructor;
destructor_t destructor;
int capacity;
int size;
} my_list;
#ifdef HAVE_DISCORD
/* The Discord API specifies these variables:
- userId --------- char[24] - the userId of the player asking to join
@ -538,23 +526,10 @@ typedef struct discord_state discord_state_t;
struct rarch_state
{
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 */
#endif
#ifdef HAVE_DISCORD
discord_state_t discord_st; /* int64_t alignment */
#endif
#ifdef HAVE_RUNAHEAD
uint64_t runahead_last_frame_count;
#endif
struct retro_camera_callback camera_cb; /* uint64_t alignment */
#if defined(HAVE_RUNAHEAD)
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
char *secondary_library_path;
#endif
retro_ctx_load_content_info_t *load_content_info;
#endif
const camera_driver_t *camera_driver;
void *camera_data;
@ -566,7 +541,6 @@ struct rarch_state
void *ui_companion_qt_data;
#endif
const bluetooth_driver_t *bluetooth_driver;
void *bluetooth_data;
@ -582,31 +556,12 @@ struct rarch_state
struct video_shader *menu_driver_shader;
#endif
frontend_ctx_driver_t *current_frontend_ctx;
#ifdef HAVE_RUNAHEAD
my_list *runahead_save_state_list;
my_list *input_state_list;
#endif
struct retro_perf_counter *perf_counters_rarch[MAX_COUNTERS];
struct retro_perf_counter *perf_counters_libretro[MAX_COUNTERS];
#ifdef HAVE_REWIND
struct state_manager_rewind_state rewind_st;
#endif
content_state_t content_st; /* ptr alignment */
#ifdef HAVE_NETWORKING
struct netplay_room netplay_host_room; /* ptr alignment */
#endif
#ifdef HAVE_DYNAMIC
dylib_t lib_handle; /* ptr alignment */
#endif
#if defined(HAVE_RUNAHEAD)
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
dylib_t secondary_lib_handle; /* ptr alignment */
#endif
size_t runahead_save_state_size;
#endif
jmp_buf error_sjlj_context; /* 4-byte alignment,
put it right before long */
#if defined(HAVE_COMMAND)
@ -627,7 +582,6 @@ struct rarch_state
int ai_gamepad_state[MAX_USERS];
#endif
#endif
#ifdef HAVE_NETWORKING
int reannounce;
#endif
@ -635,21 +589,14 @@ struct rarch_state
#ifdef HAVE_THREAD_STORAGE
sthread_tls_t rarch_tls; /* unsigned alignment */
#endif
#ifdef HAVE_NETWORKING
unsigned server_port_deferred;
#endif
unsigned perf_ptr_rarch;
unsigned perf_ptr_libretro;
#if defined(HAVE_COMMAND)
enum cmd_source_t lastcmd_source;
#endif
#if defined(HAVE_RUNAHEAD)
enum rarch_core_type last_core_type;
#endif
retro_bits_t has_set_libretro_device; /* uint32_t alignment */
char error_string[255];
@ -668,8 +615,6 @@ struct rarch_state
char path_core_options_file[PATH_MAX_LENGTH];
char dir_system[PATH_MAX_LENGTH];
char dir_savefile[PATH_MAX_LENGTH];
char current_savefile_dir[PATH_MAX_LENGTH];
char current_savestate_dir[PATH_MAX_LENGTH];
char dir_savestate[PATH_MAX_LENGTH];
#ifdef HAVE_NETWORKING
@ -697,7 +642,6 @@ struct rarch_state
bool qt_is_inited;
#endif
bool has_set_log_to_file;
bool rarch_is_inited;
bool rarch_ups_pref;
bool rarch_bps_pref;
bool rarch_ips_pref;
@ -721,10 +665,6 @@ struct rarch_state
bool wifi_driver_active;
bool camera_driver_active;
#ifdef HAVE_RUNAHEAD
bool runahead_save_state_size_known;
bool request_fast_savestate;
#endif
#if defined(HAVE_NETWORKING)
bool has_set_netplay_mode;
bool has_set_netplay_ip_address;
@ -739,9 +679,4 @@ struct rarch_state
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
bool shader_presets_need_reload;
#endif
#ifdef HAVE_RUNAHEAD
bool runahead_available;
bool runahead_secondary_core_available;
bool runahead_force_input_dirty;
#endif
};

View File

@ -39,10 +39,10 @@ static void retroarch_deinit_drivers(struct rarch_state *p_rarch,
#ifdef HAVE_RUNAHEAD
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
static bool secondary_core_create(struct rarch_state *p_rarch,
settings_t *settings);
static void secondary_core_destroy(struct rarch_state *p_rarch);
runloop_state_t *runloop_st, settings_t *settings);
static void secondary_core_destroy(runloop_state_t *runloop_st);
static bool secondary_core_ensure_exists(struct rarch_state *p_rarch,
settings_t *settings);
runloop_state_t *runloop_st, settings_t *settings);
#endif
static int16_t input_state_get_last(unsigned port,
unsigned device, unsigned index, unsigned id);
@ -60,6 +60,7 @@ static void uninit_libretro_symbols(
struct retro_core_t *current_core);
static bool init_libretro_symbols(
struct rarch_state *p_rarch,
runloop_state_t *runloop_st,
enum rarch_core_type type,
struct retro_core_t *current_core);
@ -94,7 +95,6 @@ static bool accessibility_speak_priority(
#endif
static bool retroarch_apply_shader(
struct rarch_state *p_rarch,
settings_t *settings,
enum rarch_shader_type type, const char *preset_path,
bool message);

View File

@ -36,6 +36,7 @@
#include "dynamic.h"
#include "core_option_manager.h"
#include "state_manager.h"
enum runloop_state_enum
{
@ -97,10 +98,25 @@ typedef struct core_options_callbacks
#ifdef HAVE_RUNAHEAD
typedef bool(*runahead_load_state_function)(const void*, size_t);
typedef void *(*constructor_t)(void);
typedef void (*destructor_t )(void*);
typedef struct my_list_t
{
void **data;
constructor_t constructor;
destructor_t destructor;
int capacity;
int size;
} my_list;
#endif
struct runloop
{
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
rarch_timer_t shader_delay_timer; /* int64_t alignment */
#endif
retro_time_t core_runtime_last;
retro_time_t core_runtime_usec;
retro_time_t frame_limit_minimum_time;
@ -109,11 +125,22 @@ struct runloop
struct retro_core_t current_core; /* uint64_t alignment */
#if defined(HAVE_RUNAHEAD)
uint64_t runahead_last_frame_count; /* uint64_t alignment */
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
struct retro_core_t secondary_core; /* uint64_t alignment */
#endif
retro_ctx_load_content_info_t *load_content_info;
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
char *secondary_library_path;
#endif
my_list *runahead_save_state_list;
my_list *input_state_list;
#endif
#ifdef HAVE_REWIND
struct state_manager_rewind_state rewind_st;
#endif
struct retro_perf_counter *perf_counters_libretro[MAX_COUNTERS];
bool *load_no_content_hook;
struct string_list *subsystem_fullpaths;
struct retro_callbacks retro_ctx; /* ptr alignment */
@ -132,8 +159,8 @@ struct runloop
#ifdef HAVE_THREADS
slock_t *msg_queue_lock;
#endif
size_t msg_queue_size;
content_state_t content_st; /* ptr alignment */
struct retro_subsystem_rom_info
subsystem_data_roms[SUBSYSTEM_MAX_SUBSYSTEMS]
[SUBSYSTEM_MAX_SUBSYSTEM_ROMS]; /* ptr alignment */
@ -146,15 +173,30 @@ struct runloop
rarch_system_info_t system; /* ptr alignment */
struct retro_frame_time_callback frame_time; /* ptr alignment */
struct retro_audio_buffer_status_callback audio_buffer_status; /* ptr alignment */
#ifdef HAVE_DYNAMIC
dylib_t lib_handle; /* ptr alignment */
#endif
#if defined(HAVE_RUNAHEAD)
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
dylib_t secondary_lib_handle; /* ptr alignment */
#endif
size_t runahead_save_state_size;
#endif
size_t msg_queue_size;
unsigned pending_windowed_scale;
unsigned max_frames;
unsigned audio_latency;
unsigned fastforward_after_frames;
unsigned perf_ptr_libretro;
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;
#if defined(HAVE_RUNAHEAD)
enum rarch_core_type last_core_type;
#endif
char runtime_content_path_basename[8192];
char current_library_name[256];
@ -169,7 +211,10 @@ struct runloop
#endif
char runtime_content_path[PATH_MAX_LENGTH];
char runtime_core_path[PATH_MAX_LENGTH];
char savefile_dir[PATH_MAX_LENGTH];
char savestate_dir[PATH_MAX_LENGTH];
bool is_inited;
bool missing_bios;
bool force_nonblock;
bool paused;
@ -196,6 +241,11 @@ struct runloop
#ifdef HAVE_RUNAHEAD
bool has_variable_update;
bool input_is_dirty;
bool runahead_save_state_size_known;
bool request_fast_savestate;
bool runahead_available;
bool runahead_secondary_core_available;
bool runahead_force_input_dirty;
#endif
bool is_sram_load_disabled;
bool is_sram_save_disabled;