From 7ba460552c89e88b757a7432aabeccc0f7c39ba3 Mon Sep 17 00:00:00 2001 From: gibbed Date: Sun, 4 Aug 2019 02:12:46 -0500 Subject: [PATCH] [Base/Core] Add support for transient cvars. --- src/xenia/base/cvar.h | 48 ++++++++++++++++++++++++++++--------------- src/xenia/config.cc | 3 +++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/xenia/base/cvar.h b/src/xenia/base/cvar.h index 4661671d9..447128c36 100644 --- a/src/xenia/base/cvar.h +++ b/src/xenia/base/cvar.h @@ -20,6 +20,7 @@ class ICommandVar { class IConfigVar : virtual public ICommandVar { public: virtual std::string GetCategory() = 0; + virtual bool GetIsTransient() = 0; virtual std::string GetConfigValue() = 0; virtual void LoadConfigValue(std::shared_ptr result) = 0; virtual void LoadGameConfigValue(std::shared_ptr result) = 0; @@ -53,9 +54,10 @@ template class ConfigVar : public CommandVar, virtual public IConfigVar { public: ConfigVar(const char* name, T* defaultValue, const char* description, - const char* category); + const char* category, bool is_transient); std::string GetConfigValue() override; std::string GetCategory() override; + bool GetIsTransient() override; void AddToLaunchOptions(cxxopts::Options* options) override; void LoadConfigValue(std::shared_ptr result) override; void LoadGameConfigValue(std::shared_ptr result) override; @@ -64,6 +66,7 @@ class ConfigVar : public CommandVar, virtual public IConfigVar { private: std::string category_; + bool is_transient_; std::unique_ptr configValue_ = nullptr; std::unique_ptr gameConfigValue_ = nullptr; void UpdateValue() override; @@ -110,8 +113,11 @@ CommandVar::CommandVar(const char* name, T* defaultValue, template ConfigVar::ConfigVar(const char* name, T* defaultValue, - const char* description, const char* category) - : CommandVar(name, defaultValue, description), category_(category) {} + const char* description, const char* category, + bool is_transient) + : CommandVar(name, defaultValue, description), + category_(category), + is_transient_(is_transient) {} template void CommandVar::UpdateValue() { @@ -157,6 +163,10 @@ std::string ConfigVar::GetCategory() { return category_; } template +bool ConfigVar::GetIsTransient() { + return is_transient_; +} +template std::string ConfigVar::GetConfigValue() { if (this->configValue_) return this->ToString(*this->configValue_); return this->ToString(this->defaultValue_); @@ -192,9 +202,9 @@ void ParseLaunchArguments(int argc, char** argv); template T* define_configvar(const char* name, T* defaultValue, const char* description, - const char* category) { + const char* category, bool is_transient) { IConfigVar* cfgVar = - new ConfigVar(name, defaultValue, description, category); + new ConfigVar(name, defaultValue, description, category, is_transient); AddConfigVar(cfgVar); return defaultValue; } @@ -206,27 +216,31 @@ T* define_cmdvar(const char* name, T* defaultValue, const char* description) { return defaultValue; } #define DEFINE_double(name, defaultValue, description, category) \ - DEFINE_CVar(name, defaultValue, description, category, double) + DEFINE_CVar(name, defaultValue, description, category, false, double) #define DEFINE_int32(name, defaultValue, description, category) \ - DEFINE_CVar(name, defaultValue, description, category, int32_t) + DEFINE_CVar(name, defaultValue, description, category, false, int32_t) #define DEFINE_uint64(name, defaultValue, description, category) \ - DEFINE_CVar(name, defaultValue, description, category, uint64_t) + DEFINE_CVar(name, defaultValue, description, category, false, uint64_t) #define DEFINE_string(name, defaultValue, description, category) \ - DEFINE_CVar(name, defaultValue, description, category, std::string) + DEFINE_CVar(name, defaultValue, description, category, false, std::string) + +#define DEFINE_transient_string(name, defaultValue, description, category) \ + DEFINE_CVar(name, defaultValue, description, category, true, std::string) #define DEFINE_bool(name, defaultValue, description, category) \ - DEFINE_CVar(name, defaultValue, description, category, bool) + DEFINE_CVar(name, defaultValue, description, category, false, bool) -#define DEFINE_CVar(name, defaultValue, description, category, type) \ - namespace cvars { \ - type name = defaultValue; \ - } \ - namespace cv { \ - static auto cv_##name = \ - cvar::define_configvar(#name, &cvars::name, description, category); \ +#define DEFINE_CVar(name, defaultValue, description, category, is_transient, \ + type) \ + namespace cvars { \ + type name = defaultValue; \ + } \ + namespace cv { \ + static auto cv_##name = cvar::define_configvar( \ + #name, &cvars::name, description, category, is_transient); \ } // CmdVars can only be strings for now, we don't need any others diff --git a/src/xenia/config.cc b/src/xenia/config.cc index 210813f54..e0de33ec7 100644 --- a/src/xenia/config.cc +++ b/src/xenia/config.cc @@ -61,6 +61,9 @@ void SaveConfig() { std::ostringstream output; std::string lastCategory; for (auto configVar : vars) { + if (configVar->GetIsTransient()) { + continue; + } if (lastCategory != configVar->GetCategory()) { if (!lastCategory.empty()) { output << std::endl;