Add support for RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK environment callback

This commit is contained in:
jdgleaver 2021-08-17 17:33:02 +01:00
parent 37901de858
commit 6b983991fe
3 changed files with 135 additions and 123 deletions

View File

@ -1712,6 +1712,16 @@ enum retro_mod
* the retro_core_options_v2_intl::local struct will be ignored. * the retro_core_options_v2_intl::local struct will be ignored.
*/ */
#define RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK 69
/* const struct retro_core_options_update_display_callback * --
* Allows a frontend to signal that a core must update
* the visibility of any dynamically hidden core options,
* and enables the frontend to detect visibility changes.
* Used by the frontend to update the menu display status
* of core options without requiring a call of retro_run().
* Must be called in retro_set_environment().
*/
/* VFS functionality */ /* VFS functionality */
/* File paths: /* File paths:
@ -3519,26 +3529,6 @@ struct retro_core_option_v2_definition
* in the retro_core_option_value array, otherwise will be * in the retro_core_option_value array, otherwise will be
* ignored */ * ignored */
const char *default_value; const char *default_value;
/* Specify the type this option represents so the frontend
* can present the user an alternative input method besides
* a limited list of possible values.
* > If set to "int", all values need to be integers
* and a frontend with support for numerical input will
* allow input of any number betwen the lowest and
* highest defined value.
* > If set to "float", all values need to be numbers
* and a frontend with support for numerical input will
* allow input of any number betwen the lowest and
* highest defined value.
* > If set to "bool", there should be only two values
* "true" and "false" (label can be anything)
* The frontend can choose to show a checkbox for it.
* > If NULL or set to "enum", the frontend will show
* the list of values and input will be limited to them.
* Future versions of the specs could allow this for more
* types or to be "TYPE:MORE:OPTIONS" */
const char *type_info;
}; };
struct retro_core_options_v2 struct retro_core_options_v2
@ -3571,6 +3561,25 @@ struct retro_core_options_v2_intl
struct retro_core_options_v2 *local; struct retro_core_options_v2 *local;
}; };
/* Used by the frontend to monitor changes in core option
* visibility. May be called each time any core option
* value is set via the frontend.
* - On each invocation, the core must update the visibility
* of any dynamically hidden options using the
* RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY environment
* callback.
* - On the first invocation, returns 'true' if the visibility
* of any core option has changed since the last call of
* retro_load_game() or retro_load_game_special().
* - On each subsequent invocation, returns 'true' if the
* visibility of any core option has changed since the last
* time the function was called. */
typedef bool (RETRO_CALLCONV *retro_core_options_update_display_callback_t)(void);
struct retro_core_options_update_display_callback
{
retro_core_options_update_display_callback_t callback;
};
struct retro_game_info struct retro_game_info
{ {
const char *path; /* Path to game, UTF-8 encoded. const char *path; /* Path to game, UTF-8 encoded.

View File

@ -649,6 +649,65 @@ static void deactivate_rumble(void)
/* Rumble support END */ /* Rumble support END */
/**********************/ /**********************/
#ifdef HAVE_NETWORK
/* Core options 'update display' callback */
static bool update_option_visibility(void)
{
struct retro_variable var = {0};
bool updated = false;
unsigned i;
/* If frontend supports core option categories,
* then gambatte_show_gb_link_settings is ignored
* and no options should be hidden */
if (libretro_supports_option_categories)
return false;
var.key = "gambatte_show_gb_link_settings";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
bool show_gb_link_settings_prev = show_gb_link_settings;
show_gb_link_settings = true;
if (strcmp(var.value, "disabled") == 0)
show_gb_link_settings = false;
if (show_gb_link_settings != show_gb_link_settings_prev)
{
struct retro_core_option_display option_display;
option_display.visible = show_gb_link_settings;
option_display.key = "gambatte_gb_link_mode";
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
option_display.key = "gambatte_gb_link_network_port";
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
for (i = 0; i < 12; i++)
{
char key[64] = {0};
/* Should be using std::to_string() here, but some
* compilers don't support it... */
sprintf(key, "%s%u",
"gambatte_gb_link_network_server_ip_", i + 1);
option_display.key = key;
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
}
updated = true;
}
}
return updated;
}
#endif
/* Fast forward override */ /* Fast forward override */
void set_fastforward_override(bool fastforward) void set_fastforward_override(bool fastforward)
{ {
@ -1028,6 +1087,7 @@ void retro_set_environment(retro_environment_t cb)
libretro_set_core_options(environ_cb, libretro_set_core_options(environ_cb,
&libretro_supports_option_categories); &libretro_supports_option_categories);
#ifdef HAVE_NETWORK
/* If frontend supports core option categories, /* If frontend supports core option categories,
* gambatte_show_gb_link_settings is unused and * gambatte_show_gb_link_settings is unused and
* should be hidden */ * should be hidden */
@ -1041,6 +1101,20 @@ void retro_set_environment(retro_environment_t cb)
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY,
&option_display); &option_display);
} }
/* If frontend does not support core option
* categories, core options may be shown/hidden
* at runtime. In this case, register 'update
* display' callback, so frontend can update
* core options menu without calling retro_run() */
else
{
struct retro_core_options_update_display_callback update_display_cb;
update_display_cb.callback = update_option_visibility;
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK,
&update_display_cb);
}
#endif
vfs_iface_info.required_interface_version = 1; vfs_iface_info.required_interface_version = 1;
vfs_iface_info.iface = NULL; vfs_iface_info.iface = NULL;
@ -1503,50 +1577,8 @@ static void check_variables(void)
break; break;
} }
/* Show/hide core options /* Show/hide core options */
* > If frontend supports core option categories, update_option_visibility();
* then gambatte_show_gb_link_settings is ignored
* and no options should be hidden */
var.key = "gambatte_show_gb_link_settings";
var.value = NULL;
if (!libretro_supports_option_categories &&
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
bool show_gb_link_settings_prev = show_gb_link_settings;
show_gb_link_settings = true;
if (strcmp(var.value, "disabled") == 0)
show_gb_link_settings = false;
if (show_gb_link_settings != show_gb_link_settings_prev)
{
struct retro_core_option_display option_display;
option_display.visible = show_gb_link_settings;
option_display.key = "gambatte_gb_link_mode";
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
option_display.key = "gambatte_gb_link_network_port";
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
for (i = 0; i < 12; i++)
{
char key[64] = {0};
/* Should be using std::to_string() here, but some
* compilers don't support it... */
sprintf(key, "%s%u",
"gambatte_gb_link_network_server_ip_", i + 1);
option_display.key = key;
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
}
}
}
#endif #endif

View File

@ -75,8 +75,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "custom", "Custom" }, { "custom", "Custom" },
{ NULL, NULL }, { NULL, NULL },
}, },
"disabled", "disabled"
NULL
}, },
{ {
"gambatte_gb_internal_palette", "gambatte_gb_internal_palette",
@ -141,8 +140,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "TWB64 - Pack 2", NULL }, { "TWB64 - Pack 2", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"GB - DMG", "GB - DMG"
NULL
}, },
{ {
"gambatte_gb_palette_twb64_1", "gambatte_gb_palette_twb64_1",
@ -254,8 +252,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "TWB64 100 - Stone Orange", NULL }, { "TWB64 100 - Stone Orange", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"TWB64 001 - Aqours Blue", "TWB64 001 - Aqours Blue"
NULL
}, },
{ {
"gambatte_gb_palette_twb64_2", "gambatte_gb_palette_twb64_2",
@ -367,8 +364,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "TWB64 200 - TOKYO SKYTREE CLOUDY BLUE", NULL }, { "TWB64 200 - TOKYO SKYTREE CLOUDY BLUE", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"TWB64 101 - 765PRO Pink", "TWB64 101 - 765PRO Pink"
NULL
}, },
{ {
"gambatte_gbc_color_correction", "gambatte_gbc_color_correction",
@ -383,8 +379,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "disabled", NULL }, { "disabled", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"GBC only", "GBC only"
NULL
}, },
{ {
"gambatte_gbc_color_correction_mode", "gambatte_gbc_color_correction_mode",
@ -398,8 +393,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "fast", "Fast" }, { "fast", "Fast" },
{ NULL, NULL }, { NULL, NULL },
}, },
"accurate", "accurate"
NULL
}, },
{ {
"gambatte_gbc_frontlight_position", "gambatte_gbc_frontlight_position",
@ -414,8 +408,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "below screen", "Below Screen" }, { "below screen", "Below Screen" },
{ NULL, NULL }, { NULL, NULL },
}, },
"central", "central"
NULL
}, },
{ {
"gambatte_dark_filter_level", "gambatte_dark_filter_level",
@ -438,8 +431,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "50", NULL }, { "50", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_hwmode", "gambatte_gb_hwmode",
@ -455,8 +447,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "GBA", NULL }, { "GBA", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"Auto", "Auto"
NULL
}, },
{ {
"gambatte_gb_bootloader", "gambatte_gb_bootloader",
@ -470,8 +461,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "disabled", NULL }, { "disabled", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"enabled", "enabled"
"bool"
}, },
{ {
"gambatte_mix_frames", "gambatte_mix_frames",
@ -487,8 +477,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "lcd_ghosting_fast", "LCD Ghosting (Fast)" }, { "lcd_ghosting_fast", "LCD Ghosting (Fast)" },
{ NULL, NULL }, { NULL, NULL },
}, },
"disabled", "disabled"
NULL
}, },
{ {
"gambatte_up_down_allowed", "gambatte_up_down_allowed",
@ -502,8 +491,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "enabled", NULL }, { "enabled", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"disabled", "disabled"
"bool"
}, },
{ {
"gambatte_turbo_period", "gambatte_turbo_period",
@ -632,8 +620,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "120", NULL }, { "120", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"4", "4"
"int"
}, },
{ {
"gambatte_rumble_level", "gambatte_rumble_level",
@ -656,15 +643,14 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "10", NULL }, { "10", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"10", "10"
"int"
}, },
#ifdef HAVE_NETWORK #ifdef HAVE_NETWORK
{ {
"gambatte_show_gb_link_settings", "gambatte_show_gb_link_settings",
"Show Game Boy Link Settings", "Show Game Boy Link Settings",
NULL, NULL,
"Enable configuration of networked 'Game Boy Link' (multiplayer) options. NOTE: Quick Menu must be toggled for this setting to take effect.", "Enable configuration of networked 'Game Boy Link' (multiplayer) options. NOTE: Quick Menu may need to be toggled for this setting to take effect.",
NULL, NULL,
NULL, NULL,
{ {
@ -672,8 +658,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "disabled", NULL }, { "disabled", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"disabled", "disabled"
"bool"
}, },
{ {
"gambatte_gb_link_mode", "gambatte_gb_link_mode",
@ -688,8 +673,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "Network Client", NULL }, { "Network Client", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"Not Connected", "Not Connected"
NULL
}, },
{ {
"gambatte_gb_link_network_port", "gambatte_gb_link_network_port",
@ -722,8 +706,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "56420", NULL }, { "56420", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"56400", "56400"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_1", "gambatte_gb_link_network_server_ip_1",
@ -745,8 +728,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_2", "gambatte_gb_link_network_server_ip_2",
@ -768,8 +750,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_3", "gambatte_gb_link_network_server_ip_3",
@ -791,8 +772,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_4", "gambatte_gb_link_network_server_ip_4",
@ -814,8 +794,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_5", "gambatte_gb_link_network_server_ip_5",
@ -837,8 +816,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_6", "gambatte_gb_link_network_server_ip_6",
@ -860,8 +838,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_7", "gambatte_gb_link_network_server_ip_7",
@ -883,8 +860,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_8", "gambatte_gb_link_network_server_ip_8",
@ -906,8 +882,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_9", "gambatte_gb_link_network_server_ip_9",
@ -929,8 +904,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_10", "gambatte_gb_link_network_server_ip_10",
@ -952,8 +926,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_11", "gambatte_gb_link_network_server_ip_11",
@ -975,8 +948,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
{ {
"gambatte_gb_link_network_server_ip_12", "gambatte_gb_link_network_server_ip_12",
@ -998,8 +970,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "9", NULL }, { "9", NULL },
{ NULL, NULL }, { NULL, NULL },
}, },
"0", "0"
"int"
}, },
#endif #endif
{ NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL }, { NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL },