mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-26 06:16:24 -04:00
Revert "Move RegisteredConfigVars to function-local static"
This reverts commit ea09dd73c6.
This commit is contained in:
+9
-16
@@ -23,13 +23,9 @@ using json = nlohmann::json;
|
||||
|
||||
aurora::Module DuskConfigLog("dusk::config");
|
||||
|
||||
static absl::flat_hash_map<std::string_view, ConfigVarBase*> RegisteredConfigVars;
|
||||
static bool RegistrationDone = false;
|
||||
|
||||
static absl::flat_hash_map<std::string_view, ConfigVarBase*>& registered_config_vars() {
|
||||
static absl::flat_hash_map<std::string_view, ConfigVarBase*> vars;
|
||||
return vars;
|
||||
}
|
||||
|
||||
static std::filesystem::path GetConfigJsonPath() {
|
||||
return dusk::ConfigPath / ConfigFileName;
|
||||
}
|
||||
@@ -215,17 +211,16 @@ namespace dusk::config {
|
||||
}
|
||||
|
||||
void dusk::config::Register(ConfigVarBase& configVar) {
|
||||
auto& registeredConfigVars = registered_config_vars();
|
||||
const auto& name = configVar.getName();
|
||||
if (RegistrationDone) {
|
||||
DuskConfigLog.fatal("Tried to register CVar {} after registrations closed!", name);
|
||||
}
|
||||
|
||||
if (registeredConfigVars.contains(name)) {
|
||||
if (RegisteredConfigVars.contains(name)) {
|
||||
DuskConfigLog.fatal("Tried to register CVar {} twice!", name);
|
||||
}
|
||||
|
||||
registeredConfigVars[name] = &configVar;
|
||||
RegisteredConfigVars[name] = &configVar;
|
||||
configVar.markRegistered();
|
||||
}
|
||||
|
||||
@@ -250,7 +245,6 @@ void dusk::config::LoadFromUserPreferences() {
|
||||
}
|
||||
|
||||
static void LoadFromPath(const char* path) {
|
||||
auto& registeredConfigVars = registered_config_vars();
|
||||
auto data = dusk::io::FileStream::ReadAllBytes(path);
|
||||
|
||||
json j = json::parse(data);
|
||||
@@ -261,8 +255,8 @@ static void LoadFromPath(const char* path) {
|
||||
|
||||
for (const auto& el : j.items()) {
|
||||
const auto& key = el.key();
|
||||
auto configVar = registeredConfigVars.find(key);
|
||||
if (configVar == registeredConfigVars.end()) {
|
||||
auto configVar = RegisteredConfigVars.find(key);
|
||||
if (configVar == RegisteredConfigVars.end()) {
|
||||
DuskConfigLog.error("Unknown key '{}' found in config!", key);
|
||||
continue;
|
||||
}
|
||||
@@ -310,7 +304,7 @@ void dusk::config::Save() {
|
||||
|
||||
json j;
|
||||
|
||||
for (const auto& pair : registered_config_vars()) {
|
||||
for (const auto& pair : RegisteredConfigVars) {
|
||||
const auto layer = pair.second->getLayer();
|
||||
if (layer == ConfigVarLayer::Value || layer == ConfigVarLayer::Speedrun) {
|
||||
j[pair.first] = pair.second->getImpl()->dumpToJson(*pair.second);
|
||||
@@ -334,9 +328,8 @@ void dusk::config::ClearAllActionBindings(int port) {
|
||||
}
|
||||
|
||||
ConfigVarBase* dusk::config::GetConfigVar(std::string_view name) {
|
||||
auto& registeredConfigVars = registered_config_vars();
|
||||
const auto configVar = registeredConfigVars.find(name);
|
||||
if (configVar != registeredConfigVars.end()) {
|
||||
const auto configVar = RegisteredConfigVars.find(name);
|
||||
if (configVar != RegisteredConfigVars.end()) {
|
||||
return configVar->second;
|
||||
}
|
||||
|
||||
@@ -344,7 +337,7 @@ ConfigVarBase* dusk::config::GetConfigVar(std::string_view name) {
|
||||
}
|
||||
|
||||
void dusk::config::EnumerateRegistered(std::function<void(ConfigVarBase&)> callback) {
|
||||
for (auto& pair : registered_config_vars()) {
|
||||
for (auto& pair : RegisteredConfigVars) {
|
||||
callback(*pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user