mirror of
https://github.com/libretro/RetroArch
synced 2025-03-02 19:13:34 +00:00
Move core option manager into retroarch.c
This commit is contained in:
parent
11ad4eb227
commit
9f4e8688f3
@ -223,7 +223,6 @@ OBJ += frontend/frontend.o \
|
||||
input/input_keymaps.o \
|
||||
input/input_remapping.o \
|
||||
$(LIBRETRO_COMM_DIR)/queues/fifo_queue.o \
|
||||
managers/core_option_manager.o \
|
||||
$(LIBRETRO_COMM_DIR)/compat/compat_fnmatch.o \
|
||||
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.o \
|
||||
managers/cheat_manager.o \
|
||||
|
@ -141,7 +141,6 @@ CONFIG FILE
|
||||
|
||||
#include "../libretro-common/file/config_file.c"
|
||||
#include "../libretro-common/file/config_file_userdata.c"
|
||||
#include "../managers/core_option_manager.c"
|
||||
|
||||
/*============================================================
|
||||
RUNTIME FILE
|
||||
|
@ -1,405 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <file/config_file.h>
|
||||
#include <lists/string_list.h>
|
||||
#include <compat/posix_string.h>
|
||||
#include <compat/strl.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <string/stdstring.h>
|
||||
|
||||
#include <libretro.h>
|
||||
|
||||
#include "core_option_manager.h"
|
||||
|
||||
#include "../verbosity.h"
|
||||
|
||||
#ifdef HAVE_RUNAHEAD
|
||||
#include "../runahead/secondary_core.h"
|
||||
#endif
|
||||
|
||||
static bool core_option_manager_parse_variable(
|
||||
core_option_manager_t *opt, size_t idx,
|
||||
const struct retro_variable *var)
|
||||
{
|
||||
const char *val_start = NULL;
|
||||
char *value = NULL;
|
||||
char *desc_end = NULL;
|
||||
char *config_val = NULL;
|
||||
struct core_option *option = (struct core_option*)&opt->opts[idx];
|
||||
|
||||
if (!string_is_empty(var->key))
|
||||
option->key = strdup(var->key);
|
||||
if (!string_is_empty(var->value))
|
||||
value = strdup(var->value);
|
||||
|
||||
if (!string_is_empty(value))
|
||||
desc_end = strstr(value, "; ");
|
||||
|
||||
if (!desc_end)
|
||||
goto error;
|
||||
|
||||
*desc_end = '\0';
|
||||
|
||||
if (!string_is_empty(value))
|
||||
option->desc = strdup(value);
|
||||
|
||||
val_start = desc_end + 2;
|
||||
option->vals = string_split(val_start, "|");
|
||||
|
||||
if (!option->vals)
|
||||
goto error;
|
||||
|
||||
if (config_get_string(opt->conf, option->key, &config_val))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < option->vals->size; i++)
|
||||
{
|
||||
if (string_is_equal(option->vals->elems[i].data, config_val))
|
||||
{
|
||||
option->index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(config_val);
|
||||
}
|
||||
|
||||
free(value);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
free(value);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_free:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Frees core option manager handle.
|
||||
**/
|
||||
void core_option_manager_free(core_option_manager_t *opt)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
if (opt->opts[i].desc)
|
||||
free(opt->opts[i].desc);
|
||||
if (opt->opts[i].key)
|
||||
free(opt->opts[i].key);
|
||||
|
||||
if (opt->opts[i].vals)
|
||||
string_list_free(opt->opts[i].vals);
|
||||
|
||||
opt->opts[i].desc = NULL;
|
||||
opt->opts[i].key = NULL;
|
||||
opt->opts[i].vals = NULL;
|
||||
}
|
||||
|
||||
if (opt->conf)
|
||||
config_file_free(opt->conf);
|
||||
free(opt->opts);
|
||||
free(opt);
|
||||
}
|
||||
|
||||
void core_option_manager_get(core_option_manager_t *opt, void *data)
|
||||
{
|
||||
size_t i;
|
||||
struct retro_variable *var = (struct retro_variable*)data;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_RUNAHEAD
|
||||
if (opt->updated)
|
||||
{
|
||||
secondary_core_set_variable_update();
|
||||
}
|
||||
#endif
|
||||
|
||||
opt->updated = false;
|
||||
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
if (string_is_empty(opt->opts[i].key))
|
||||
continue;
|
||||
|
||||
if (string_is_equal(opt->opts[i].key, var->key))
|
||||
{
|
||||
var->value = core_option_manager_get_val(opt, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var->value = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_new:
|
||||
* @conf_path : Filesystem path to write core option config file to.
|
||||
* @vars : Pointer to variable array handle.
|
||||
*
|
||||
* Creates and initializes a core manager handle.
|
||||
*
|
||||
* Returns: handle to new core manager handle, otherwise NULL.
|
||||
**/
|
||||
core_option_manager_t *core_option_manager_new(const char *conf_path,
|
||||
const void *data)
|
||||
{
|
||||
const struct retro_variable *var;
|
||||
const struct retro_variable *vars = (const struct retro_variable*)data;
|
||||
size_t size = 0;
|
||||
core_option_manager_t *opt = (core_option_manager_t*)
|
||||
calloc(1, sizeof(*opt));
|
||||
|
||||
if (!opt)
|
||||
return NULL;
|
||||
|
||||
if (!string_is_empty(conf_path))
|
||||
opt->conf = config_file_new(conf_path);
|
||||
if (!opt->conf)
|
||||
opt->conf = config_file_new(NULL);
|
||||
|
||||
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));
|
||||
|
||||
if (!opt->conf)
|
||||
goto error;
|
||||
|
||||
for (var = vars; var->key && var->value; var++)
|
||||
size++;
|
||||
|
||||
if (size == 0)
|
||||
goto error;
|
||||
|
||||
opt->opts = (struct core_option*)calloc(size, sizeof(*opt->opts));
|
||||
if (!opt->opts)
|
||||
goto error;
|
||||
|
||||
opt->size = size;
|
||||
size = 0;
|
||||
|
||||
for (var = vars; var->key && var->value; size++, var++)
|
||||
{
|
||||
if (!core_option_manager_parse_variable(opt, size, var))
|
||||
goto error;
|
||||
}
|
||||
|
||||
return opt;
|
||||
|
||||
error:
|
||||
core_option_manager_free(opt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_updated:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Has a core option been updated?
|
||||
*
|
||||
* Returns: true (1) if a core option has been updated,
|
||||
* otherwise false (0).
|
||||
**/
|
||||
bool core_option_manager_updated(core_option_manager_t *opt)
|
||||
{
|
||||
if (!opt)
|
||||
return false;
|
||||
return opt->updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_flush:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Writes core option key-pair values to file.
|
||||
*
|
||||
* Returns: true (1) if core option values could be
|
||||
* successfully saved to disk, otherwise false (0).
|
||||
**/
|
||||
bool core_option_manager_flush(core_option_manager_t *opt)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
struct core_option *option = (struct core_option*)&opt->opts[i];
|
||||
|
||||
if (option)
|
||||
config_set_string(opt->conf, option->key,
|
||||
core_option_manager_get_val(opt, i));
|
||||
}
|
||||
|
||||
RARCH_LOG("Saved core options file to \"%s\"\n", opt->conf_path);
|
||||
return config_file_write(opt->conf, opt->conf_path, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_flush_game_specific:
|
||||
* @opt : options manager handle
|
||||
* @path : path for the core options file
|
||||
*
|
||||
* Writes core option key-pair values to a custom file.
|
||||
*
|
||||
* Returns: true (1) if core option values could be
|
||||
* successfully saved to disk, otherwise false (0).
|
||||
**/
|
||||
bool core_option_manager_flush_game_specific(
|
||||
core_option_manager_t *opt, const char* path)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
struct core_option *option = (struct core_option*)&opt->opts[i];
|
||||
|
||||
if (option)
|
||||
config_set_string(opt->conf, option->key,
|
||||
core_option_manager_get_val(opt, i));
|
||||
}
|
||||
|
||||
return config_file_write(opt->conf, path, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_size:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Gets total number of options.
|
||||
*
|
||||
* Returns: Total number of options.
|
||||
**/
|
||||
size_t core_option_manager_size(core_option_manager_t *opt)
|
||||
{
|
||||
if (!opt)
|
||||
return 0;
|
||||
return opt->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_get_desc:
|
||||
* @opt : options manager handle
|
||||
* @index : index identifier of the option
|
||||
*
|
||||
* Gets description for an option.
|
||||
*
|
||||
* Returns: Description for an option.
|
||||
**/
|
||||
const char *core_option_manager_get_desc(core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
if (!opt)
|
||||
return NULL;
|
||||
return opt->opts[idx].desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_get_val:
|
||||
* @opt : options manager handle
|
||||
* @index : index identifier of the option
|
||||
*
|
||||
* Gets value for an option.
|
||||
*
|
||||
* Returns: Value for an option.
|
||||
**/
|
||||
const char *core_option_manager_get_val(core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
struct core_option *option = NULL;
|
||||
if (!opt)
|
||||
return NULL;
|
||||
option = (struct core_option*)&opt->opts[idx];
|
||||
return option->vals->elems[option->index].data;
|
||||
}
|
||||
|
||||
void core_option_manager_set_val(core_option_manager_t *opt,
|
||||
size_t idx, size_t val_idx)
|
||||
{
|
||||
struct core_option *option= NULL;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
option = (struct core_option*)&opt->opts[idx];
|
||||
option->index = val_idx % option->vals->size;
|
||||
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_next:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index of core option to be reset to defaults.
|
||||
*
|
||||
* Get next value for core option specified by @idx.
|
||||
* Options wrap around.
|
||||
**/
|
||||
void core_option_manager_next(core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
struct core_option *option = NULL;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
option = (struct core_option*)&opt->opts[idx];
|
||||
|
||||
option->index = (option->index + 1) % option->vals->size;
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_prev:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index of core option to be reset to defaults.
|
||||
* Options wrap around.
|
||||
*
|
||||
* Get previous value for core option specified by @idx.
|
||||
* Options wrap around.
|
||||
**/
|
||||
void core_option_manager_prev(core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
struct core_option *option = NULL;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
option = (struct core_option*)&opt->opts[idx];
|
||||
option->index = (option->index + option->vals->size - 1) %
|
||||
option->vals->size;
|
||||
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_set_default:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index of core option to be reset to defaults.
|
||||
*
|
||||
* Reset core option specified by @idx and sets default value for option.
|
||||
**/
|
||||
void core_option_manager_set_default(core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
opt->opts[idx].index = 0;
|
||||
opt->updated = true;
|
||||
}
|
@ -48,71 +48,13 @@ struct core_option_manager
|
||||
typedef struct core_option_manager core_option_manager_t;
|
||||
|
||||
/**
|
||||
* core_option_manager_new:
|
||||
* @conf_path : Filesystem path to write core option config file to.
|
||||
* @vars : Pointer to variable array handle.
|
||||
* core_option_manager_set_default:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index of core option to be reset to defaults.
|
||||
*
|
||||
* Creates and initializes a core manager handle.
|
||||
*
|
||||
* Returns: handle to new core manager handle, otherwise NULL.
|
||||
* Reset core option specified by @idx and sets default value for option.
|
||||
**/
|
||||
core_option_manager_t *core_option_manager_new(const char *conf_path,
|
||||
const void *data);
|
||||
|
||||
/**
|
||||
* core_option_manager_updated:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Has a core option been updated?
|
||||
*
|
||||
* Returns: true (1) if a core option has been updated,
|
||||
* otherwise false (0).
|
||||
**/
|
||||
bool core_option_manager_updated(core_option_manager_t *opt);
|
||||
|
||||
/**
|
||||
* core_option_manager_flush:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Writes core option key-pair values to file.
|
||||
*
|
||||
* Returns: true (1) if core option values could be
|
||||
* successfully saved to disk, otherwise false (0).
|
||||
**/
|
||||
bool core_option_manager_flush(core_option_manager_t *opt);
|
||||
|
||||
/**
|
||||
* core_option_manager_flush_game_specific:
|
||||
* @opt : options manager handle
|
||||
* @path : path for the core options file
|
||||
*
|
||||
* Writes core option key-pair values to a custom file.
|
||||
*
|
||||
* Returns: true (1) if core option values could be
|
||||
* successfully saved to disk, otherwise false (0).
|
||||
**/
|
||||
bool core_option_manager_flush_game_specific(
|
||||
core_option_manager_t *opt, const char* path);
|
||||
|
||||
/**
|
||||
* core_option_manager_free:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Frees core option manager handle.
|
||||
**/
|
||||
void core_option_manager_free(core_option_manager_t *opt);
|
||||
|
||||
void core_option_manager_get(core_option_manager_t *opt, void *data);
|
||||
|
||||
/**
|
||||
* core_option_manager_size:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Gets total number of options.
|
||||
*
|
||||
* Returns: Total number of options.
|
||||
**/
|
||||
size_t core_option_manager_size(core_option_manager_t *opt);
|
||||
void core_option_manager_set_default(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
/**
|
||||
* core_option_manager_get_desc:
|
||||
@ -141,36 +83,6 @@ const char *core_option_manager_get_val(core_option_manager_t *opt,
|
||||
void core_option_manager_set_val(core_option_manager_t *opt,
|
||||
size_t idx, size_t val_idx);
|
||||
|
||||
/**
|
||||
* core_option_manager_next:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : idx of core option to be reset to defaults.
|
||||
*
|
||||
* Get next value for core option specified by @idx.
|
||||
* Options wrap around.
|
||||
**/
|
||||
void core_option_manager_next(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
/**
|
||||
* core_option_manager_prev:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : idx of core option to be reset to defaults.
|
||||
* Options wrap around.
|
||||
*
|
||||
* Get previous value for core option specified by @idx.
|
||||
* Options wrap around.
|
||||
**/
|
||||
void core_option_manager_prev(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
/**
|
||||
* core_option_manager_set_default:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : idx of core option to be reset to defaults.
|
||||
*
|
||||
* Reset core option specified by @idx and sets default value for option.
|
||||
**/
|
||||
void core_option_manager_set_default(core_option_manager_t *opt, size_t idx);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
345
retroarch.c
345
retroarch.c
@ -41,6 +41,7 @@
|
||||
|
||||
#include <boolean.h>
|
||||
#include <string/stdstring.h>
|
||||
#include <file/config_file.h>
|
||||
#include <lists/string_list.h>
|
||||
#include <retro_math.h>
|
||||
#include <retro_timers.h>
|
||||
@ -333,6 +334,299 @@ static char log_file_override_path[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
static char launch_arguments[4096];
|
||||
|
||||
/* Core Options */
|
||||
|
||||
static bool core_option_manager_parse_variable(
|
||||
core_option_manager_t *opt, size_t idx,
|
||||
const struct retro_variable *var)
|
||||
{
|
||||
const char *val_start = NULL;
|
||||
char *value = NULL;
|
||||
char *desc_end = NULL;
|
||||
char *config_val = NULL;
|
||||
struct core_option *option = (struct core_option*)&opt->opts[idx];
|
||||
|
||||
if (!string_is_empty(var->key))
|
||||
option->key = strdup(var->key);
|
||||
if (!string_is_empty(var->value))
|
||||
value = strdup(var->value);
|
||||
|
||||
if (!string_is_empty(value))
|
||||
desc_end = strstr(value, "; ");
|
||||
|
||||
if (!desc_end)
|
||||
goto error;
|
||||
|
||||
*desc_end = '\0';
|
||||
|
||||
if (!string_is_empty(value))
|
||||
option->desc = strdup(value);
|
||||
|
||||
val_start = desc_end + 2;
|
||||
option->vals = string_split(val_start, "|");
|
||||
|
||||
if (!option->vals)
|
||||
goto error;
|
||||
|
||||
if (config_get_string(opt->conf, option->key, &config_val))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < option->vals->size; i++)
|
||||
{
|
||||
if (string_is_equal(option->vals->elems[i].data, config_val))
|
||||
{
|
||||
option->index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(config_val);
|
||||
}
|
||||
|
||||
free(value);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
free(value);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_free:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Frees core option manager handle.
|
||||
**/
|
||||
static void core_option_manager_free(core_option_manager_t *opt)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
if (opt->opts[i].desc)
|
||||
free(opt->opts[i].desc);
|
||||
if (opt->opts[i].key)
|
||||
free(opt->opts[i].key);
|
||||
|
||||
if (opt->opts[i].vals)
|
||||
string_list_free(opt->opts[i].vals);
|
||||
|
||||
opt->opts[i].desc = NULL;
|
||||
opt->opts[i].key = NULL;
|
||||
opt->opts[i].vals = NULL;
|
||||
}
|
||||
|
||||
if (opt->conf)
|
||||
config_file_free(opt->conf);
|
||||
free(opt->opts);
|
||||
free(opt);
|
||||
}
|
||||
|
||||
static void core_option_manager_get(core_option_manager_t *opt,
|
||||
struct retro_variable *var)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
#ifdef HAVE_RUNAHEAD
|
||||
if (opt->updated)
|
||||
secondary_core_set_variable_update();
|
||||
#endif
|
||||
|
||||
opt->updated = false;
|
||||
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
if (string_is_empty(opt->opts[i].key))
|
||||
continue;
|
||||
|
||||
if (string_is_equal(opt->opts[i].key, var->key))
|
||||
{
|
||||
var->value = core_option_manager_get_val(opt, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var->value = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_new:
|
||||
* @conf_path : Filesystem path to write core option config file to.
|
||||
* @vars : Pointer to variable array handle.
|
||||
*
|
||||
* Creates and initializes a core manager handle.
|
||||
*
|
||||
* Returns: handle to new core manager handle, otherwise NULL.
|
||||
**/
|
||||
static core_option_manager_t *core_option_manager_new(const char *conf_path,
|
||||
const struct retro_variable *vars)
|
||||
{
|
||||
const struct retro_variable *var;
|
||||
size_t size = 0;
|
||||
core_option_manager_t *opt = (core_option_manager_t*)
|
||||
calloc(1, sizeof(*opt));
|
||||
|
||||
if (!opt)
|
||||
return NULL;
|
||||
|
||||
if (!string_is_empty(conf_path))
|
||||
opt->conf = config_file_new(conf_path);
|
||||
if (!opt->conf)
|
||||
opt->conf = config_file_new(NULL);
|
||||
|
||||
strlcpy(opt->conf_path, conf_path, sizeof(opt->conf_path));
|
||||
|
||||
if (!opt->conf)
|
||||
goto error;
|
||||
|
||||
for (var = vars; var->key && var->value; var++)
|
||||
size++;
|
||||
|
||||
if (size == 0)
|
||||
goto error;
|
||||
|
||||
opt->opts = (struct core_option*)calloc(size, sizeof(*opt->opts));
|
||||
if (!opt->opts)
|
||||
goto error;
|
||||
|
||||
opt->size = size;
|
||||
size = 0;
|
||||
|
||||
for (var = vars; var->key && var->value; size++, var++)
|
||||
{
|
||||
if (!core_option_manager_parse_variable(opt, size, var))
|
||||
goto error;
|
||||
}
|
||||
|
||||
return opt;
|
||||
|
||||
error:
|
||||
core_option_manager_free(opt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_flush:
|
||||
* @opt : options manager handle
|
||||
*
|
||||
* Writes core option key-pair values to file.
|
||||
*
|
||||
* Returns: true (1) if core option values could be
|
||||
* successfully saved to disk, otherwise false (0).
|
||||
**/
|
||||
static bool core_option_manager_flush(core_option_manager_t *opt)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
struct core_option *option = (struct core_option*)&opt->opts[i];
|
||||
|
||||
if (option)
|
||||
config_set_string(opt->conf, option->key,
|
||||
core_option_manager_get_val(opt, i));
|
||||
}
|
||||
|
||||
RARCH_LOG("Saved core options file to \"%s\"\n", opt->conf_path);
|
||||
return config_file_write(opt->conf, opt->conf_path, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_flush_game_specific:
|
||||
* @opt : options manager handle
|
||||
* @path : path for the core options file
|
||||
*
|
||||
* Writes core option key-pair values to a custom file.
|
||||
*
|
||||
* Returns: true (1) if core option values could be
|
||||
* successfully saved to disk, otherwise false (0).
|
||||
**/
|
||||
static bool core_option_manager_flush_game_specific(
|
||||
core_option_manager_t *opt, const char* path)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < opt->size; i++)
|
||||
{
|
||||
struct core_option *option = (struct core_option*)&opt->opts[i];
|
||||
|
||||
if (option)
|
||||
config_set_string(opt->conf, option->key,
|
||||
core_option_manager_get_val(opt, i));
|
||||
}
|
||||
|
||||
return config_file_write(opt->conf, path, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_get_desc:
|
||||
* @opt : options manager handle
|
||||
* @index : index identifier of the option
|
||||
*
|
||||
* Gets description for an option.
|
||||
*
|
||||
* Returns: Description for an option.
|
||||
**/
|
||||
const char *core_option_manager_get_desc(
|
||||
core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
if (!opt)
|
||||
return NULL;
|
||||
return opt->opts[idx].desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_get_val:
|
||||
* @opt : options manager handle
|
||||
* @index : index identifier of the option
|
||||
*
|
||||
* Gets value for an option.
|
||||
*
|
||||
* Returns: Value for an option.
|
||||
**/
|
||||
const char *core_option_manager_get_val(core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
struct core_option *option = NULL;
|
||||
if (!opt)
|
||||
return NULL;
|
||||
option = (struct core_option*)&opt->opts[idx];
|
||||
return option->vals->elems[option->index].data;
|
||||
}
|
||||
|
||||
void core_option_manager_set_val(core_option_manager_t *opt,
|
||||
size_t idx, size_t val_idx)
|
||||
{
|
||||
struct core_option *option= NULL;
|
||||
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
option = (struct core_option*)&opt->opts[idx];
|
||||
option->index = val_idx % option->vals->size;
|
||||
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* core_option_manager_set_default:
|
||||
* @opt : pointer to core option manager object.
|
||||
* @idx : index of core option to be reset to defaults.
|
||||
*
|
||||
* Reset core option specified by @idx and sets default value for option.
|
||||
**/
|
||||
void core_option_manager_set_default(core_option_manager_t *opt, size_t idx)
|
||||
{
|
||||
if (!opt)
|
||||
return;
|
||||
|
||||
opt->opts[idx].index = 0;
|
||||
opt->updated = true;
|
||||
}
|
||||
|
||||
/* Video */
|
||||
|
||||
#define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024)
|
||||
@ -14829,7 +15123,10 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
|
||||
unsigned *idx = (unsigned*)data;
|
||||
if (!idx)
|
||||
return false;
|
||||
*idx = (unsigned)core_option_manager_size(runloop_core_options);
|
||||
if (runloop_core_options)
|
||||
*idx = (unsigned)runloop_core_options->size;
|
||||
else
|
||||
*idx = 0;
|
||||
}
|
||||
break;
|
||||
case RARCH_CTL_HAS_CORE_OPTIONS:
|
||||
@ -15115,21 +15412,50 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
|
||||
case RARCH_CTL_IS_CORE_OPTION_UPDATED:
|
||||
if (!runloop_core_options)
|
||||
return false;
|
||||
return core_option_manager_updated(runloop_core_options);
|
||||
return runloop_core_options->updated;
|
||||
case RARCH_CTL_CORE_OPTION_PREV:
|
||||
/*
|
||||
* Get previous value for core option specified by @idx.
|
||||
* Options wrap around.
|
||||
*/
|
||||
{
|
||||
unsigned *idx = (unsigned*)data;
|
||||
if (!idx)
|
||||
struct core_option *option = NULL;
|
||||
unsigned *idx = (unsigned*)data;
|
||||
if (!idx || !runloop_core_options)
|
||||
return false;
|
||||
core_option_manager_prev(runloop_core_options, *idx);
|
||||
option = (struct core_option*)
|
||||
&runloop_core_options->opts[*idx];
|
||||
|
||||
if (option)
|
||||
{
|
||||
option->index =
|
||||
(option->index + option->vals->size - 1) %
|
||||
option->vals->size;
|
||||
runloop_core_options->updated = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RARCH_CTL_CORE_OPTION_NEXT:
|
||||
/*
|
||||
* Get next value for core option specified by @idx.
|
||||
* Options wrap around.
|
||||
*/
|
||||
{
|
||||
unsigned *idx = (unsigned*)data;
|
||||
if (!idx)
|
||||
struct core_option *option = NULL;
|
||||
unsigned *idx = (unsigned*)data;
|
||||
|
||||
if (!idx || !runloop_core_options)
|
||||
return false;
|
||||
core_option_manager_next(runloop_core_options, *idx);
|
||||
|
||||
option =
|
||||
(struct core_option*)&runloop_core_options->opts[*idx];
|
||||
|
||||
if (option)
|
||||
{
|
||||
option->index =
|
||||
(option->index + 1) % option->vals->size;
|
||||
runloop_core_options->updated = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RARCH_CTL_CORE_OPTIONS_GET:
|
||||
@ -15142,7 +15468,8 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
|
||||
if (!runloop_core_options || !var)
|
||||
return false;
|
||||
|
||||
core_option_manager_get(runloop_core_options, var);
|
||||
if (runloop_core_options)
|
||||
core_option_manager_get(runloop_core_options, var);
|
||||
|
||||
if (log_level == RETRO_LOG_DEBUG)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user