Merge branch 'unsigned_settings' into 'master'

Support unsigned settings values

See merge request OpenMW/openmw!2453
focus_on_focal
psi29a 2 years ago
commit bfa303f73b

@ -93,8 +93,7 @@ namespace Launcher
int getMaxNavMeshDbFileSizeMiB()
{
return static_cast<int>(
Settings::Manager::getInt64("max navmeshdb file size", "Navigator") / (1024 * 1024));
return Settings::Manager::getUInt64("max navmeshdb file size", "Navigator") / (1024 * 1024);
}
}
}
@ -318,8 +317,8 @@ QStringList Launcher::DataFilesPage::filesInProfile(const QString& profileName,
void Launcher::DataFilesPage::saveSettings(const QString& profile)
{
if (const int value = ui.navMeshMaxSizeSpinBox->value(); value != getMaxNavMeshDbFileSizeMiB())
Settings::Manager::setInt64(
"max navmeshdb file size", "Navigator", static_cast<std::int64_t>(value) * 1024 * 1024);
Settings::Manager::setUInt64(
"max navmeshdb file size", "Navigator", static_cast<std::uint64_t>(std::max(0, value)) * 1024 * 1024);
QString profileName = profile;

@ -196,8 +196,7 @@ namespace NavMeshTool
const osg::Vec3f agentHalfExtents
= Settings::Manager::getVector3("default actor pathfind half extents", "Game");
const DetourNavigator::AgentBounds agentBounds{ agentCollisionShape, agentHalfExtents };
const std::uint64_t maxDbFileSize
= static_cast<std::uint64_t>(Settings::Manager::getInt64("max navmeshdb file size", "Navigator"));
const std::uint64_t maxDbFileSize = Settings::Manager::getUInt64("max navmeshdb file size", "Navigator");
const auto dbPath = Files::pathToUnicodeString(config.getUserDataPath() / "navmesh.db");
DetourNavigator::NavMeshDb db(dbPath, maxDbFileSize);

@ -123,7 +123,7 @@ namespace MWGui
void DebugWindow::startLogRecording()
{
sLogCircularBuffer.resize(std::max<int64_t>(0, Settings::Manager::getInt64("log buffer size", "General")));
sLogCircularBuffer.resize(Settings::Manager::getSize("log buffer size", "General"));
Debug::setLogListener([](Debug::Level level, std::string_view prefix, std::string_view msg) {
if (sLogCircularBuffer.empty())
return; // Log viewer is disabled.

@ -43,10 +43,8 @@ namespace DetourNavigator
= std::clamp(::Settings::Manager::getInt("max nav mesh query nodes", "Navigator"), 1, 65535);
result.mMaxPolys
= std::clamp(::Settings::Manager::getInt("max polygons per tile", "Navigator"), 1, (1 << 22) - 1);
result.mMaxPolygonPathSize
= static_cast<std::size_t>(std::max(0, ::Settings::Manager::getInt("max polygon path size", "Navigator")));
result.mMaxSmoothPathSize
= static_cast<std::size_t>(std::max(0, ::Settings::Manager::getInt("max smooth path size", "Navigator")));
result.mMaxPolygonPathSize = ::Settings::Manager::getSize("max polygon path size", "Navigator");
result.mMaxSmoothPathSize = ::Settings::Manager::getSize("max smooth path size", "Navigator");
return result;
}
@ -60,10 +58,9 @@ namespace DetourNavigator
result.mMaxTilesNumber = std::max(0, ::Settings::Manager::getInt("max tiles number", "Navigator"));
result.mWaitUntilMinDistanceToPlayer
= ::Settings::Manager::getInt("wait until min distance to player", "Navigator");
result.mAsyncNavMeshUpdaterThreads = static_cast<std::size_t>(
std::max(0, ::Settings::Manager::getInt("async nav mesh updater threads", "Navigator")));
result.mMaxNavMeshTilesCacheSize = static_cast<std::size_t>(
std::max(std::int64_t{ 0 }, ::Settings::Manager::getInt64("max nav mesh tiles cache size", "Navigator")));
result.mAsyncNavMeshUpdaterThreads
= ::Settings::Manager::getSize("async nav mesh updater threads", "Navigator");
result.mMaxNavMeshTilesCacheSize = ::Settings::Manager::getSize("max nav mesh tiles cache size", "Navigator");
result.mEnableWriteRecastMeshToFile
= ::Settings::Manager::getBool("enable write recast mesh to file", "Navigator");
result.mEnableWriteNavMeshToFile = ::Settings::Manager::getBool("enable write nav mesh to file", "Navigator");
@ -77,8 +74,7 @@ namespace DetourNavigator
= std::chrono::milliseconds(::Settings::Manager::getInt("min update interval ms", "Navigator"));
result.mEnableNavMeshDiskCache = ::Settings::Manager::getBool("enable nav mesh disk cache", "Navigator");
result.mWriteToNavMeshDb = ::Settings::Manager::getBool("write to navmeshdb", "Navigator");
result.mMaxDbFileSize
= static_cast<std::uint64_t>(::Settings::Manager::getInt64("max navmeshdb file size", "Navigator"));
result.mMaxDbFileSize = ::Settings::Manager::getUInt64("max navmeshdb file size", "Navigator");
return result;
}

@ -1,14 +1,44 @@
#include "settings.hpp"
#include "parser.hpp"
#include <cerrno>
#include <charconv>
#include <filesystem>
#include <sstream>
#include <system_error>
#include <components/files/configurationmanager.hpp>
#include <components/misc/strings/algorithm.hpp>
namespace Settings
{
namespace
{
template <class T>
auto parseIntegralNumber(const std::string& value, std::string_view setting, std::string_view category)
{
T number{};
const auto result = std::from_chars(value.data(), value.data() + value.size(), number);
if (result.ec != std::errc())
throw std::system_error(std::make_error_code(result.ec),
"Failed to parse number from setting [" + std::string(category) + "] " + std::string(setting)
+ " value \"" + value + "\"");
return number;
}
template <class T>
auto parseFloatingPointNumber(const std::string& value, std::string_view setting, std::string_view category)
{
std::stringstream stream(value);
T number{};
stream >> number;
if (stream.bad())
throw std::system_error(errno, std::generic_category(),
"Failed to parse number from setting [" + std::string(category) + "] " + std::string(setting)
+ " value \"" + value + "\"");
return number;
}
}
CategorySettingValueMap Manager::mDefaultSettings = CategorySettingValueMap();
CategorySettingValueMap Manager::mUserSettings = CategorySettingValueMap();
@ -109,38 +139,27 @@ namespace Settings
float Manager::getFloat(std::string_view setting, std::string_view category)
{
const std::string& value = getString(setting, category);
std::stringstream stream(value);
float number = 0.f;
stream >> number;
return number;
return parseFloatingPointNumber<float>(getString(setting, category), setting, category);
}
double Manager::getDouble(std::string_view setting, std::string_view category)
{
const std::string& value = getString(setting, category);
std::stringstream stream(value);
double number = 0.0;
stream >> number;
return number;
return parseFloatingPointNumber<double>(getString(setting, category), setting, category);
}
int Manager::getInt(std::string_view setting, std::string_view category)
{
const std::string& value = getString(setting, category);
std::stringstream stream(value);
int number = 0;
stream >> number;
return number;
return parseIntegralNumber<int>(getString(setting, category), setting, category);
}
std::int64_t Manager::getInt64(std::string_view setting, std::string_view category)
std::uint64_t Manager::getUInt64(std::string_view setting, std::string_view category)
{
const std::string& value = getString(setting, category);
std::stringstream stream(value);
std::int64_t number = 0;
stream >> number;
return number;
return parseIntegralNumber<std::uint64_t>(getString(setting, category), setting, category);
}
std::size_t Manager::getSize(std::string_view setting, std::string_view category)
{
return parseIntegralNumber<std::size_t>(getString(setting, category), setting, category);
}
bool Manager::getBool(std::string_view setting, std::string_view category)
@ -213,7 +232,7 @@ namespace Settings
setString(setting, category, stream.str());
}
void Manager::setInt64(std::string_view setting, std::string_view category, const std::int64_t value)
void Manager::setUInt64(std::string_view setting, std::string_view category, const std::uint64_t value)
{
std::ostringstream stream;
stream << value;

@ -61,7 +61,8 @@ namespace Settings
///< returns the list of changed settings intersecting with the filter
static int getInt(std::string_view setting, std::string_view category);
static std::int64_t getInt64(std::string_view setting, std::string_view category);
static std::uint64_t getUInt64(std::string_view setting, std::string_view category);
static std::size_t getSize(std::string_view setting, std::string_view category);
static float getFloat(std::string_view setting, std::string_view category);
static double getDouble(std::string_view setting, std::string_view category);
static const std::string& getString(std::string_view setting, std::string_view category);
@ -71,7 +72,7 @@ namespace Settings
static osg::Vec3f getVector3(std::string_view setting, std::string_view category);
static void setInt(std::string_view setting, std::string_view category, int value);
static void setInt64(std::string_view setting, std::string_view category, std::int64_t value);
static void setUInt64(std::string_view setting, std::string_view category, std::uint64_t value);
static void setFloat(std::string_view setting, std::string_view category, float value);
static void setDouble(std::string_view setting, std::string_view category, double value);
static void setString(std::string_view setting, std::string_view category, const std::string& value);

@ -90,7 +90,7 @@ Two highest priority locales may be assigned via the Localization tab of the in-
log buffer size
---------------
:Type: integer
:Type: platform dependant unsigned integer
:Range: >= 0
:Default: 65536

@ -77,7 +77,7 @@ If true generated navmesh tiles will be stored into disk cache while game is run
max navmeshdb file size
-----------------------
:Type: integer
:Type: unsigned 64-bit integer
:Range: > 0
:Default: 2147483648
@ -91,7 +91,7 @@ This section is for advanced PC uses who understands concepts of OS thread and m
async nav mesh updater threads
------------------------------
:Type: integer
:Type: platform dependant unsigned integer
:Range: >= 1
:Default: 1
@ -103,7 +103,7 @@ Don't expect twice better latency by doubling this value.
max nav mesh tiles cache size
-----------------------------
:Type: integer
:Type: platform dependant unsigned integer
:Range: >= 0
:Default: 268435456
@ -279,7 +279,7 @@ Pay attention to slopes and roofs when change it. Increasing this value will red
max polygon path size
---------------------
:Type: integer
:Type: platform dependant unsigned integer
:Range: > 0
:Default: 1024
@ -288,7 +288,7 @@ Maximum size of path over polygons.
max smooth path size
--------------------
:Type: integer
:Type: platform dependant unsigned integer
:Range: > 0
:Default: 1024

Loading…
Cancel
Save