mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-21 12:29:43 -10:00
The option-list / extension-filter string shares the aux union with the float rounding string, since no row type uses both. index_offset and size are 16 bits wide, and the never-read index byte and directory empty-value string are gone, together with the arguments that only fed them. rarch_setting_t is 80 bytes on 64-bit targets and 56 on 32-bit ones.
276 lines
9.4 KiB
C
276 lines
9.4 KiB
C
/* RetroArch - A frontend for libretro.
|
|
* 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/>.
|
|
*/
|
|
|
|
#ifndef __SETTING_LIST_H
|
|
#define __SETTING_LIST_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
#include <boolean.h>
|
|
|
|
#include <retro_common_api.h>
|
|
#include <retro_inline.h>
|
|
|
|
#include "gfx/video_defines.h"
|
|
|
|
#include "command.h"
|
|
#include "msg_hash.h"
|
|
|
|
RETRO_BEGIN_DECLS
|
|
|
|
enum setting_type
|
|
{
|
|
ST_NONE = 0,
|
|
ST_ACTION,
|
|
ST_BOOL,
|
|
ST_INT,
|
|
ST_UINT,
|
|
ST_SIZE,
|
|
ST_FLOAT,
|
|
ST_PATH,
|
|
ST_DIR,
|
|
ST_STRING,
|
|
ST_STRING_OPTIONS,
|
|
ST_BIND,
|
|
ST_GROUP,
|
|
ST_SUB_GROUP,
|
|
ST_END_GROUP,
|
|
ST_END_SUB_GROUP
|
|
};
|
|
|
|
enum ui_setting_type
|
|
{
|
|
ST_UI_TYPE_NONE = 0,
|
|
ST_UI_TYPE_CHECKBOX,
|
|
ST_UI_TYPE_UINT_COLOR_BUTTON,
|
|
ST_UI_TYPE_UINT_SPINBOX,
|
|
ST_UI_TYPE_UINT_COMBOBOX,
|
|
ST_UI_TYPE_UINT_RADIO_BUTTONS,
|
|
ST_UI_TYPE_FLOAT_COLOR_BUTTON,
|
|
ST_UI_TYPE_FLOAT_SPINBOX,
|
|
ST_UI_TYPE_FLOAT_SLIDER_AND_SPINBOX,
|
|
ST_UI_TYPE_SIZE_SPINBOX,
|
|
ST_UI_TYPE_BIND_BUTTON,
|
|
ST_UI_TYPE_DIRECTORY_SELECTOR,
|
|
ST_UI_TYPE_FILE_SELECTOR,
|
|
ST_UI_TYPE_FONT_SELECTOR,
|
|
ST_UI_TYPE_STRING_COMBOBOX,
|
|
ST_UI_TYPE_STRING_LINE_EDIT,
|
|
ST_UI_TYPE_PASSWORD_LINE_EDIT,
|
|
ST_UI_TYPE_LAST
|
|
};
|
|
|
|
enum setting_flags
|
|
{
|
|
SD_FLAG_NONE = 0,
|
|
SD_FLAG_PATH_DIR = (1 << 0),
|
|
SD_FLAG_PATH_FILE = (1 << 1),
|
|
SD_FLAG_ALLOW_EMPTY = (1 << 2),
|
|
SD_FLAG_HAS_RANGE = (1 << 3),
|
|
SD_FLAG_ALLOW_INPUT = (1 << 4),
|
|
SD_FLAG_IS_DRIVER = (1 << 5),
|
|
SD_FLAG_EXIT = (1 << 6),
|
|
SD_FLAG_CMD_APPLY_AUTO = (1 << 7),
|
|
SD_FLAG_BROWSER_ACTION = (1 << 8),
|
|
SD_FLAG_ADVANCED = (1 << 9),
|
|
SD_FLAG_LAKKA_ADVANCED = (1 << 10),
|
|
SD_FLAG_ENFORCE_MINRANGE = (1 << 11),
|
|
SD_FLAG_ENFORCE_MAXRANGE = (1 << 12),
|
|
SD_FLAG_DONT_USE_ENUM_IDX_REPRESENTATION = (1 << 13),
|
|
SD_FLAG_CMD_TRIGGER_EVENT_TRIGGERED = (1 << 14),
|
|
SD_FLAG_DEFAULT_VALUE = (1 << 15)
|
|
};
|
|
|
|
enum settings_free_flags
|
|
{
|
|
SD_FREE_FLAG_VALUES = (1 << 0),
|
|
SD_FREE_FLAG_NAME = (1 << 1),
|
|
SD_FREE_FLAG_SHORT = (1 << 2),
|
|
/* Not an ownership bit: set at build time on ST_GROUP entries
|
|
* whose parent is the main menu, replacing the parent_group
|
|
* string the callbacks compared against - equality with the main
|
|
* menu label was the only thing that string was ever read for.
|
|
* Lives here because the byte has spare bits. */
|
|
SD_FREE_FLAG_MAIN_MENU_GROUP = (1 << 3),
|
|
/* Also not ownership bits. A row carrying one of these has a
|
|
* target that addresses a packed word rather than a value of its
|
|
* own, and the bit says which half of it the row edits: the high
|
|
* half for a width or an x, the low half for a height or a y.
|
|
* Set on every row whose settings_t value shares one word with a
|
|
* partner axis: the custom viewport's origin and size, the window
|
|
* size pairs and the desktop menu window geometry.
|
|
*
|
|
* Anything that can reach such a row - the generic ST_UINT and
|
|
* ST_INT handlers, the dropdown lists and the desktop UIs - reads
|
|
* and writes it through setting_uint_get / setting_uint_set and
|
|
* the signed pair below, never through value.target directly. */
|
|
SD_FREE_FLAG_PACKED_HI = (1 << 4),
|
|
SD_FREE_FLAG_PACKED_LO = (1 << 5)
|
|
};
|
|
|
|
#define SD_FREE_FLAG_PACKED_ANY \
|
|
(SD_FREE_FLAG_PACKED_HI | SD_FREE_FLAG_PACKED_LO)
|
|
|
|
typedef struct rarch_setting rarch_setting_t;
|
|
typedef struct setting_actions setting_actions_t;
|
|
typedef struct rarch_setting_group_info rarch_setting_group_info_t;
|
|
|
|
typedef void (*change_handler_t )(rarch_setting_t *setting);
|
|
typedef int (*action_left_handler_t )(rarch_setting_t *setting, size_t idx, bool wraparound);
|
|
typedef int (*action_right_handler_t )(rarch_setting_t *setting, size_t idx, bool wraparound);
|
|
typedef int (*action_start_handler_t )(rarch_setting_t *setting);
|
|
typedef int (*action_ok_handler_t )(rarch_setting_t *setting, size_t idx, bool wraparound);
|
|
typedef int (*action_select_handler_t )(rarch_setting_t *setting, size_t idx, bool wraparound);
|
|
|
|
|
|
typedef size_t (*get_string_representation_t )(rarch_setting_t *setting, char *s, size_t len);
|
|
|
|
struct setting_actions
|
|
{
|
|
action_ok_handler_t ok;
|
|
action_start_handler_t start;
|
|
/* Named sel, not select: net_compat.h defines select as a
|
|
* five-argument macro on platforms without a native one, and a
|
|
* member of that name breaks every consumer that includes the
|
|
* networking headers first - the Wii found this the hard way. */
|
|
action_select_handler_t sel;
|
|
action_left_handler_t left;
|
|
action_right_handler_t right;
|
|
change_handler_t change;
|
|
change_handler_t read;
|
|
get_string_representation_t repr;
|
|
};
|
|
|
|
struct rarch_setting_group_info
|
|
{
|
|
const char *name;
|
|
};
|
|
|
|
struct rarch_setting
|
|
{
|
|
|
|
float min;
|
|
float max;
|
|
/* Disjoint by type: float entries store their printf rounding
|
|
* string; option rows their '|'-separated choices, path and
|
|
* browser-action rows their extension filter. */
|
|
union
|
|
{
|
|
const char *rounding_fraction; /* ST_FLOAT */
|
|
const char *values;
|
|
} aux;
|
|
const char *name;
|
|
const char *short_description;
|
|
|
|
/* Every per-entry handler lives in shared interned tuples: the
|
|
* full eight-handler combination counts 150 distinct blocks
|
|
* across 1,904 entries, so each entry stores one pointer instead
|
|
* of eight handlers. Never NULL. */
|
|
const setting_actions_t *actions;
|
|
|
|
struct
|
|
{
|
|
union
|
|
{
|
|
bool *boolean;
|
|
char *string;
|
|
int *integer;
|
|
unsigned int *unsigned_integer;
|
|
float *fraction;
|
|
size_t *sizet;
|
|
} target;
|
|
} value;
|
|
|
|
|
|
union
|
|
{
|
|
const char *string;
|
|
const struct retro_keybind_def *keybind;
|
|
size_t sizet;
|
|
int integer;
|
|
unsigned int unsigned_integer;
|
|
float fraction;
|
|
bool boolean;
|
|
} default_value;
|
|
|
|
float step;
|
|
|
|
/* Narrow storage; every value in use fits, reads promote back to
|
|
* int, and nothing takes their address. enum event_command tops
|
|
* out below 1024, the setting and ui type enums below 64, the hash
|
|
* enums below 65536, the largest string target is 8 KiB, and
|
|
* index_offset holds a user, an entry or a hash enum base. */
|
|
uint16_t index_offset;
|
|
uint16_t size;
|
|
uint16_t bind_type;
|
|
uint16_t cmd_trigger_idx; /* enum event_command */
|
|
uint16_t enum_idx; /* enum msg_hash_enums */
|
|
uint16_t enum_value_idx; /* enum msg_hash_enums */
|
|
uint16_t flags;
|
|
int16_t offset_by;
|
|
uint8_t ui_type; /* enum ui_setting_type */
|
|
uint8_t browser_selection_type; /* enum setting_type */
|
|
uint8_t type; /* enum setting_type */
|
|
uint8_t free_flags;
|
|
};
|
|
|
|
/* An ST_UINT or ST_INT row's value. Most rows own the word their
|
|
* target addresses; a row flagged SD_FREE_FLAG_PACKED_HI or _LO owns
|
|
* one half of it, in VIDEO_SCALE_PACK's layout for a uint row and
|
|
* VIDEO_POS_PACK's for an int row, and a write leaves the partner
|
|
* half as it stands. */
|
|
static INLINE unsigned setting_uint_get(const rarch_setting_t *setting)
|
|
{
|
|
if (setting->free_flags & SD_FREE_FLAG_PACKED_HI)
|
|
return VIDEO_SCALE_W(*setting->value.target.unsigned_integer);
|
|
if (setting->free_flags & SD_FREE_FLAG_PACKED_LO)
|
|
return VIDEO_SCALE_H(*setting->value.target.unsigned_integer);
|
|
return *setting->value.target.unsigned_integer;
|
|
}
|
|
|
|
static INLINE void setting_uint_set(rarch_setting_t *setting, unsigned v)
|
|
{
|
|
if (setting->free_flags & SD_FREE_FLAG_PACKED_HI)
|
|
VIDEO_SCALE_PUT_W(*setting->value.target.unsigned_integer, v);
|
|
else if (setting->free_flags & SD_FREE_FLAG_PACKED_LO)
|
|
VIDEO_SCALE_PUT_H(*setting->value.target.unsigned_integer, v);
|
|
else
|
|
*setting->value.target.unsigned_integer = v;
|
|
}
|
|
|
|
static INLINE int setting_int_get(const rarch_setting_t *setting)
|
|
{
|
|
if (setting->free_flags & SD_FREE_FLAG_PACKED_HI)
|
|
return VIDEO_POS_X(*setting->value.target.integer);
|
|
if (setting->free_flags & SD_FREE_FLAG_PACKED_LO)
|
|
return VIDEO_POS_Y(*setting->value.target.integer);
|
|
return *setting->value.target.integer;
|
|
}
|
|
|
|
static INLINE void setting_int_set(rarch_setting_t *setting, int v)
|
|
{
|
|
if (setting->free_flags & SD_FREE_FLAG_PACKED_HI)
|
|
VIDEO_POS_PUT_X(*setting->value.target.integer, v);
|
|
else if (setting->free_flags & SD_FREE_FLAG_PACKED_LO)
|
|
VIDEO_POS_PUT_Y(*setting->value.target.integer, v);
|
|
else
|
|
*setting->value.target.integer = v;
|
|
}
|
|
|
|
RETRO_END_DECLS
|
|
|
|
#endif
|