Reworked per-core options interface in libretro. It is now far more flexible and less obscure than before. I have removed the old environment_variables config which were sort of used for this before. It was awkward and hard to use.
Setting: core_options_path = “/path/to/config.cfg”
This will be written to by RetroArch.
RETRO_ENVIRONMENT_GET_VARIABLE/SET_VARIABLES have changed somewhat in behavior, so they have received new #define values to avoid potential ABI clashes. The old values are removed from the API. They weren’t used ever to my knowledge, so it’s not a big deal. Added GET_VARIABLE_UPDATE call. This allows you to check if any options have changed since last call to GET_VARIABLE. This is an optimization so that GET_VARIABLE doesn’t have to be called a zillion times over every frame.
libretro-test/ has tests for this now.
libretro cores expose their options as such:
void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;
static const struct retro_variable vars[] = {
{ "test_opt0", "Test option #0; false|true" },
{ "test_opt1", "Test option #1; 0" },
{ "test_opt2", "Test option #2; 0|1|foo|3" },
{ NULL, NULL },
};
cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
}
This call should come as early as possible so the frontend can expose options as early as possible.
Per-frame querying:
static void check_variables(void)
{
struct retro_variable var = {0};
var.key = "test_opt0";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
fprintf(stderr, "Key -> Val: %s -> %s.
", var.key, var.value);
var.key = "test_opt1";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
fprintf(stderr, "Key -> Val: %s -> %s.
", var.key, var.value);
var.key = "test_opt2";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
fprintf(stderr, "Key -> Val: %s -> %s.
", var.key, var.value);
}
// In retro_run() or something.
bool updated = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
check_variables();
After running once, defaults will be set in core_options_path as such:
test_opt0 = "false"
test_opt1 = "0"
test_opt2 = "0"
The structure is such that e.g. RGUI will be able to expose this nicely in a GUI and have it be saved to disk in-between emulator uses, transparently to the user.