From 7ff88d4bedc217331e68299a907898e656de7a9c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Jun 2019 12:15:31 -0700 Subject: [PATCH] Core: Save GPU backend as identifier. Still reads in old number values. This way it's easier for someone to follow instructions to fix the backend if necessary due to driver crashes. --- Core/Config.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 8c52116987..7e64c202b9 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -120,6 +120,13 @@ struct ConfigSetting { default_.i = def; } + ConfigSetting(const char *ini, int *v, int def, std::function transTo, std::function transFrom, bool save = true, bool perGame = false) + : ini_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame), translateTo_(transTo), translateFrom_(transFrom) { + ptr_.i = v; + cb_.i = nullptr; + default_.i = def; + } + ConfigSetting(const char *ini, uint32_t *v, uint32_t def, bool save = true, bool perGame = false) : ini_(ini), type_(TYPE_UINT32), report_(false), save_(save), perGame_(perGame) { ptr_.u = v; @@ -160,6 +167,12 @@ struct ConfigSetting { cb_.i = def; } + ConfigSetting(const char *ini, int *v, IntDefaultCallback def, std::function transTo, std::function transFrom, bool save = true, bool perGame = false) + : ini_(ini), type_(TYPE_INT), report_(false), save_(save), perGame_(perGame), translateTo_(transTo), translateFrom_(transFrom) { + ptr_.i = v; + cb_.i = def; + } + ConfigSetting(const char *ini, uint32_t *v, Uint32DefaultCallback def, bool save = true, bool perGame = false) : ini_(ini), type_(TYPE_UINT32), report_(false), save_(save), perGame_(perGame) { ptr_ .u = v; @@ -199,6 +212,13 @@ struct ConfigSetting { if (cb_.i) { default_.i = cb_.i(); } + if (translateFrom_) { + std::string value; + if (section->Get(ini_, &value, nullptr)) { + *ptr_.i = translateFrom_(value); + return true; + } + } return section->Get(ini_, ptr_.i, default_.i); case TYPE_UINT32: if (cb_.u) { @@ -242,6 +262,10 @@ struct ConfigSetting { case TYPE_BOOL: return section->Set(ini_, *ptr_.b); case TYPE_INT: + if (translateTo_) { + std::string value = translateTo_(*ptr_.i); + return section->Set(ini_, value); + } return section->Set(ini_, *ptr_.i); case TYPE_UINT32: return section->Set(ini_, *ptr_.u); @@ -298,6 +322,10 @@ struct ConfigSetting { SettingPtr ptr_; Value default_; Callback cb_; + + // We only support transform for ints. + std::function translateTo_; + std::function translateFrom_; }; struct ReportedConfigSetting : public ConfigSetting { @@ -306,6 +334,12 @@ struct ReportedConfigSetting : public ConfigSetting { : ConfigSetting(ini, v, def, save, perGame) { report_ = true; } + + template + ReportedConfigSetting(const char *ini, T1 *v, T2 def, std::function transTo, std::function transFrom, bool save = true, bool perGame = false) + : ConfigSetting(ini, v, def, transTo, transFrom, save, perGame) { + report_ = true; + } }; const char *DefaultLangRegion() { @@ -642,13 +676,26 @@ static bool DefaultVertexCache() { return DefaultGPUBackend() == (int)GPUBackend::OPENGL; } +template +struct ConfigTranslator { + static std::string To(int v) { + return FTo(T(v)); + } + + static int From(const std::string &v) { + return (int)FFrom(v); + } +}; + +typedef ConfigTranslator GPUBackendTranslator; + static ConfigSetting graphicsSettings[] = { ConfigSetting("EnableCardboard", &g_Config.bEnableCardboard, false, true, true), ConfigSetting("CardboardScreenSize", &g_Config.iCardboardScreenSize, 50, true, true), ConfigSetting("CardboardXShift", &g_Config.iCardboardXShift, 0, true, true), ConfigSetting("CardboardYShift", &g_Config.iCardboardXShift, 0, true, true), ConfigSetting("ShowFPSCounter", &g_Config.iShowFPSCounter, 0, true, true), - ReportedConfigSetting("GraphicsBackend", &g_Config.iGPUBackend, &DefaultGPUBackend), + ReportedConfigSetting("GraphicsBackend", &g_Config.iGPUBackend, &DefaultGPUBackend, &GPUBackendTranslator::To, &GPUBackendTranslator::From, true, false), ConfigSetting("FailedGraphicsBackends", &g_Config.sFailedGPUBackends, ""), ConfigSetting("DisabledGraphicsBackends", &g_Config.sDisabledGPUBackends, ""), ConfigSetting("VulkanDevice", &g_Config.sVulkanDevice, "", true, false),