Less passing around of settings_t pointer

This commit is contained in:
LibretroAdmin 2025-02-10 16:11:18 +01:00
parent ddd7ff2d33
commit 1a561ea0c2
5 changed files with 78 additions and 58 deletions

View file

@ -84,11 +84,10 @@ static void command_post_state_loaded(void)
netplay_driver_ctl(RARCH_NETPLAY_CTL_LOAD_SAVESTATE, NULL);
#endif
{
settings_t *settings = config_get_ptr();
video_driver_state_t *video_st =
video_state_get_ptr();
bool frame_time_counter_reset_after_load_state =
settings->bools.frame_time_counter_reset_after_load_state;
config_get_ptr()->bools.frame_time_counter_reset_after_load_state;
if (frame_time_counter_reset_after_load_state)
video_st->frame_time_count = 0;
}
@ -1255,6 +1254,7 @@ size_t command_event_save_auto_state(void)
{
size_t _len;
runloop_state_t *runloop_st = runloop_state_get_ptr();
const char *name_savestate = runloop_st->name.savestate;
char savestate_name_auto[PATH_MAX_LENGTH];
if (runloop_st->entry_state_slot > -1)
return 0;
@ -1262,8 +1262,7 @@ size_t command_event_save_auto_state(void)
return 0;
if (string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME))))
return 0;
_len = strlcpy(savestate_name_auto,
runloop_st->name.savestate,
_len = strlcpy(savestate_name_auto, name_savestate,
sizeof(savestate_name_auto));
_len += strlcpy(savestate_name_auto + _len, ".auto",
sizeof(savestate_name_auto) - _len);
@ -1367,6 +1366,7 @@ void command_event_load_auto_state(void)
size_t _len;
char savestate_name_auto[PATH_MAX_LENGTH];
runloop_state_t *runloop_st = runloop_state_get_ptr();
const char *name_savestate = runloop_st->name.savestate;
if (!core_info_current_supports_savestate())
return;
@ -1380,8 +1380,7 @@ void command_event_load_auto_state(void)
return;
#endif
_len = strlcpy(savestate_name_auto,
runloop_st->name.savestate,
_len = strlcpy(savestate_name_auto, name_savestate,
sizeof(savestate_name_auto));
strlcpy(savestate_name_auto + _len, ".auto",
sizeof(savestate_name_auto) - _len);
@ -1412,7 +1411,10 @@ void command_event_load_auto_state(void)
* @param last_index Return value for load slot.
* @param @s Return value for file name that should be removed.
*/
static void scan_states(settings_t *settings,
static void command_scan_states(
bool show_hidden_files,
unsigned savestate_max_keep,
int curr_state_slot,
unsigned *last_index, char *s)
{
/* Base name of 128 may be too short for some (<<1%) of the
@ -1421,9 +1423,7 @@ static void scan_states(settings_t *settings,
char state_base[128];
char state_dir[DIR_MAX_LENGTH];
runloop_state_t *runloop_st = runloop_state_get_ptr();
bool show_hidden_files = settings->bools.show_hidden_files;
unsigned savestate_max_keep = settings->uints.savestate_max_keep;
int curr_state_slot = settings->ints.state_slot;
const char *name_savestate = runloop_st->name.savestate;
unsigned max_idx = 0;
unsigned loa_idx = 0;
@ -1439,15 +1439,14 @@ static void scan_states(settings_t *settings,
size_t i, cnt = 0;
size_t cnt_in_range = 0;
fill_pathname_basedir(state_dir, runloop_st->name.savestate,
fill_pathname_basedir(state_dir, name_savestate,
sizeof(state_dir));
if (!(dir_list = dir_list_new_special(state_dir,
DIR_LIST_PLAIN, NULL, show_hidden_files)))
return;
fill_pathname_base(state_base, runloop_st->name.savestate,
sizeof(state_base));
fill_pathname_base(state_base, name_savestate, sizeof(state_base));
for (i = 0; i < dir_list->size; i++)
{
@ -1639,7 +1638,10 @@ void command_event_set_savestate_auto_index(settings_t *settings)
configuration_set_int(settings, settings->ints.state_slot, 0);
return;
}
scan_states(settings, &max_idx, NULL);
command_scan_states(
settings->bools.show_hidden_files,
settings->uints.savestate_max_keep,
settings->ints.state_slot, &max_idx, NULL);
configuration_set_int(settings, settings->ints.state_slot, max_idx);
RARCH_LOG("[State]: %s: #%d.\n",
msg_hash_to_str(MSG_FOUND_LAST_STATE_SLOT),
@ -1655,7 +1657,10 @@ static void command_event_set_savestate_garbage_collect(settings_t *settings)
{
size_t i;
char state_to_delete[PATH_MAX_LENGTH] = {0};
scan_states(settings, NULL, state_to_delete);
command_scan_states(
settings->bools.show_hidden_files,
settings->uints.savestate_max_keep,
settings->ints.state_slot, NULL, state_to_delete);
/* Only delete one save state per save action
* > Conservative behaviour, designed to minimise
* the risk of deleting multiple incorrect files
@ -1676,37 +1681,37 @@ static void command_event_set_savestate_garbage_collect(settings_t *settings)
void command_event_set_replay_auto_index(settings_t *settings)
{
size_t i;
char elem_base[128];
char state_base[128];
char state_dir[DIR_MAX_LENGTH];
struct string_list *dir_list = NULL;
unsigned max_idx = 0;
runloop_state_t *runloop_st = runloop_state_get_ptr();
const char *name_replay = runloop_st->name.replay;
bool replay_auto_index = settings->bools.replay_auto_index;
bool show_hidden_files = settings->bools.show_hidden_files;
if (!replay_auto_index)
return;
/* Find the file in the same directory as runloop_st->names.replay
/* Find the file in the same directory as runloop_st->name.replay
* with the largest numeral suffix.
*
* E.g. /foo/path/content.replay will try to find
* /foo/path/content.replay%d, where %d is the largest number available.
*/
fill_pathname_basedir(state_dir, runloop_st->name.replay,
fill_pathname_basedir(state_dir, name_replay,
sizeof(state_dir));
if (!(dir_list = dir_list_new_special(state_dir,
DIR_LIST_PLAIN, NULL, show_hidden_files)))
return;
fill_pathname_base(state_base, runloop_st->name.replay,
sizeof(state_base));
fill_pathname_base(state_base, name_replay, sizeof(state_base));
for (i = 0; i < dir_list->size; i++)
{
unsigned idx;
char elem_base[128] = {0};
const char *end = NULL;
const char *dir_elem = dir_list->elems[i].data;
size_t _len = fill_pathname_base(elem_base, dir_elem, sizeof(elem_base));
@ -1743,21 +1748,20 @@ void command_event_set_replay_garbage_collect(
size_t i, cnt = 0;
char tmp[DIR_MAX_LENGTH];
runloop_state_t *runloop_st = runloop_state_get_ptr();
const char *name_replay = runloop_st->name.replay;
struct string_list *dir_list = NULL;
unsigned min_idx = UINT_MAX;
const char *oldest_save = NULL;
/* Similar to command_event_set_replay_auto_index(),
* this will find the lowest numbered replay */
fill_pathname_basedir(tmp, runloop_st->name.replay,
sizeof(tmp));
fill_pathname_basedir(tmp, name_replay, sizeof(tmp));
if (!(dir_list = dir_list_new_special(tmp,
DIR_LIST_PLAIN, NULL, show_hidden_files)))
return;
fill_pathname_base(tmp, runloop_st->name.replay,
sizeof(tmp));
fill_pathname_base(tmp, name_replay, sizeof(tmp));
for (i = 0; i < dir_list->size; i++)
{

View file

@ -282,8 +282,11 @@ static bool gfx_thumbnail_get_path(
* on-demand thumbnail download support
* (an annoyance...) */
void gfx_thumbnail_request(
gfx_thumbnail_path_data_t *path_data, enum gfx_thumbnail_id thumbnail_id,
playlist_t *playlist, size_t idx, gfx_thumbnail_t *thumbnail,
gfx_thumbnail_path_data_t *path_data,
enum gfx_thumbnail_id thumbnail_id,
playlist_t *playlist,
size_t idx,
gfx_thumbnail_t *thumbnail,
unsigned gfx_thumbnail_upscale_threshold,
bool network_on_demand_thumbnails)
{
@ -332,7 +335,7 @@ void gfx_thumbnail_request(
{
enum playlist_thumbnail_name_flags curr_flag;
static char last_img_name[PATH_MAX_LENGTH] = {0};
settings_t *settings = config_get_ptr();
bool playlist_use_filename = config_get_ptr()->bools.playlist_use_filename;
if (!playlist)
goto end;
/* Only trigger a thumbnail download if image
@ -364,7 +367,7 @@ void gfx_thumbnail_request(
|| curr_flag & PLAYLIST_THUMBNAIL_FLAG_SHORT_NAME)
goto end;
/* Do not try to fetch full names here, if it is not explicitly wanted */
if ( !settings->bools.playlist_use_filename
if ( !playlist_use_filename
&& !playlist_thumbnail_match_with_filename(playlist)
&& curr_flag == PLAYLIST_THUMBNAIL_FLAG_INVALID)
playlist_update_thumbnail_name_flag(playlist, idx, PLAYLIST_THUMBNAIL_FLAG_FULL_NAME);

View file

@ -39,15 +39,14 @@
* Named_Titles, Named_Boxarts, Named_Logos) for specified thumbnail
* identifier (right, left) */
static const char *gfx_thumbnail_get_type(
settings_t *settings,
unsigned menu_left_thumbnails,
unsigned gfx_thumbnails,
gfx_thumbnail_path_data_t *path_data,
enum gfx_thumbnail_id thumbnail_id)
{
if (path_data)
{
unsigned type = 0;
unsigned menu_left_thumbnails = settings->uints.menu_left_thumbnails;
unsigned gfx_thumbnails = settings->uints.gfx_thumbnails;
switch (thumbnail_id)
{
case GFX_THUMBNAIL_RIGHT:
@ -166,7 +165,8 @@ gfx_thumbnail_path_data_t *gfx_thumbnail_path_init(void)
/* Returns true if specified thumbnail is enabled
* (i.e. if 'type' is not equal to MENU_ENUM_LABEL_VALUE_OFF) */
bool gfx_thumbnail_is_enabled(gfx_thumbnail_path_data_t *path_data, enum gfx_thumbnail_id thumbnail_id)
bool gfx_thumbnail_is_enabled(gfx_thumbnail_path_data_t *path_data,
enum gfx_thumbnail_id thumbnail_id)
{
if (path_data)
{
@ -559,10 +559,11 @@ bool gfx_thumbnail_update_path(
enum gfx_thumbnail_id thumbnail_id)
{
char content_dir[DIR_MAX_LENGTH];
settings_t *settings = config_get_ptr();
const char *system_name = NULL;
char *thumbnail_path = NULL;
const char *dir_thumbnails = NULL;
settings_t *settings = config_get_ptr();
const char *system_name = NULL;
char *thumbnail_path = NULL;
const char *dir_thumbnails = settings->paths.directory_thumbnails;
bool playlist_allow_non_png = settings->bools.playlist_allow_non_png;
/* Thumbnail extension order. The default (i.e. png) is always the first. */
#define MAX_SUPPORTED_THUMBNAIL_EXTENSIONS 5
const char* const SUPPORTED_THUMBNAIL_EXTENSIONS[] = { ".png", ".jpg", ".jpeg", ".bmp", ".tga", 0 };
@ -588,9 +589,6 @@ bool gfx_thumbnail_update_path(
content_dir[0] = '\0';
if (settings)
dir_thumbnails = settings->paths.directory_thumbnails;
/* Sundry error checking */
if (string_is_empty(dir_thumbnails))
return false;
@ -642,7 +640,9 @@ bool gfx_thumbnail_update_path(
else
{
char tmp_buf[DIR_MAX_LENGTH];
const char *type = gfx_thumbnail_get_type(settings,
const char *type = gfx_thumbnail_get_type(
settings->uints.menu_left_thumbnails,
settings->uints.gfx_thumbnails,
path_data, thumbnail_id);
int i;
bool thumbnail_found = false;
@ -664,7 +664,7 @@ bool gfx_thumbnail_update_path(
/* Try alternative file extensions in turn, if wanted */
for (i = 1;
settings->bools.playlist_allow_non_png
playlist_allow_non_png
&& !thumbnail_found
&& thumbnail_path[0]!='\0'
&& i < MAX_SUPPORTED_THUMBNAIL_EXTENSIONS; i++ )
@ -683,7 +683,7 @@ bool gfx_thumbnail_update_path(
}
for (i = 1;
settings->bools.playlist_allow_non_png
playlist_allow_non_png
&& !thumbnail_found
&& i < MAX_SUPPORTED_THUMBNAIL_EXTENSIONS ; i++ )
{
@ -701,7 +701,7 @@ bool gfx_thumbnail_update_path(
}
for( i = 1 ;
settings->bools.playlist_allow_non_png
playlist_allow_non_png
&& !thumbnail_found
&& i < MAX_SUPPORTED_THUMBNAIL_EXTENSIONS ; i++ )
{
@ -720,11 +720,11 @@ bool gfx_thumbnail_update_path(
/* Fetches current content directory.
* Returns true if content directory is valid. */
size_t gfx_thumbnail_get_content_dir(
gfx_thumbnail_path_data_t *path_data, char *s, size_t len)
size_t gfx_thumbnail_get_content_dir(gfx_thumbnail_path_data_t *path_data,
char *s, size_t len)
{
char *last_slash;
size_t _len;
char *last_slash;
char tmp_buf[NAME_MAX_LENGTH];
if (!path_data || string_is_empty(path_data->content_path))
return 0;

View file

@ -78,15 +78,15 @@ static void crt_store_temp_changes(videocrt_switch_t *p_switch)
static void crt_aspect_ratio_switch(
videocrt_switch_t *p_switch,
unsigned width, unsigned height,
float srm_width, float srm_height)
float srm_width, float srm_height,
unsigned video_aspect_ratio_idx)
{
settings_t *settings = config_get_ptr();
float fly_aspect = (float)width / (float)height;
p_switch->fly_aspect = fly_aspect;
video_driver_state_t *video_st = video_state_get_ptr();
/* We only force aspect ratio for the core provided setting */
if (settings->uints.video_aspect_ratio_idx != ASPECT_RATIO_CORE)
if (video_aspect_ratio_idx != ASPECT_RATIO_CORE)
{
RARCH_LOG("[CRT]: Aspect ratio forced by user: %f\n", video_st->aspect_ratio);
return;
@ -145,7 +145,9 @@ static void crt_switch_set_aspect(
scaled_width = roundf(patched_width * srm_xscale);
scaled_height = roundf(patched_height * srm_yscale);
crt_aspect_ratio_switch(p_switch, scaled_width, scaled_height, srm_width, srm_height);
crt_aspect_ratio_switch(p_switch, scaled_width, scaled_height,
srm_width, srm_height,
config_get_ptr()->uints.video_aspect_ratio_idx);
}
#if !defined(HAVE_VIDEOCORE)
@ -558,7 +560,8 @@ static void crt_rpi_switch(videocrt_switch_t *p_switch,
width = w;
crt_aspect_ratio_switch(p_switch, width,height,width,height);
crt_aspect_ratio_switch(p_switch, width, height, width, height,
config_get_ptr()->uints.video_aspect_ratio_idx);
/* following code is the mode line generator */
hfp = ((width * 0.044f) + (width / 112));

View file

@ -2533,14 +2533,13 @@ static bool video_shader_dir_init_shader_internal(
static void video_shader_dir_init_shader(
void *menu_driver_data_,
settings_t *settings,
const char *directory_video_shader,
const char *directory_menu_config,
bool show_hidden_files,
bool shader_remember_last_dir,
bool video_shader_remember_last_dir,
struct rarch_dir_shader_list *dir_list)
{
bool show_hidden_files = settings->bools.show_hidden_files;
bool shader_remember_last_dir = settings->bools.video_shader_remember_last_dir;
const char *directory_video_shader = settings->paths.directory_video_shader;
const char *directory_menu_config = settings->paths.directory_menu_config;
bool video_shader_remember_last_dir = settings->bools.video_shader_remember_last_dir;
const char *last_shader_preset_dir = NULL;
const char *last_shader_preset_file_name = NULL;
video_driver_state_t *video_st = video_state_get_ptr();
@ -2645,7 +2644,18 @@ void video_shader_dir_check_shader(
&& (last_shader_preset_type != RARCH_SHADER_NONE)
&& !string_is_equal(dir_list->directory, last_shader_preset_dir)))
{
video_shader_dir_init_shader(menu_ptr, settings, dir_list);
const char *directory_video_shader = settings->paths.directory_video_shader;
const char *directory_menu_config = settings->paths.directory_menu_config;
bool show_hidden_files = settings->bools.show_hidden_files;
bool shader_remember_last_dir = settings->bools.video_shader_remember_last_dir;
bool video_shader_remember_last_dir = settings->bools.video_shader_remember_last_dir;
video_shader_dir_init_shader(menu_ptr,
directory_video_shader,
directory_menu_config,
show_hidden_files,
shader_remember_last_dir,
video_shader_remember_last_dir,
dir_list);
dir_list_initialised = true;
}