Skip to content

Commit

Permalink
Reduced warning spam from missing options.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Jul 28, 2024
1 parent 78ce657 commit 01d241a
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions OpenTESArena/src/Game/Options.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <algorithm>
#include <fstream>
#include <sstream>
#include <unordered_set>

#include "Options.h"
#include "../Utilities/Platform.h"
Expand Down Expand Up @@ -59,6 +60,13 @@ namespace
{ Options::Key_Misc_StarDensity, Options::OptionType_Misc_StarDensity },
{ Options::Key_Misc_PlayerHasLight, Options::OptionType_Misc_PlayerHasLight }
};

std::unordered_set<std::string> s_loggedMissingOptions; // Reduces log spam.

std::string MakeLoggingKey(const std::string &section, const std::string &key)
{
return section + "_" + key;
}
}

// The "default" options file is shipped with releases, and it resides in the options
Expand Down Expand Up @@ -228,7 +236,13 @@ bool Options::getBool(const std::string &section, const std::string &key) const
}
else
{
DebugLogWarning("Boolean \"" + key + "\" (section \"" + section + "\") not in options, defaulting to false.");
std::string loggingKey = MakeLoggingKey(section, key);
if (!s_loggedMissingOptions.contains(loggingKey))
{
s_loggedMissingOptions.emplace(loggingKey);
DebugLogWarning("Expected \"" + key + "\" boolean under [" + section + "] in defaults or changes, defaulting to false and silencing warning.");
}

return false;
}
}
Expand Down Expand Up @@ -269,7 +283,13 @@ int Options::getInt(const std::string &section, const std::string &key) const
}
else
{
DebugLogWarning("Integer \"" + key + "\" (section \"" + section + "\") not in options, defaulting to 0.");
std::string loggingKey = MakeLoggingKey(section, key);
if (!s_loggedMissingOptions.contains(loggingKey))
{
s_loggedMissingOptions.emplace(loggingKey);
DebugLogWarning("Expected \"" + key + "\" integer under [" + section + "] in defaults or changes, defaulting to 0 and silencing warning.");
}

return 0;
}
}
Expand Down Expand Up @@ -310,7 +330,13 @@ double Options::getDouble(const std::string &section, const std::string &key) co
}
else
{
DebugLogWarning("Double \"" + key + "\" (section \"" + section + "\") not in options, defaulting to 0.");
std::string loggingKey = MakeLoggingKey(section, key);
if (!s_loggedMissingOptions.contains(loggingKey))
{
s_loggedMissingOptions.emplace(loggingKey);
DebugLogWarning("Expected \"" + key + "\" decimal value under [" + section + "] in defaults or changes, defaulting to 0 and silencing warning.");
}

return 0.0;
}
}
Expand Down Expand Up @@ -351,7 +377,13 @@ const std::string &Options::getString(const std::string &section, const std::str
}
else
{
DebugLogWarning("String \"" + key + "\" (section \"" + section + "\") not in options, defaulting to \"\".");
std::string loggingKey = MakeLoggingKey(section, key);
if (!s_loggedMissingOptions.contains(loggingKey))
{
s_loggedMissingOptions.emplace(loggingKey);
DebugLogWarning("Expected \"" + key + "\" string under [" + section + "] in defaults or changes, defaulting to \"\" and silencing warning.");
}

static const std::string fallbackString;
return fallbackString;
}
Expand Down

0 comments on commit 01d241a

Please sign in to comment.