2023-06-12 17:05:30 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-06-10 23:40:39 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <typeindex>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
enum class Category : u32 {
|
2023-08-16 02:36:56 -04:00
|
|
|
Android,
|
2023-06-10 23:40:39 -04:00
|
|
|
Audio,
|
|
|
|
Core,
|
|
|
|
Cpu,
|
|
|
|
CpuDebug,
|
|
|
|
CpuUnsafe,
|
|
|
|
Renderer,
|
|
|
|
RendererAdvanced,
|
|
|
|
RendererDebug,
|
|
|
|
System,
|
|
|
|
SystemAudio,
|
|
|
|
DataStorage,
|
|
|
|
Debugging,
|
|
|
|
DebuggingGraphics,
|
|
|
|
Miscellaneous,
|
|
|
|
Network,
|
|
|
|
WebService,
|
|
|
|
AddOns,
|
|
|
|
Controls,
|
|
|
|
Ui,
|
2023-11-09 21:11:13 -05:00
|
|
|
UiAudio,
|
2023-06-10 23:40:39 -04:00
|
|
|
UiGeneral,
|
|
|
|
UiLayout,
|
|
|
|
UiGameList,
|
|
|
|
Screenshots,
|
|
|
|
Shortcuts,
|
|
|
|
Multiplayer,
|
|
|
|
Services,
|
|
|
|
Paths,
|
2023-11-03 10:41:16 -04:00
|
|
|
Linux,
|
2023-06-10 23:40:39 -04:00
|
|
|
MaxEnum,
|
|
|
|
};
|
|
|
|
|
2023-06-21 05:04:21 -04:00
|
|
|
constexpr u8 SpecializationTypeMask = 0xf;
|
|
|
|
constexpr u8 SpecializationAttributeMask = 0xf0;
|
|
|
|
constexpr u8 SpecializationAttributeOffset = 4;
|
|
|
|
|
2023-07-23 16:21:08 -04:00
|
|
|
// Scalar and countable could have better names
|
2023-06-21 05:04:21 -04:00
|
|
|
enum Specialization : u8 {
|
|
|
|
Default = 0,
|
2023-07-23 16:21:08 -04:00
|
|
|
Time = 1, // Duration or specific moment in time
|
|
|
|
Hex = 2, // Hexadecimal number
|
|
|
|
List = 3, // Setting has specific members
|
|
|
|
RuntimeList = 4, // Members of the list are determined during runtime
|
|
|
|
Scalar = 5, // Values are continuous
|
|
|
|
Countable = 6, // Can be stepped through
|
|
|
|
Paired = 7, // Another setting is associated with this setting
|
2023-08-21 16:03:30 -04:00
|
|
|
Radio = 8, // Setting should be presented in a radio group
|
2023-06-21 05:04:21 -04:00
|
|
|
|
2023-07-23 16:21:08 -04:00
|
|
|
Percentage = (1 << SpecializationAttributeOffset), // Should be represented as a percentage
|
2023-06-21 03:23:36 -04:00
|
|
|
};
|
|
|
|
|
2023-06-12 17:05:30 -04:00
|
|
|
class BasicSetting;
|
2023-06-10 23:40:39 -04:00
|
|
|
|
|
|
|
class Linkage {
|
|
|
|
public:
|
|
|
|
explicit Linkage(u32 initial_count = 0);
|
|
|
|
~Linkage();
|
2023-07-19 13:46:48 -04:00
|
|
|
std::map<Category, std::vector<BasicSetting*>> by_category{};
|
2023-08-16 02:36:56 -04:00
|
|
|
std::map<std::string, Settings::BasicSetting*> by_key{};
|
2023-06-10 23:40:39 -04:00
|
|
|
std::vector<std::function<void()>> restore_functions{};
|
|
|
|
u32 count;
|
|
|
|
};
|
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/**
|
|
|
|
* BasicSetting is an abstract class that only keeps track of metadata. The string methods are
|
|
|
|
* available to get data values out.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
class BasicSetting {
|
|
|
|
protected:
|
2023-06-21 17:06:10 -04:00
|
|
|
explicit BasicSetting(Linkage& linkage, const std::string& name, Category category_, bool save_,
|
|
|
|
bool runtime_modifiable_, u32 specialization,
|
2023-06-21 04:32:13 -04:00
|
|
|
BasicSetting* other_setting);
|
2023-06-12 17:05:30 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~BasicSetting();
|
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/*
|
|
|
|
* Data retrieval
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/**
|
|
|
|
* Returns a string representation of the internal data. If the Setting is Switchable, it
|
|
|
|
* respects the internal global state: it is based on GetValue().
|
|
|
|
*
|
|
|
|
* @returns A string representation of the internal data.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual std::string ToString() const = 0;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string representation of the global version of internal data. If the Setting is
|
|
|
|
* not Switchable, it behaves like ToString.
|
|
|
|
*
|
|
|
|
* @returns A string representation of the global version of internal data.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual std::string ToStringGlobal() const;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns A string representation of the Setting's default value.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual std::string DefaultToString() const = 0;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string representation of the minimum value of the setting. If the Setting is not
|
|
|
|
* ranged, the string represents the default initialization of the data type.
|
|
|
|
*
|
|
|
|
* @returns A string representation of the minimum value of the setting.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual std::string MinVal() const = 0;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string representation of the maximum value of the setting. If the Setting is not
|
|
|
|
* ranged, the string represents the default initialization of the data type.
|
|
|
|
*
|
|
|
|
* @returns A string representation of the maximum value of the setting.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual std::string MaxVal() const = 0;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a string input, converts it to the internal data type if necessary, and then runs
|
|
|
|
* SetValue with it.
|
|
|
|
*
|
|
|
|
* @param load String of the input data.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
virtual void LoadString(const std::string& load) = 0;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string representation of the data. If the data is an enum, it returns a string of
|
|
|
|
* the enum value. If the internal data type is not an enum, this is equivalent to ToString.
|
|
|
|
*
|
|
|
|
* e.g. renderer_backend.Canonicalize() == "OpenGL"
|
|
|
|
*
|
|
|
|
* @returns Canonicalized string representation of the internal data
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual std::string Canonicalize() const = 0;
|
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/*
|
|
|
|
* Metadata
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/**
|
|
|
|
* @returns A unique identifier for the Setting's internal data type.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual std::type_index TypeId() const = 0;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the Setting's internal data type is an enum.
|
|
|
|
*
|
|
|
|
* @returns True if the Setting's internal data type is an enum
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual constexpr bool IsEnum() const = 0;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
2023-06-12 17:05:30 -04:00
|
|
|
/**
|
2023-06-13 19:37:54 -04:00
|
|
|
* Returns true if the current setting is Switchable.
|
2023-06-12 17:05:30 -04:00
|
|
|
*
|
|
|
|
* @returns If the setting is a SwitchableSetting
|
|
|
|
*/
|
|
|
|
[[nodiscard]] virtual constexpr bool Switchable() const {
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-13 19:37:54 -04:00
|
|
|
|
2023-06-12 17:05:30 -04:00
|
|
|
/**
|
2023-06-13 19:37:54 -04:00
|
|
|
* Returns true to suggest that a frontend can read or write the setting to a configuration
|
|
|
|
* file.
|
2023-06-12 17:05:30 -04:00
|
|
|
*
|
|
|
|
* @returns The save preference
|
|
|
|
*/
|
|
|
|
[[nodiscard]] bool Save() const;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns true if the current setting can be changed while the guest is running.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] bool RuntimeModfiable() const;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns A unique number corresponding to the setting.
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] constexpr u32 Id() const {
|
|
|
|
return id;
|
|
|
|
}
|
2023-06-13 19:37:54 -04:00
|
|
|
|
2023-06-12 17:05:30 -04:00
|
|
|
/**
|
|
|
|
* Returns the setting's category AKA INI group.
|
|
|
|
*
|
|
|
|
* @returns The setting's category
|
|
|
|
*/
|
2023-07-18 15:42:59 -04:00
|
|
|
[[nodiscard]] Category GetCategory() const;
|
2023-06-13 19:37:54 -04:00
|
|
|
|
2023-06-21 03:23:36 -04:00
|
|
|
/**
|
|
|
|
* @returns Extra metadata for data representation in frontend implementations.
|
|
|
|
*/
|
2023-06-21 05:04:21 -04:00
|
|
|
[[nodiscard]] u32 Specialization() const;
|
2023-06-21 03:23:36 -04:00
|
|
|
|
2023-06-21 04:32:13 -04:00
|
|
|
/**
|
|
|
|
* @returns Another BasicSetting if one is paired, or nullptr otherwise.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] BasicSetting* PairedSetting() const;
|
|
|
|
|
2023-06-12 17:05:30 -04:00
|
|
|
/**
|
|
|
|
* Returns the label this setting was created with.
|
|
|
|
*
|
|
|
|
* @returns A reference to the label
|
|
|
|
*/
|
|
|
|
[[nodiscard]] const std::string& GetLabel() const;
|
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/**
|
|
|
|
* @returns If the Setting checks input values for valid ranges.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] virtual constexpr bool Ranged() const = 0;
|
|
|
|
|
2023-06-21 21:41:06 -04:00
|
|
|
/**
|
|
|
|
* @returns The index of the enum if the underlying setting type is an enum, else max of u32.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] virtual constexpr u32 EnumIndex() const = 0;
|
|
|
|
|
2023-09-13 13:31:46 -04:00
|
|
|
/**
|
|
|
|
* @returns True if the underlying type is a floating point storage
|
|
|
|
*/
|
|
|
|
[[nodiscard]] virtual constexpr bool IsFloatingPoint() const = 0;
|
|
|
|
|
|
|
|
/**
|
2023-09-14 11:30:14 -04:00
|
|
|
* @returns True if the underlying type is an integer storage
|
2023-09-13 13:31:46 -04:00
|
|
|
*/
|
|
|
|
[[nodiscard]] virtual constexpr bool IsIntegral() const = 0;
|
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/*
|
|
|
|
* Switchable settings
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
|
2023-06-13 19:37:54 -04:00
|
|
|
/**
|
|
|
|
* Sets a setting's global state. True means use the normal setting, false to use a custom
|
|
|
|
* value. Has no effect if the Setting is not Switchable.
|
|
|
|
*
|
|
|
|
* @param global The desired state
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
virtual void SetGlobal(bool global);
|
2023-06-13 19:37:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the setting is using the normal setting value. Always true if the setting is
|
|
|
|
* not Switchable.
|
|
|
|
*
|
|
|
|
* @returns The Setting's global state
|
|
|
|
*/
|
2023-06-12 17:05:30 -04:00
|
|
|
[[nodiscard]] virtual bool UsingGlobal() const;
|
|
|
|
|
|
|
|
private:
|
2023-07-18 15:42:59 -04:00
|
|
|
const std::string label; ///< The setting's label
|
|
|
|
const Category category; ///< The setting's category AKA INI group
|
|
|
|
const u32 id; ///< Unique integer for the setting
|
2023-06-13 19:37:54 -04:00
|
|
|
const bool save; ///< Suggests if the setting should be saved and read to a frontend config
|
|
|
|
const bool
|
2023-06-21 05:04:21 -04:00
|
|
|
runtime_modifiable; ///< Suggests if the setting can be modified while a guest is running
|
|
|
|
const u32 specialization; ///< Extra data to identify representation of a setting
|
2023-06-21 04:32:13 -04:00
|
|
|
BasicSetting* const other_setting; ///< A paired setting
|
2023-06-12 17:05:30 -04:00
|
|
|
};
|
|
|
|
|
2023-06-10 23:40:39 -04:00
|
|
|
} // namespace Settings
|