settings: Move some simple data to BasicSetting
Reduces the need for the compiler to duplicate this code, by about 100KB executable size.
This commit is contained in:
parent
4903f40efe
commit
11e7e1b8ce
|
@ -110,6 +110,7 @@ add_library(common STATIC
|
|||
scratch_buffer.h
|
||||
settings.cpp
|
||||
settings.h
|
||||
settings_common.cpp
|
||||
settings_common.h
|
||||
settings_enums.h
|
||||
settings_input.cpp
|
||||
|
@ -199,6 +200,7 @@ if (MSVC)
|
|||
else()
|
||||
target_compile_options(common PRIVATE
|
||||
$<$<CXX_COMPILER_ID:Clang>:-fsized-deallocation>
|
||||
$<$<CXX_COMPILER_ID:Clang>:-Werror=unreachable-code-aggressive>
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -282,14 +282,6 @@ void UpdateRescalingInfo() {
|
|||
info.active = info.up_scale != 1 || info.down_shift != 0;
|
||||
}
|
||||
|
||||
std::string BasicSetting::ToStringGlobal() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool BasicSetting::UsingGlobal() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void RestoreGlobalState(bool is_powered_on) {
|
||||
// If a game is running, DO NOT restore the global settings state
|
||||
if (is_powered_on) {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string>
|
||||
#include "common/settings_common.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
BasicSetting::BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
|
||||
bool save_, bool runtime_modifiable_)
|
||||
: label{name}, category{category_}, id{linkage.count}, save{save_}, runtime_modifiable{
|
||||
runtime_modifiable_} {
|
||||
linkage.by_category[category].push_front(this);
|
||||
linkage.count++;
|
||||
}
|
||||
|
||||
BasicSetting::~BasicSetting() = default;
|
||||
|
||||
std::string BasicSetting::ToStringGlobal() const {
|
||||
return this->ToString();
|
||||
}
|
||||
|
||||
bool BasicSetting::UsingGlobal() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BasicSetting::SetGlobal(bool global) {}
|
||||
|
||||
bool BasicSetting::Save() const {
|
||||
return save;
|
||||
}
|
||||
|
||||
bool BasicSetting::RuntimeModfiable() const {
|
||||
return runtime_modifiable;
|
||||
}
|
||||
|
||||
Category BasicSetting::Category() const {
|
||||
return category;
|
||||
}
|
||||
|
||||
const std::string& BasicSetting::GetLabel() const {
|
||||
return label;
|
||||
}
|
||||
|
||||
} // namespace Settings
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <forward_list>
|
||||
|
@ -40,31 +43,7 @@ enum class Category : u32 {
|
|||
MaxEnum,
|
||||
};
|
||||
|
||||
class BasicSetting {
|
||||
protected:
|
||||
explicit BasicSetting() = default;
|
||||
|
||||
public:
|
||||
virtual ~BasicSetting() = default;
|
||||
|
||||
virtual Category Category() const = 0;
|
||||
virtual constexpr bool Switchable() const = 0;
|
||||
virtual std::string ToString() const = 0;
|
||||
virtual std::string ToStringGlobal() const;
|
||||
virtual void LoadString(const std::string& load) = 0;
|
||||
virtual std::string Canonicalize() const = 0;
|
||||
virtual const std::string& GetLabel() const = 0;
|
||||
virtual std::string DefaultToString() const = 0;
|
||||
virtual bool Save() const = 0;
|
||||
virtual std::type_index TypeId() const = 0;
|
||||
virtual constexpr bool IsEnum() const = 0;
|
||||
virtual bool RuntimeModfiable() const = 0;
|
||||
virtual void SetGlobal(bool global) {}
|
||||
virtual constexpr u32 Id() const = 0;
|
||||
virtual std::string MinVal() const = 0;
|
||||
virtual std::string MaxVal() const = 0;
|
||||
virtual bool UsingGlobal() const;
|
||||
};
|
||||
class BasicSetting;
|
||||
|
||||
class Linkage {
|
||||
public:
|
||||
|
@ -75,4 +54,71 @@ public:
|
|||
u32 count;
|
||||
};
|
||||
|
||||
class BasicSetting {
|
||||
protected:
|
||||
explicit BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
|
||||
bool save_, bool runtime_modifiable_);
|
||||
|
||||
public:
|
||||
virtual ~BasicSetting();
|
||||
|
||||
/* Data retrieval */
|
||||
|
||||
[[nodiscard]] virtual std::string ToString() const = 0;
|
||||
[[nodiscard]] virtual std::string ToStringGlobal() const;
|
||||
[[nodiscard]] virtual std::string DefaultToString() const = 0;
|
||||
[[nodiscard]] virtual std::string MinVal() const = 0;
|
||||
[[nodiscard]] virtual std::string MaxVal() const = 0;
|
||||
virtual void LoadString(const std::string& load) = 0;
|
||||
[[nodiscard]] virtual std::string Canonicalize() const = 0;
|
||||
|
||||
/* Identification */
|
||||
|
||||
[[nodiscard]] virtual std::type_index TypeId() const = 0;
|
||||
[[nodiscard]] virtual constexpr bool IsEnum() const = 0;
|
||||
/**
|
||||
* Returns whether the current setting is Switchable.
|
||||
*
|
||||
* @returns If the setting is a SwitchableSetting
|
||||
*/
|
||||
[[nodiscard]] virtual constexpr bool Switchable() const {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns the save preference of the setting i.e. when saving or reading the setting from a
|
||||
* frontend, whether this setting should be skipped.
|
||||
*
|
||||
* @returns The save preference
|
||||
*/
|
||||
[[nodiscard]] bool Save() const;
|
||||
[[nodiscard]] bool RuntimeModfiable() const;
|
||||
[[nodiscard]] constexpr u32 Id() const {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Returns the setting's category AKA INI group.
|
||||
*
|
||||
* @returns The setting's category
|
||||
*/
|
||||
[[nodiscard]] Category Category() const;
|
||||
/**
|
||||
* Returns the label this setting was created with.
|
||||
*
|
||||
* @returns A reference to the label
|
||||
*/
|
||||
[[nodiscard]] const std::string& GetLabel() const;
|
||||
|
||||
/* Switchable settings */
|
||||
|
||||
virtual void SetGlobal(bool global);
|
||||
[[nodiscard]] virtual bool UsingGlobal() const;
|
||||
|
||||
private:
|
||||
const std::string label; ///< The setting's label
|
||||
const enum Category category; ///< The setting's category AKA INI group
|
||||
const u32 id;
|
||||
const bool save;
|
||||
const bool runtime_modifiable;
|
||||
};
|
||||
|
||||
} // namespace Settings
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
@ -21,16 +24,6 @@ class Setting : public BasicSetting {
|
|||
protected:
|
||||
Setting() = default;
|
||||
|
||||
/**
|
||||
* Only sets the setting to the given initializer, leaving the other members to their default
|
||||
* initializers.
|
||||
*
|
||||
* @param global_val Initial value of the setting
|
||||
*/
|
||||
explicit Setting(const Type& val)
|
||||
: value{val},
|
||||
default_value{}, maximum{}, minimum{}, label{}, category{Category::Miscellaneous}, id{} {}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Sets a default value, label, and setting value.
|
||||
|
@ -43,11 +36,8 @@ public:
|
|||
explicit Setting(Linkage& linkage, const Type& default_val, const std::string& name,
|
||||
enum Category category_, bool save_ = true, bool runtime_modifiable_ = false)
|
||||
requires(!ranged)
|
||||
: value{default_val}, default_value{default_val}, label{name}, category{category_},
|
||||
id{linkage.count}, save{save_}, runtime_modifiable{runtime_modifiable_} {
|
||||
linkage.by_category[category].push_front(this);
|
||||
linkage.count++;
|
||||
}
|
||||
: BasicSetting(linkage, name, category_, save_, runtime_modifiable_), value{default_val},
|
||||
default_value{default_val} {}
|
||||
virtual ~Setting() = default;
|
||||
|
||||
/**
|
||||
|
@ -64,12 +54,8 @@ public:
|
|||
const Type& max_val, const std::string& name, enum Category category_,
|
||||
bool save_ = true, bool runtime_modifiable_ = false)
|
||||
requires(ranged)
|
||||
: value{default_val}, default_value{default_val}, maximum{max_val}, minimum{min_val},
|
||||
label{name}, category{category_}, id{linkage.count}, save{save_},
|
||||
runtime_modifiable{runtime_modifiable_} {
|
||||
linkage.by_category[category].push_front(this);
|
||||
linkage.count++;
|
||||
}
|
||||
: BasicSetting(linkage, name, category_, save_, runtime_modifiable_), value{default_val},
|
||||
default_value{default_val}, maximum{max_val}, minimum{min_val} {}
|
||||
|
||||
/**
|
||||
* Returns a reference to the setting's value.
|
||||
|
@ -99,41 +85,10 @@ public:
|
|||
return default_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label this setting was created with.
|
||||
*
|
||||
* @returns A reference to the label
|
||||
*/
|
||||
[[nodiscard]] const std::string& GetLabel() const override {
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the setting's category AKA INI group.
|
||||
*
|
||||
* @returns The setting's category
|
||||
*/
|
||||
[[nodiscard]] enum Category Category() const override {
|
||||
return category;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool RuntimeModfiable() const override {
|
||||
return runtime_modifiable;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool IsEnum() const override {
|
||||
return std::is_enum<Type>::value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current setting is Switchable.
|
||||
*
|
||||
* @returns If the setting is a SwitchableSetting
|
||||
*/
|
||||
[[nodiscard]] virtual constexpr bool Switchable() const override {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string ToString(const Type& value_) const {
|
||||
if constexpr (std::is_same<Type, std::string>()) {
|
||||
|
@ -227,16 +182,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the save preference of the setting i.e. when saving or reading the setting from a
|
||||
* frontend, whether this setting should be skipped.
|
||||
*
|
||||
* @returns The save preference
|
||||
*/
|
||||
virtual bool Save() const override {
|
||||
return save;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives us another way to identify the setting without having to go through a string.
|
||||
*
|
||||
|
@ -246,10 +191,6 @@ public:
|
|||
return std::type_index(typeid(Type));
|
||||
}
|
||||
|
||||
virtual constexpr u32 Id() const override {
|
||||
return id;
|
||||
}
|
||||
|
||||
virtual std::string MinVal() const override {
|
||||
return this->ToString(minimum);
|
||||
}
|
||||
|
@ -262,11 +203,6 @@ protected:
|
|||
const Type default_value{}; ///< The default value
|
||||
const Type maximum{}; ///< Maximum allowed value of the setting
|
||||
const Type minimum{}; ///< Minimum allowed value of the setting
|
||||
const std::string label{}; ///< The setting's label
|
||||
const enum Category category; ///< The setting's category AKA INI group
|
||||
const u32 id;
|
||||
bool save;
|
||||
bool runtime_modifiable;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue