Overlays/Input: Turn a bunch more functions static

This commit is contained in:
libretroadmin 2022-11-23 19:54:15 +01:00
parent 0cf1d86a3a
commit f062b74e26
6 changed files with 97 additions and 162 deletions

View File

@ -5333,7 +5333,7 @@ bool input_remapping_load_file(void *data, const char *path)
/* Whenever a remap file is loaded, subsequent /* Whenever a remap file is loaded, subsequent
* changes to global remap-related parameters * changes to global remap-related parameters
* must be reset at the next core deinitialisation */ * must be reset at the next core deinitialisation */
input_remapping_enable_global_config_restore(); input_state_get_ptr()->flags |= INP_FLAG_REMAPPING_CACHE_ACTIVE;
return true; return true;
} }

View File

@ -1411,7 +1411,7 @@ static bool inside_hitbox(const struct overlay_desc *desc, float x, float y)
(fabs(x - desc->x_hitbox) <= desc->range_x_mod) && (fabs(x - desc->x_hitbox) <= desc->range_x_mod) &&
(fabs(y - desc->y_hitbox) <= desc->range_y_mod); (fabs(y - desc->y_hitbox) <= desc->range_y_mod);
case OVERLAY_HITBOX_NONE: case OVERLAY_HITBOX_NONE:
return false; break;
} }
return false; return false;
} }
@ -1428,7 +1428,7 @@ static bool inside_hitbox(const struct overlay_desc *desc, float x, float y)
* @norm_x and @norm_y are the result of * @norm_x and @norm_y are the result of
* input_translate_coord_viewport(). * input_translate_coord_viewport().
**/ **/
void input_overlay_poll( static void input_overlay_poll(
input_overlay_t *ol, input_overlay_t *ol,
input_overlay_state_t *out, input_overlay_state_t *out,
unsigned ptr_idx, int16_t norm_x, int16_t norm_y, float touch_scale) unsigned ptr_idx, int16_t norm_x, int16_t norm_y, float touch_scale)
@ -1556,7 +1556,14 @@ static void input_overlay_update_desc_geom(input_overlay_t *ol,
desc->delta_y = 0.0f; desc->delta_y = 0.0f;
} }
void input_overlay_post_poll( /**
* input_overlay_post_poll:
*
* Called after all the input_overlay_poll() calls to
* update the range modifiers for pressed/unpressed regions
* and alpha mods.
**/
static void input_overlay_post_poll(
enum overlay_visibility *visibility, enum overlay_visibility *visibility,
input_overlay_t *ol, input_overlay_t *ol,
bool show_input, float opacity) bool show_input, float opacity)
@ -1614,43 +1621,14 @@ static void input_overlay_desc_init_hitbox(struct overlay_desc *desc)
} }
/** /**
* input_overlay_set_scale_factor: * input_overlay_scale:
* @ol : Overlay handle. * @ol : Overlay handle.
* @layout_desc : Scale + offset factors. * @layout : Scale + offset factors.
* *
* Scales the overlay and applies any aspect ratio/ * Scales the overlay and all its associated descriptors
* offset factors. * and applies any aspect ratio/offset factors.
**/ **/
void input_overlay_set_scale_factor( static void input_overlay_scale(struct overlay *ol,
input_overlay_t *ol, const overlay_layout_desc_t *layout_desc,
unsigned video_driver_width,
unsigned video_driver_height
)
{
size_t i;
float display_aspect_ratio = 0.0f;
if (!ol || !layout_desc)
return;
if (video_driver_height > 0)
display_aspect_ratio = (float)video_driver_width /
(float)video_driver_height;
for (i = 0; i < ol->size; i++)
{
struct overlay *current_overlay = &ol->overlays[i];
overlay_layout_t overlay_layout;
input_overlay_parse_layout(current_overlay,
layout_desc, display_aspect_ratio, &overlay_layout);
input_overlay_scale(current_overlay, &overlay_layout);
}
input_overlay_set_vertex_geom(ol);
}
void input_overlay_scale(struct overlay *ol,
const overlay_layout_t *layout) const overlay_layout_t *layout)
{ {
size_t i; size_t i;
@ -1702,7 +1680,7 @@ void input_overlay_scale(struct overlay *ol,
} }
} }
void input_overlay_parse_layout( static void input_overlay_parse_layout(
const struct overlay *ol, const struct overlay *ol,
const overlay_layout_desc_t *layout_desc, const overlay_layout_desc_t *layout_desc,
float display_aspect_ratio, float display_aspect_ratio,
@ -1722,15 +1700,14 @@ void input_overlay_parse_layout(
/* Sanity check - if scaling is blocked, /* Sanity check - if scaling is blocked,
* or aspect ratios are invalid, then we * or aspect ratios are invalid, then we
* can do nothing */ * can do nothing */
if ((ol->flags & OVERLAY_BLOCK_SCALE) || if ( (ol->flags & OVERLAY_BLOCK_SCALE)
(ol->aspect_ratio <= 0.0f) || || (ol->aspect_ratio <= 0.0f)
(display_aspect_ratio <= 0.0f)) || (display_aspect_ratio <= 0.0f))
return; return;
/* If display is wider than overlay, /* If display is wider than overlay,
* reduce width */ * reduce width */
if (display_aspect_ratio > if (display_aspect_ratio > ol->aspect_ratio)
ol->aspect_ratio)
{ {
overlay_layout->x_scale = ol->aspect_ratio / overlay_layout->x_scale = ol->aspect_ratio /
display_aspect_ratio; display_aspect_ratio;
@ -1777,9 +1754,8 @@ void input_overlay_parse_layout(
* > Landscape display orientations */ * > Landscape display orientations */
if (display_aspect_ratio > 1.0f) if (display_aspect_ratio > 1.0f)
{ {
float scale = layout_desc->scale_landscape; float scale = layout_desc->scale_landscape;
float aspect_adjust = layout_desc->aspect_adjust_landscape; float aspect_adjust = layout_desc->aspect_adjust_landscape;
/* Note: Y offsets have their sign inverted, /* Note: Y offsets have their sign inverted,
* since from a usability perspective positive * since from a usability perspective positive
* values should move the overlay upwards */ * values should move the overlay upwards */
@ -1827,7 +1803,7 @@ void input_overlay_parse_layout(
} }
} }
void input_overlay_set_vertex_geom(input_overlay_t *ol) static void input_overlay_set_vertex_geom(input_overlay_t *ol)
{ {
size_t i; size_t i;
@ -1848,6 +1824,42 @@ void input_overlay_set_vertex_geom(input_overlay_t *ol)
} }
} }
/**
* input_overlay_set_scale_factor:
* @ol : Overlay handle.
* @layout_desc : Scale + offset factors.
*
* Scales the overlay and applies any aspect ratio/
* offset factors.
**/
void input_overlay_set_scale_factor(
input_overlay_t *ol, const overlay_layout_desc_t *layout_desc,
unsigned video_driver_width,
unsigned video_driver_height
)
{
size_t i;
float display_aspect_ratio = 0.0f;
if (!ol || !layout_desc)
return;
if (video_driver_height > 0)
display_aspect_ratio = (float)video_driver_width /
(float)video_driver_height;
for (i = 0; i < ol->size; i++)
{
struct overlay *current_overlay = &ol->overlays[i];
overlay_layout_t overlay_layout;
input_overlay_parse_layout(current_overlay,
layout_desc, display_aspect_ratio, &overlay_layout);
input_overlay_scale(current_overlay, &overlay_layout);
}
input_overlay_set_vertex_geom(ol);
}
void input_overlay_load_active( void input_overlay_load_active(
enum overlay_visibility *visibility, enum overlay_visibility *visibility,
@ -1865,7 +1877,14 @@ void input_overlay_load_active(
(ol->active->flags & OVERLAY_FULL_SCREEN)); (ol->active->flags & OVERLAY_FULL_SCREEN));
} }
void input_overlay_poll_clear( /**
* input_overlay_poll_clear:
* @ol : overlay handle
*
* Call when there is nothing to poll. Allows overlay to
* clear certain state.
**/
static void input_overlay_poll_clear(
enum overlay_visibility *visibility, enum overlay_visibility *visibility,
input_overlay_t *ol, float opacity) input_overlay_t *ol, float opacity)
{ {
@ -1887,6 +1906,17 @@ void input_overlay_poll_clear(
} }
} }
static enum overlay_visibility input_overlay_get_visibility(
enum overlay_visibility *visibility,
int overlay_idx)
{
if (!visibility)
return OVERLAY_VISIBILITY_DEFAULT;
if ((overlay_idx < 0) || (overlay_idx >= MAX_VISIBILITY))
return OVERLAY_VISIBILITY_DEFAULT;
return visibility[overlay_idx];
}
void input_overlay_set_alpha_mod( void input_overlay_set_alpha_mod(
enum overlay_visibility *visibility, enum overlay_visibility *visibility,
input_overlay_t *ol, float mod) input_overlay_t *ol, float mod)
@ -1906,18 +1936,7 @@ void input_overlay_set_alpha_mod(
} }
} }
enum overlay_visibility input_overlay_get_visibility( static void input_overlay_free_overlays(input_overlay_t *ol)
enum overlay_visibility *visibility,
int overlay_idx)
{
if (!visibility)
return OVERLAY_VISIBILITY_DEFAULT;
if ((overlay_idx < 0) || (overlay_idx >= MAX_VISIBILITY))
return OVERLAY_VISIBILITY_DEFAULT;
return visibility[overlay_idx];
}
void input_overlay_free_overlays(input_overlay_t *ol)
{ {
size_t i; size_t i;
@ -1955,7 +1974,13 @@ void input_overlay_free_overlay(struct overlay *overlay)
image_texture_free(&overlay->image); image_texture_free(&overlay->image);
} }
void input_overlay_free(input_overlay_t *ol) /**
* input_overlay_free:
* @ol : Overlay handle.
*
* Frees overlay handle.
**/
static void input_overlay_free(input_overlay_t *ol)
{ {
if (!ol) if (!ol)
return; return;
@ -2036,7 +2061,12 @@ void input_overlay_auto_rotate_(
} }
} }
void input_poll_overlay( /*
* input_poll_overlay:
*
* Poll pressed buttons/keys on currently active overlay.
**/
static void input_poll_overlay(
bool keyboard_mapping_blocked, bool keyboard_mapping_blocked,
settings_t *settings, settings_t *settings,
void *ol_data, void *ol_data,
@ -5440,12 +5470,6 @@ void input_remapping_cache_global_config(void)
| INP_FLAG_OLD_LIBRETRO_DEVICE_SET; | INP_FLAG_OLD_LIBRETRO_DEVICE_SET;
} }
void input_remapping_enable_global_config_restore(void)
{
input_driver_state_t *input_st = &input_driver_st;
input_st->flags |= INP_FLAG_REMAPPING_CACHE_ACTIVE;
}
void input_remapping_restore_global_config(bool clear_cache) void input_remapping_restore_global_config(bool clear_cache)
{ {
unsigned i; unsigned i;

View File

@ -942,25 +942,8 @@ void input_driver_deinit_command(input_driver_state_t *input_st);
#endif #endif
#ifdef HAVE_OVERLAY #ifdef HAVE_OVERLAY
/*
* input_poll_overlay:
*
* Poll pressed buttons/keys on currently active overlay.
**/
void input_poll_overlay(
bool keyboard_mapping_blocked,
settings_t *settings,
void *ol_data,
enum overlay_visibility *overlay_visibility,
float opacity,
unsigned analog_dpad_mode,
float axis_threshold);
void input_overlay_deinit(void); void input_overlay_deinit(void);
void input_overlay_set_visibility(int overlay_idx,
enum overlay_visibility vis);
void input_overlay_init(void); void input_overlay_init(void);
#endif #endif

View File

@ -365,59 +365,10 @@ void input_overlay_auto_rotate_(
bool input_overlay_enable, bool input_overlay_enable,
input_overlay_t *ol); input_overlay_t *ol);
void input_overlay_poll(
input_overlay_t *ol,
input_overlay_state_t *out,
unsigned ptr_idx, int16_t norm_x, int16_t norm_y, float touch_scale);
/**
* input_overlay_poll_clear:
* @ol : overlay handle
*
* Call when there is nothing to poll. Allows overlay to
* clear certain state.
**/
void input_overlay_poll_clear(
enum overlay_visibility *visibility,
input_overlay_t *ol, float opacity);
/**
* input_overlay_post_poll:
*
* Called after all the input_overlay_poll() calls to
* update the range modifiers for pressed/unpressed regions
* and alpha mods.
**/
void input_overlay_post_poll(
enum overlay_visibility *visibility,
input_overlay_t *ol,
bool show_input, float opacity);
void input_overlay_load_active( void input_overlay_load_active(
enum overlay_visibility *visibility, enum overlay_visibility *visibility,
input_overlay_t *ol, float opacity); input_overlay_t *ol, float opacity);
void input_overlay_parse_layout(
const struct overlay *ol,
const overlay_layout_desc_t *layout_desc,
float display_aspect_ratio,
overlay_layout_t *overlay_layout);
void input_overlay_set_vertex_geom(input_overlay_t *ol);
void input_overlay_free_overlays(input_overlay_t *ol);
/**
* input_overlay_scale:
* @ol : Overlay handle.
* @layout : Scale + offset factors.
*
* Scales the overlay and all its associated descriptors
* and applies any aspect ratio/offset factors.
**/
void input_overlay_scale(struct overlay *ol,
const overlay_layout_t *layout);
/** /**
* input_overlay_set_scale_factor: * input_overlay_set_scale_factor:
* @ol : Overlay handle. * @ol : Overlay handle.
@ -443,10 +394,6 @@ void input_overlay_set_alpha_mod(
enum overlay_visibility *visibility, enum overlay_visibility *visibility,
input_overlay_t *ol, float mod); input_overlay_t *ol, float mod);
enum overlay_visibility input_overlay_get_visibility(
enum overlay_visibility *visibility,
int overlay_idx);
/** /**
* input_overlay_set_eightway_diagonal_sensitivity: * input_overlay_set_eightway_diagonal_sensitivity:
* *
@ -454,14 +401,6 @@ enum overlay_visibility input_overlay_get_visibility(
*/ */
void input_overlay_set_eightway_diagonal_sensitivity(void); void input_overlay_set_eightway_diagonal_sensitivity(void);
/**
* input_overlay_free:
* @ol : Overlay handle.
*
* Frees overlay handle.
**/
void input_overlay_free(input_overlay_t *ol);
RETRO_END_DECLS RETRO_END_DECLS
#endif #endif

View File

@ -53,25 +53,14 @@ bool input_remapping_save_file(const char *path);
*/ */
void input_remapping_cache_global_config(void); void input_remapping_cache_global_config(void);
/**
* Sets flags to enable the restoration of global configuration settings from
* the internal cache. Should be called independently from
* `input_remapping_cache_global_config()`.
* Must be called:
* - Whenever content is loaded
* - Whenever a remap file is loaded
*/
void input_remapping_enable_global_config_restore(void);
/** /**
* Restores any global configuration settings that were cached on the last core * Restores any global configuration settings that were cached on the last core
* init if `input_remapping_enable_global_config_restore()` has been called. * init if INP_FLAG_REMAPPING_CACHE_ACTIVE is set.
* Must be called on core deinitialization. * Must be called on core deinitialization.
* *
* @param clear_cache If true, function becomes a NOOP until the next time * @param clear_cache If true, function becomes a NOOP until the next time
* `input_remapping_cache_global_config()` and * `input_remapping_cache_global_config()` is called, and
* `input_remapping_enable_global_config_restore()` are * INP_FLAG_REMAPPING_CACHE_ACTIVE is set.
* called.
*/ */
void input_remapping_restore_global_config(bool clear_cache); void input_remapping_restore_global_config(bool clear_cache);

View File

@ -8472,7 +8472,7 @@ bool core_load_game(retro_ctx_load_content_info_t *load_info)
* core is actually running; register that any * core is actually running; register that any
* changes to global remap-related parameters * changes to global remap-related parameters
* should be reset once core is deinitialised */ * should be reset once core is deinitialised */
input_remapping_enable_global_config_restore(); input_state_get_ptr()->flags |= INP_FLAG_REMAPPING_CACHE_ACTIVE;
runloop_st->current_core.flags |= RETRO_CORE_FLAG_GAME_LOADED; runloop_st->current_core.flags |= RETRO_CORE_FLAG_GAME_LOADED;
return true; return true;
} }