Settings cleanups

This commit is contained in:
LibretroAdmin 2025-02-10 17:12:02 +01:00
parent ef7b9830db
commit 7a7c4df2a1
5 changed files with 69 additions and 99 deletions

View File

@ -1222,7 +1222,8 @@ static int16_t input_overlay_device_mouse_state(
return 0;
}
static int16_t input_overlay_lightgun_state(settings_t *settings,
static int16_t input_overlay_lightgun_state(
bool input_overlay_lightgun_allow_offscreen,
input_overlay_t *ol, unsigned id)
{
unsigned rarch_id;
@ -1235,19 +1236,19 @@ static int16_t input_overlay_lightgun_state(settings_t *settings,
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
ptr_st->device_mask |= (1 << RETRO_DEVICE_LIGHTGUN);
if ( ( ptr_st->ptr[0].x > -0x7fff && ptr_st->ptr[0].x != 0x7fff)
|| !settings->bools.input_overlay_lightgun_allow_offscreen)
|| !input_overlay_lightgun_allow_offscreen)
return ptr_st->ptr[0].x;
else
return -0x8000;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
if ( ( ptr_st->ptr[0].y > -0x7fff && ptr_st->ptr[0].y != 0x7fff)
|| !settings->bools.input_overlay_lightgun_allow_offscreen)
|| !input_overlay_lightgun_allow_offscreen)
return ptr_st->ptr[0].y;
else
return -0x8000;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
ptr_st->device_mask |= (1 << RETRO_DEVICE_LIGHTGUN);
return ( settings->bools.input_overlay_lightgun_allow_offscreen
return ( input_overlay_lightgun_allow_offscreen
&& input_driver_pointer_is_offscreen(ptr_st->ptr[0].x, ptr_st->ptr[0].y));
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
@ -1298,7 +1299,9 @@ static int16_t input_overlay_pointer_state(input_overlay_t *ol,
return 0;
}
static int16_t input_overlay_pointing_device_state(settings_t *settings,
static int16_t input_overlay_pointing_device_state(
int input_overlay_lightgun_port,
bool input_overlay_lightgun_allow_offscreen,
input_overlay_t *ol, unsigned port, unsigned device,
unsigned idx, unsigned id)
{
@ -1307,9 +1310,11 @@ static int16_t input_overlay_pointing_device_state(settings_t *settings,
case RETRO_DEVICE_MOUSE:
return input_overlay_device_mouse_state(ol, id);
case RETRO_DEVICE_LIGHTGUN:
if ( settings->ints.input_overlay_lightgun_port == -1
|| settings->ints.input_overlay_lightgun_port == (int)port)
return input_overlay_lightgun_state(settings, ol, id);
if ( input_overlay_lightgun_port == -1
|| input_overlay_lightgun_port == (int)port)
return input_overlay_lightgun_state(
input_overlay_lightgun_allow_offscreen,
ol, id);
break;
case RETRO_DEVICE_POINTER:
return input_overlay_pointer_state(ol,
@ -1419,10 +1424,8 @@ input_remote_t *input_driver_init_remote(
settings_t *settings,
unsigned num_active_users)
{
unsigned network_remote_base_port = settings->uints.network_remote_base_port;
return input_remote_new(
settings,
network_remote_base_port,
return input_remote_new(settings,
settings->uints.network_remote_base_port,
num_active_users);
}
#endif
@ -1784,7 +1787,9 @@ static int16_t input_state_device(
if ( (input_st->overlay_ptr)
&& (input_st->overlay_ptr->flags & INPUT_OVERLAY_ENABLE)
&& (settings->bools.input_overlay_pointer_enable))
res = input_overlay_pointing_device_state(settings,
res = input_overlay_pointing_device_state(
settings->ints.input_overlay_lightgun_port,
settings->bools.input_overlay_lightgun_allow_offscreen,
input_st->overlay_ptr, port, device, idx, id);
#endif
@ -1824,14 +1829,14 @@ static int16_t input_state_internal(
rarch_joypad_info_t joypad_info;
float input_analog_deadzone = settings->floats.input_analog_deadzone;
float input_analog_sensitivity = settings->floats.input_analog_sensitivity;
unsigned *input_remap_port_map = settings->uints.input_remap_port_map[port];
uint8_t max_users = settings->uints.input_max_users;
const input_device_driver_t *joypad = input_st->primary_joypad;
#ifdef HAVE_MFI
const input_device_driver_t *sec_joypad = input_st->secondary_joypad;
#else
const input_device_driver_t *sec_joypad = NULL;
#endif
unsigned *input_remap_port_map = settings->uints.input_remap_port_map[port];
uint8_t max_users = settings->uints.input_max_users;
uint8_t mapped_port = 0;
int16_t result = 0;
#ifdef HAVE_MENU
@ -3183,18 +3188,15 @@ static void input_overlay_get_mouse_scale(settings_t *settings,
{
video_driver_state_t *video_st = video_state_get_ptr();
struct retro_game_geometry *geom = &video_st->av_info.geometry;
float swipe_thres;
float adj_x, adj_y;
float display_aspect, core_aspect;
float speed;
if (geom->base_height)
{
speed = settings->floats.input_overlay_mouse_speed;
swipe_thres =
float adj_x, adj_y;
float speed = settings->floats.input_overlay_mouse_speed;
float swipe_thres =
655.35f * settings->floats.input_overlay_mouse_swipe_threshold;
display_aspect = (float)video_st->width / video_st->height;
core_aspect = (float)geom->base_width / geom->base_height;
float display_aspect = (float)video_st->width / video_st->height;
float core_aspect = (float)geom->base_width / geom->base_height;
if (display_aspect > core_aspect)
{
@ -4449,8 +4451,7 @@ void input_mapper_reset(void *data)
bool input_set_sensor_state(unsigned port,
enum retro_sensor_action action, unsigned rate)
{
settings_t *settings = config_get_ptr();
bool input_sensors_enable = settings->bools.input_sensors_enable;
bool input_sensors_enable = config_get_ptr()->bools.input_sensors_enable;
return input_driver_set_sensor(
port, input_sensors_enable, action, rate);
}
@ -4499,9 +4500,7 @@ void joypad_driver_reinit(void *data, const char *joypad_driver_name)
**/
float input_get_sensor_state(unsigned port, unsigned id)
{
settings_t *settings = config_get_ptr();
bool input_sensors_enable = settings->bools.input_sensors_enable;
bool input_sensors_enable = config_get_ptr()->bools.input_sensors_enable;
return input_driver_get_sensor(port, input_sensors_enable, id);
}
@ -4544,17 +4543,14 @@ bool input_set_rumble_state(unsigned port,
**/
bool input_set_rumble_gain(unsigned gain)
{
settings_t *settings = config_get_ptr();
if (input_driver_set_rumble_gain(
gain, settings->uints.input_max_users))
return true;
return false;
return (input_driver_set_rumble_gain(
gain, config_get_ptr()->uints.input_max_users));
}
uint64_t input_driver_get_capabilities(void)
{
if ( !input_driver_st.current_driver ||
!input_driver_st.current_driver->get_capabilities)
if ( !input_driver_st.current_driver
|| !input_driver_st.current_driver->get_capabilities)
return 0;
return input_driver_st.current_driver->get_capabilities(input_driver_st.current_data);
}
@ -4585,7 +4581,6 @@ bool input_key_pressed(int key, bool keyboard_pressed)
)
)
{
settings_t *settings = config_get_ptr();
const input_device_driver_t
*joypad = (const input_device_driver_t*)
input_driver_st.primary_joypad;
@ -4594,7 +4589,7 @@ bool input_key_pressed(int key, bool keyboard_pressed)
const uint64_t autobind_joykey = input_autoconf_binds[0][key].joykey;
const uint64_t autobind_joyaxis= input_autoconf_binds[0][key].joyaxis;
uint16_t port = 0;
float axis_threshold = settings->floats.input_axis_threshold;
float axis_threshold = config_get_ptr()->floats.input_axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint64_t joyaxis = (bind_joyaxis != AXIS_NONE)
@ -4656,8 +4651,8 @@ bool video_driver_init_input(
/* This should never really happen as tmp (driver.input) is always
* found before this in find_driver_input(), or we have aborted
* in a similar fashion anyways. */
if ( !input_driver_st.current_driver ||
!(new_data = input_driver_init_wrap(
if ( !input_driver_st.current_driver
|| !(new_data = input_driver_init_wrap(
input_driver_st.current_driver,
settings->arrays.input_joypad_driver)))
{
@ -4722,7 +4717,6 @@ void input_config_reset(void)
void input_config_set_device(unsigned port, unsigned id)
{
settings_t *settings = config_get_ptr();
if (settings && (port < MAX_USERS))
configuration_set_uint(settings,
settings->uints.input_libretro_device[port], id);
@ -4731,10 +4725,8 @@ void input_config_set_device(unsigned port, unsigned id)
unsigned input_config_get_device(unsigned port)
{
settings_t *settings = config_get_ptr();
if (settings && (port < MAX_USERS))
return settings->uints.input_libretro_device[port];
return RETRO_DEVICE_NONE;
}
@ -4752,10 +4744,8 @@ const struct retro_keybind *input_config_get_bind_auto(
unsigned *input_config_get_device_ptr(unsigned port)
{
settings_t *settings = config_get_ptr();
if (settings && (port < MAX_USERS))
return &settings->uints.input_libretro_device[port];
return NULL;
}
@ -5272,11 +5262,11 @@ static void input_overlay_swap_with_cached(void)
void input_overlay_unload(void)
{
settings_t *settings = config_get_ptr();
bool input_overlay_enable = config_get_ptr()->bools.input_overlay_enable;
runloop_state_t *runloop_st = runloop_state_get_ptr();
/* Free if overlays disabled or initing/deiniting core */
if ( !settings->bools.input_overlay_enable
if ( !input_overlay_enable
|| !(runloop_st->flags & RUNLOOP_FLAG_IS_INITED)
|| (runloop_st->flags & RUNLOOP_FLAG_SHUTDOWN_INITIATED))
input_overlay_deinit();
@ -5325,7 +5315,6 @@ static bool input_overlay_want_hidden(void)
void input_overlay_check_mouse_cursor(void)
{
settings_t *settings = config_get_ptr();
input_driver_state_t *input_st = &input_driver_st;
video_driver_state_t *video_st = video_state_get_ptr();
input_overlay_t *ol = input_st->overlay_ptr;
@ -5334,7 +5323,7 @@ void input_overlay_check_mouse_cursor(void)
&& video_st->poke
&& video_st->poke->show_mouse)
{
if (settings->bools.input_overlay_show_mouse_cursor)
if (config_get_ptr()->bools.input_overlay_show_mouse_cursor)
video_st->poke->show_mouse(video_st->data, true);
else if (input_st->flags & INP_FLAG_GRAB_MOUSE_STATE)
video_st->poke->show_mouse(video_st->data, false);
@ -5345,15 +5334,14 @@ void input_overlay_check_mouse_cursor(void)
static void input_overlay_loaded(retro_task_t *task,
void *task_data, void *user_data, const char *err)
{
settings_t *settings = config_get_ptr();
#ifdef HAVE_MENU
uint16_t overlay_types;
#endif
overlay_task_data_t *data = (overlay_task_data_t*)task_data;
input_overlay_t *ol = NULL;
input_driver_state_t *input_st = &input_driver_st;
bool enable_overlay = !input_overlay_want_hidden()
&& settings->bools.input_overlay_enable;
#ifdef HAVE_MENU
uint16_t overlay_types;
#endif
&& config_get_ptr()->bools.input_overlay_enable;
if (err)
return;
@ -5609,7 +5597,7 @@ static void input_keys_pressed(
const input_device_driver_t *joypad,
const input_device_driver_t *sec_joypad,
rarch_joypad_info_t *joypad_info,
settings_t *settings)
bool input_hotkey_device_merge)
{
unsigned i;
input_driver_state_t *input_st = &input_driver_st;
@ -5625,7 +5613,7 @@ static void input_keys_pressed(
if (!binds)
return;
if ( settings->bools.input_hotkey_device_merge
if ( input_hotkey_device_merge
&& (libretro_hotkey_set || keyboard_hotkey_set))
libretro_hotkey_set = keyboard_hotkey_set = true;
@ -6170,15 +6158,14 @@ void bsv_movie_read_next_events(bsv_movie_t *handle)
void bsv_movie_next_frame(input_driver_state_t *input_st)
{
settings_t *settings = config_get_ptr();
unsigned checkpoint_interval = settings->uints.replay_checkpoint_interval;
unsigned checkpoint_interval = config_get_ptr()->uints.replay_checkpoint_interval;
/* if bsv_movie_state_next_handle is not null, deinit and set
bsv_movie_state_handle to bsv_movie_state_next_handle and clear
next_handle */
bsv_movie_t *handle = input_st->bsv_movie_state_handle;
if (input_st->bsv_movie_state_next_handle)
{
if(handle)
if (handle)
bsv_movie_deinit(input_st);
handle = input_st->bsv_movie_state_next_handle;
input_st->bsv_movie_state_handle = handle;
@ -6391,6 +6378,7 @@ void input_driver_poll(void)
*sec_joypad = NULL;
#endif
bool input_remap_binds_enable = settings->bools.input_remap_binds_enable;
float input_axis_threshold = settings->floats.input_axis_threshold;
uint8_t max_users = (uint8_t)settings->uints.input_max_users;
if (joypad && joypad->poll)
@ -6415,7 +6403,7 @@ void input_driver_poll(void)
* when mapping analog stick to dpad input. */
for (i = 0; i < max_users; i++)
{
joypad_info[i].axis_threshold = settings->floats.input_axis_threshold;
joypad_info[i].axis_threshold = input_axis_threshold;
joypad_info[i].joy_idx = settings->uints.input_joypad_index[i];
joypad_info[i].auto_binds = input_autoconf_binds[joypad_info[i].joy_idx];
@ -6889,14 +6877,10 @@ int16_t input_driver_state_wrapper(unsigned port, unsigned device,
#endif
#ifdef HAVE_GAME_AI
if(settings->bools.game_ai_override_p1 && port == 0)
{
if (settings->bools.game_ai_override_p1 && port == 0)
result |= game_ai_input(port, device, idx, id, result);
}
if(settings->bools.game_ai_override_p2 && port == 1)
{
if (settings->bools.game_ai_override_p2 && port == 1)
result |= game_ai_input(port, device, idx, id, result);
}
#endif
return result;
@ -6912,10 +6896,7 @@ void *hid_driver_get_data(void)
* HID driver; the memory will have already been freed, so we need to
* reset the pointer.
*/
void hid_driver_reset_data(void)
{
input_driver_st.hid_data = NULL;
}
void hid_driver_reset_data(void) { input_driver_st.hid_data = NULL; }
/**
* config_get_hid_driver_options:
@ -7211,7 +7192,7 @@ void input_driver_collect_system_input(input_driver_state_t *input_st,
joypad,
sec_joypad,
&joypad_info,
settings);
settings->bools.input_hotkey_device_merge);
#ifdef HAVE_MENU
if (menu_is_alive)

View File

@ -445,14 +445,15 @@ static void reallocate_port_if_needed(unsigned detected_port, int vendor_id,
if (settings->uints.input_device_reservation_type[player] != INPUT_DEVICE_RESERVATION_NONE)
no_reservation_at_all = false;
}
if (first_free_player_slot > settings->uints.input_max_users) {
if (first_free_player_slot > settings->uints.input_max_users)
{
RARCH_ERR( "[Autoconf]: No free and unreserved player slots found for adding new device"
" \"%s\"! Detected port %d, max_users: %d, first free slot %d\n",
device_name, detected_port,
settings->uints.input_max_users,
first_free_player_slot+1);
" \"%s\"! Detected port %d, max_users: %d, first free slot %d\n",
device_name, detected_port,
settings->uints.input_max_users,
first_free_player_slot+1);
RARCH_WARN("[Autoconf]: Leaving detected player slot in place: %d\n",
prev_assigned_player_slots[detected_port]);
prev_assigned_player_slots[detected_port]);
return;
}

View File

@ -1081,19 +1081,12 @@ static bool task_database_check_serial_and_crc(
database_state_handle_t *db_state)
{
#ifdef RARCH_INTERNAL
settings_t *settings = config_get_ptr();
#endif
const char *db_path =
database_info_get_current_name(db_state);
#ifdef RARCH_INTERNAL
if (!settings->bools.scan_serial_and_crc)
if (!config_get_ptr()->bools.scan_serial_and_crc)
return false;
#endif
/* the PSP shares serials for disc/download content */
return string_starts_with(
path_basename_nocompression(db_path),
path_basename_nocompression(database_info_get_current_name(db_state)),
"Sony - PlayStation Portable");
}

View File

@ -727,9 +727,6 @@ static bool apply_patch_content(uint8_t **buf,
ssize_t *size, const char *patch_desc, const char *patch_path,
patch_func_t func, void *patch_data, int64_t patch_size)
{
settings_t *settings = config_get_ptr();
bool show_notification = settings ?
settings->bools.notification_show_patch_applied : false;
enum patch_error err = PATCH_UNKNOWN;
ssize_t ret_size = *size;
uint8_t *ret_buf = *buf;
@ -747,7 +744,7 @@ static bool apply_patch_content(uint8_t **buf,
*size = target_size;
/* Show an OSD message */
if (show_notification)
if (config_get_ptr()->bools.notification_show_patch_applied)
{
char msg[128];
const char *patch_filename = path_basename_nocompression(patch_path);

View File

@ -181,9 +181,9 @@ bool content_undo_load_state(void)
* the backing up of it and
* its flushing could all be in their
* own functions... */
if ( config_get_ptr()->bools.block_sram_overwrite
&& savefile_list
&& savefile_list->size)
if ( savefile_list
&& savefile_list->size
&& config_get_ptr()->bools.block_sram_overwrite)
{
RARCH_LOG("[SRAM]: %s.\n",
msg_hash_to_str(MSG_BLOCKING_SRAM_OVERWRITE));
@ -994,8 +994,6 @@ static void content_load_state_cb(retro_task_t *task,
unsigned num_blocks = 0;
void *buf = load_data->data;
struct sram_block *blocks = NULL;
settings_t *settings = config_get_ptr();
bool block_sram_overwrite = settings->bools.block_sram_overwrite;
struct string_list *savefile_list = (struct string_list*)savefile_ptr_get();
#ifdef HAVE_CHEEVOS
@ -1036,7 +1034,10 @@ static void content_load_state_cb(retro_task_t *task,
return;
}
if (block_sram_overwrite && savefile_list && savefile_list->size)
if ( savefile_list
&& savefile_list->size
&& config_get_ptr()->bools.block_sram_overwrite
)
{
RARCH_LOG("[SRAM]: %s.\n",
msg_hash_to_str(MSG_BLOCKING_SRAM_OVERWRITE));
@ -1136,11 +1137,8 @@ static void save_state_cb(retro_task_t *task,
save_task_state_t *state = (save_task_state_t*)task_data;
#ifdef HAVE_SCREENSHOTS
char *path = strdup(state->path);
settings_t *settings = config_get_ptr();
const char *dir_screenshot = settings->paths.directory_screenshot;
if (state->flags & SAVE_TASK_FLAG_THUMBNAIL_ENABLE)
take_screenshot(dir_screenshot,
take_screenshot(config_get_ptr()->paths.directory_screenshot,
path, true,
state->flags & SAVE_TASK_FLAG_HAS_VALID_FB, false, true);
free(path);