mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-26 12:21:39 +00:00
config: implement read callbacks
This commit is contained in:
parent
438a315e5b
commit
dd59190347
3 changed files with 25 additions and 8 deletions
|
|
@ -11,8 +11,6 @@ void Config::Load()
|
||||||
{
|
{
|
||||||
printf("Failed to parse configuration: %s\n", err.what());
|
printf("Failed to parse configuration: %s\n", err.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolutionScale = std::clamp(ResolutionScale.Value, 0.25f, 2.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::Save()
|
void Config::Save()
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,12 @@ public:
|
||||||
CONFIG_DEFINE("Video", EGraphicsAPI, GraphicsAPI, EGraphicsAPI_D3D12);
|
CONFIG_DEFINE("Video", EGraphicsAPI, GraphicsAPI, EGraphicsAPI_D3D12);
|
||||||
CONFIG_DEFINE("Video", size_t, WindowWidth, 1280);
|
CONFIG_DEFINE("Video", size_t, WindowWidth, 1280);
|
||||||
CONFIG_DEFINE("Video", size_t, WindowHeight, 720);
|
CONFIG_DEFINE("Video", size_t, WindowHeight, 720);
|
||||||
CONFIG_DEFINE("Video", float, ResolutionScale, 1.0f);
|
|
||||||
|
CONFIG_DEFINE_CALLBACK("Video", float, ResolutionScale, 1.0f,
|
||||||
|
{
|
||||||
|
def->Value = std::clamp(def->Value, 0.25f, 2.0f);
|
||||||
|
});
|
||||||
|
|
||||||
CONFIG_DEFINE("Video", bool, Fullscreen, false);
|
CONFIG_DEFINE("Video", bool, Fullscreen, false);
|
||||||
CONFIG_DEFINE("Video", bool, VSync, true);
|
CONFIG_DEFINE("Video", bool, VSync, true);
|
||||||
CONFIG_DEFINE("Video", size_t, BufferCount, 3);
|
CONFIG_DEFINE("Video", size_t, BufferCount, 3);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,11 @@
|
||||||
|
|
||||||
#define TOML_FILE "config.toml"
|
#define TOML_FILE "config.toml"
|
||||||
|
|
||||||
#define CONFIG_DEFINE(section, type, name, defaultValue) inline static ConfigDef<type> name{section, #name, defaultValue};
|
#define CONFIG_DEFINE(section, type, name, defaultValue) \
|
||||||
#define CONFIG_VALUE(name) Config::name.Value
|
inline static ConfigDef<type> name{section, #name, defaultValue};
|
||||||
|
|
||||||
|
#define CONFIG_DEFINE_CALLBACK(section, type, name, defaultValue, readCallback) \
|
||||||
|
inline static ConfigDef<type> name{section, #name, defaultValue, [](ConfigDef<type>* def) readCallback};
|
||||||
|
|
||||||
#define CONFIG_GET_DEFAULT(name) Config::name.DefaultValue
|
#define CONFIG_GET_DEFAULT(name) Config::name.DefaultValue
|
||||||
#define CONFIG_SET_DEFAULT(name) Config::name.MakeDefault();
|
#define CONFIG_SET_DEFAULT(name) Config::name.MakeDefault();
|
||||||
|
|
@ -26,12 +29,20 @@ template<typename T>
|
||||||
class ConfigDef : public ConfigDefBase
|
class ConfigDef : public ConfigDefBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string Section;
|
std::string Section{};
|
||||||
std::string Name;
|
std::string Name{};
|
||||||
T DefaultValue{};
|
T DefaultValue{};
|
||||||
T Value{ DefaultValue };
|
T Value{ DefaultValue };
|
||||||
|
std::function<void(ConfigDef<T>*)> ReadCallback;
|
||||||
|
|
||||||
ConfigDef(std::string section, std::string name, T defaultValue) : Section(section), Name(name), DefaultValue(defaultValue)
|
ConfigDef(std::string section, std::string name, T defaultValue)
|
||||||
|
: Section(section), Name(name), DefaultValue(defaultValue)
|
||||||
|
{
|
||||||
|
Config::Definitions.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T>*)> readCallback)
|
||||||
|
: Section(section), Name(name), DefaultValue(defaultValue), ReadCallback(readCallback)
|
||||||
{
|
{
|
||||||
Config::Definitions.emplace_back(this);
|
Config::Definitions.emplace_back(this);
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +62,9 @@ public:
|
||||||
Value = section[Name].value_or(DefaultValue);
|
Value = section[Name].value_or(DefaultValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ReadCallback)
|
||||||
|
ReadCallback(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakeDefault() override
|
void MakeDefault() override
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue