Add ability to manually set default core option values when using the new v1 core options interface

This commit is contained in:
jdgleaver 2019-07-12 18:20:19 +01:00
parent 4f3adb8d2c
commit 0476901ca5
3 changed files with 44 additions and 6 deletions

View File

@ -1142,7 +1142,7 @@ enum retro_mod
* options must not change from the number in the initial call. * options must not change from the number in the initial call.
* *
* 'data' points to an array of retro_core_option_definition structs * 'data' points to an array of retro_core_option_definition structs
* terminated by a { NULL, NULL, NULL, {{0}} } element. * terminated by a { NULL, NULL, NULL, {{0}}, NULL } element.
* retro_core_option_definition::key should be namespaced to not collide * retro_core_option_definition::key should be namespaced to not collide
* with other implementations' keys. e.g. A core called * with other implementations' keys. e.g. A core called
* 'foo' should use keys named as 'foo_option'. * 'foo' should use keys named as 'foo_option'.
@ -1151,13 +1151,18 @@ enum retro_mod
* retro_core_option_definition::info should contain any additional human * retro_core_option_definition::info should contain any additional human
* readable information text that a typical user may need to * readable information text that a typical user may need to
* understand the functionality of the option. * understand the functionality of the option.
* retro_variable::values is an array of retro_core_option_value * retro_core_option_definition::values is an array of retro_core_option_value
* structs terminated by a { NULL, NULL } element. * structs terminated by a { NULL, NULL } element.
* > retro_variable::values[index].value is an expected option * > retro_core_option_definition::values[index].value is an expected option
* value. * value.
* > retro_variable::values[index].label is a human readable * > retro_core_option_definition::values[index].label is a human readable
* label used when displaying the value on screen. If NULL, * label used when displaying the value on screen. If NULL,
* the value itself is used. * the value itself is used.
* retro_core_option_definition::default_value is the default core option
* setting. It must match one of the expected option values in the
* retro_core_option_definition::values array. If it does not, or the
* default value is NULL, the first entry in the
* retro_core_option_definition::values array is treated as the default.
* *
* The number of possible options should be very limited, * The number of possible options should be very limited,
* and must be less than RETRO_NUM_CORE_OPTION_VALUES_MAX. * and must be less than RETRO_NUM_CORE_OPTION_VALUES_MAX.
@ -1176,7 +1181,8 @@ enum retro_mod
* { "true", NULL }, * { "true", NULL },
* { "unstable", "Turbo (Unstable)" }, * { "unstable", "Turbo (Unstable)" },
* { NULL, NULL }, * { NULL, NULL },
* } * },
* "false"
* } * }
* *
* Only strings are operated on. The possible values will * Only strings are operated on. The possible values will
@ -1216,6 +1222,10 @@ enum retro_mod
* retro_core_options_intl::us is used by the frontend). Any items * retro_core_options_intl::us is used by the frontend). Any items
* missing from this array will be read from retro_core_options_intl::us * missing from this array will be read from retro_core_options_intl::us
* instead. * instead.
*
* NOTE: Default core option values are always taken from the
* retro_core_options_intl::us array. Any default values in
* retro_core_options_intl::local array will be ignored.
*/ */
#define RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY 55 #define RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY 55
@ -2521,6 +2531,11 @@ struct retro_core_option_definition
/* Array of retro_core_option_value structs, terminated by NULL */ /* Array of retro_core_option_value structs, terminated by NULL */
struct retro_core_option_value values[RETRO_NUM_CORE_OPTION_VALUES_MAX]; struct retro_core_option_value values[RETRO_NUM_CORE_OPTION_VALUES_MAX];
/* Default core option value. Must match one of the values
* in the retro_core_option_value array, otherwise will be
* ignored */
const char *default_value;
}; };
struct retro_core_options_intl struct retro_core_options_intl

View File

@ -34,6 +34,7 @@ struct core_option
char *key; char *key;
struct string_list *vals; struct string_list *vals;
struct string_list *val_labels; struct string_list *val_labels;
size_t default_index;
size_t index; size_t index;
bool visible; bool visible;
}; };

View File

@ -1725,6 +1725,11 @@ static bool core_option_manager_parse_variable(
if (!option->val_labels) if (!option->val_labels)
goto error; goto error;
/* Legacy core option interface always uses first
* defined value as the default */
option->default_index = 0;
option->index = 0;
if (config_get_string(opt->conf, option->key, &config_val)) if (config_get_string(opt->conf, option->key, &config_val))
{ {
size_t i; size_t i;
@ -1793,6 +1798,10 @@ static bool core_option_manager_parse_option(
if (!option->vals || !option->val_labels) if (!option->vals || !option->val_labels)
return false; return false;
/* Initialse default value */
option->default_index = 0;
option->index = 0;
/* Extract value/label pairs */ /* Extract value/label pairs */
for (i = 0; i < num_vals; i++) for (i = 0; i < num_vals; i++)
{ {
@ -1804,6 +1813,16 @@ static bool core_option_manager_parse_option(
string_list_append(option->val_labels, values[i].label, attr); string_list_append(option->val_labels, values[i].label, attr);
else else
string_list_append(option->val_labels, values[i].value, attr); string_list_append(option->val_labels, values[i].value, attr);
/* Check whether this value is the default setting */
if (!string_is_empty(option_def->default_value))
{
if (string_is_equal(option_def->default_value, values[i].value))
{
option->default_index = i;
option->index = i;
}
}
} }
/* Set current config value */ /* Set current config value */
@ -2189,7 +2208,7 @@ void core_option_manager_set_default(core_option_manager_t *opt, size_t idx)
if (idx >= opt->size) if (idx >= opt->size)
return; return;
opt->opts[idx].index = 0; opt->opts[idx].index = opt->opts[idx].default_index;
opt->updated = true; opt->updated = true;
} }
@ -2246,6 +2265,9 @@ static struct retro_core_option_definition *core_option_manager_get_definitions(
/* Key is always taken from us english defs */ /* Key is always taken from us english defs */
option_defs[i].key = key; option_defs[i].key = key;
/* Default value is always taken from us english defs */
option_defs[i].default_value = option_defs_us[i].default_value;
/* Try to find corresponding entry in local defs array */ /* Try to find corresponding entry in local defs array */
if (option_defs_local) if (option_defs_local)
{ {