2014-01-05 17:22:29 +00:00
|
|
|
#ifndef COMPONENTS_SETTINGS_H
|
|
|
|
#define COMPONENTS_SETTINGS_H
|
2012-03-30 16:38:33 +00:00
|
|
|
|
2019-09-29 14:16:19 +00:00
|
|
|
#include "categories.hpp"
|
2023-07-21 22:52:37 +00:00
|
|
|
#include "gyroscopeaxis.hpp"
|
2023-10-12 18:25:55 +00:00
|
|
|
#include "hrtfmode.hpp"
|
2023-10-01 08:36:18 +00:00
|
|
|
#include "navmeshrendermode.hpp"
|
2023-10-27 10:24:42 +00:00
|
|
|
#include "windowmode.hpp"
|
2019-09-29 14:16:19 +00:00
|
|
|
|
2023-10-08 11:58:49 +00:00
|
|
|
#include <components/detournavigator/collisionshapetype.hpp>
|
|
|
|
#include <components/sceneutil/lightingmethod.hpp>
|
2023-10-27 10:24:42 +00:00
|
|
|
#include <components/sdlutil/vsyncmode.hpp>
|
2024-08-18 18:48:22 +00:00
|
|
|
#include <components/vfs/pathutil.hpp>
|
2023-06-30 21:18:29 +00:00
|
|
|
|
2023-07-16 18:46:54 +00:00
|
|
|
#include <filesystem>
|
2022-06-18 00:46:47 +00:00
|
|
|
#include <set>
|
2015-02-02 23:53:30 +00:00
|
|
|
#include <string>
|
2022-06-18 00:44:56 +00:00
|
|
|
#include <string_view>
|
2022-07-25 04:19:01 +00:00
|
|
|
#include <vector>
|
2022-06-18 00:44:56 +00:00
|
|
|
|
2020-07-24 19:47:49 +00:00
|
|
|
#include <osg/Vec2f>
|
|
|
|
#include <osg/Vec3f>
|
2012-03-30 16:38:33 +00:00
|
|
|
|
2023-07-16 18:46:54 +00:00
|
|
|
#include <MyGUI_Colour.h>
|
|
|
|
|
2022-01-16 00:59:20 +00:00
|
|
|
namespace Files
|
|
|
|
{
|
|
|
|
struct ConfigurationManager;
|
|
|
|
}
|
|
|
|
|
2012-03-30 16:38:33 +00:00
|
|
|
namespace Settings
|
|
|
|
{
|
|
|
|
///
|
|
|
|
/// \brief Settings management (can change during runtime)
|
|
|
|
///
|
|
|
|
class Manager
|
|
|
|
{
|
|
|
|
public:
|
2015-02-02 23:53:30 +00:00
|
|
|
static CategorySettingValueMap mDefaultSettings;
|
|
|
|
static CategorySettingValueMap mUserSettings;
|
2012-03-30 16:38:33 +00:00
|
|
|
|
2012-04-01 16:48:37 +00:00
|
|
|
static CategorySettingVector mChangedSettings;
|
2012-04-01 14:26:42 +00:00
|
|
|
///< tracks all the settings that were changed since the last apply() call
|
|
|
|
|
2022-05-22 00:47:58 +00:00
|
|
|
static void clear();
|
2015-11-27 19:32:45 +00:00
|
|
|
///< clears all settings and default settings
|
|
|
|
|
2022-06-19 11:28:33 +00:00
|
|
|
static std::filesystem::path load(const Files::ConfigurationManager& cfgMgr, bool loadEditorSettings = false);
|
2022-01-16 00:59:20 +00:00
|
|
|
///< load settings from all active config dirs. Returns the path of the last loaded file.
|
2012-03-30 16:38:33 +00:00
|
|
|
|
2022-06-19 11:28:33 +00:00
|
|
|
static void saveUser(const std::filesystem::path& file);
|
2012-03-31 11:35:40 +00:00
|
|
|
///< save user settings to file
|
2012-03-30 16:38:33 +00:00
|
|
|
|
2019-05-04 17:38:36 +00:00
|
|
|
static void resetPendingChanges();
|
2021-11-30 16:00:30 +00:00
|
|
|
///< resets the list of all pending changes
|
2019-05-04 17:38:36 +00:00
|
|
|
|
2021-11-30 16:00:30 +00:00
|
|
|
static void resetPendingChanges(const CategorySettingVector& filter);
|
|
|
|
///< resets only the pending changes listed in the filter
|
|
|
|
|
|
|
|
static CategorySettingVector getPendingChanges();
|
|
|
|
///< returns the list of changed settings
|
|
|
|
|
|
|
|
static CategorySettingVector getPendingChanges(const CategorySettingVector& filter);
|
|
|
|
///< returns the list of changed settings intersecting with the filter
|
2012-04-01 14:26:42 +00:00
|
|
|
|
2022-06-18 00:44:56 +00:00
|
|
|
static int getInt(std::string_view setting, std::string_view category);
|
2022-10-03 22:02:53 +00:00
|
|
|
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);
|
2022-06-18 00:46:47 +00:00
|
|
|
static unsigned getUnsigned(std::string_view setting, std::string_view category);
|
|
|
|
static unsigned long getUnsignedLong(std::string_view setting, std::string_view category);
|
|
|
|
static unsigned long long getUnsignedLongLong(std::string_view setting, std::string_view category);
|
2022-06-18 00:44:56 +00:00
|
|
|
static float getFloat(std::string_view setting, std::string_view category);
|
|
|
|
static double getDouble(std::string_view setting, std::string_view category);
|
2022-08-28 14:38:11 +00:00
|
|
|
static const std::string& getString(std::string_view setting, std::string_view category);
|
2022-07-25 04:19:01 +00:00
|
|
|
static std::vector<std::string> getStringArray(std::string_view setting, std::string_view category);
|
2022-06-18 00:44:56 +00:00
|
|
|
static bool getBool(std::string_view setting, std::string_view category);
|
|
|
|
static osg::Vec2f getVector2(std::string_view setting, std::string_view category);
|
|
|
|
static osg::Vec3f getVector3(std::string_view setting, std::string_view category);
|
|
|
|
|
2023-11-15 07:14:16 +00:00
|
|
|
template <class T>
|
|
|
|
static T getOrDefault(std::string_view setting, std::string_view category, const T& defaultValue)
|
|
|
|
{
|
|
|
|
const auto key = std::make_pair(category, setting);
|
|
|
|
if (!mUserSettings.contains(key) && !mDefaultSettings.contains(key))
|
|
|
|
return defaultValue;
|
|
|
|
return get<T>(setting, category);
|
|
|
|
}
|
|
|
|
|
2022-06-18 00:46:47 +00:00
|
|
|
template <class T>
|
|
|
|
static T get(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
recordInit(setting, category);
|
|
|
|
return getImpl<T>(setting, category);
|
|
|
|
}
|
|
|
|
|
2022-06-18 00:44:56 +00:00
|
|
|
static void setInt(std::string_view setting, std::string_view category, int value);
|
2022-10-03 22:02:53 +00:00
|
|
|
static void setUInt64(std::string_view setting, std::string_view category, std::uint64_t value);
|
2022-06-18 00:44:56 +00:00
|
|
|
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);
|
2022-07-25 04:19:01 +00:00
|
|
|
static void setStringArray(
|
|
|
|
std::string_view setting, std::string_view category, const std::vector<std::string>& value);
|
2022-06-18 00:44:56 +00:00
|
|
|
static void setBool(std::string_view setting, std::string_view category, bool value);
|
|
|
|
static void setVector2(std::string_view setting, std::string_view category, osg::Vec2f value);
|
|
|
|
static void setVector3(std::string_view setting, std::string_view category, osg::Vec3f value);
|
2022-06-18 00:46:47 +00:00
|
|
|
|
|
|
|
static void set(std::string_view setting, std::string_view category, int value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, unsigned value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, unsigned long value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, unsigned long long value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, float value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, double value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, const std::string& value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, bool value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, const osg::Vec2f& value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, const osg::Vec3f& value);
|
2023-06-30 21:18:29 +00:00
|
|
|
static void set(std::string_view setting, std::string_view category, DetourNavigator::CollisionShapeType value);
|
2023-07-03 21:47:53 +00:00
|
|
|
static void set(std::string_view setting, std::string_view category, const std::vector<std::string>& value);
|
2023-07-16 18:46:54 +00:00
|
|
|
static void set(std::string_view setting, std::string_view category, const MyGUI::Colour& value);
|
2023-10-08 11:58:49 +00:00
|
|
|
static void set(std::string_view setting, std::string_view category, SceneUtil::LightingMethod value);
|
2023-10-12 18:25:55 +00:00
|
|
|
static void set(std::string_view setting, std::string_view category, HrtfMode value);
|
2023-10-27 10:24:42 +00:00
|
|
|
static void set(std::string_view setting, std::string_view category, WindowMode value);
|
|
|
|
static void set(std::string_view setting, std::string_view category, SDLUtil::VSyncMode value);
|
2022-06-18 00:46:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static std::set<std::pair<std::string_view, std::string_view>> sInitialized;
|
|
|
|
|
|
|
|
template <class T>
|
2023-07-03 21:47:53 +00:00
|
|
|
static T getImpl(std::string_view setting, std::string_view category) = delete;
|
2022-06-18 00:46:47 +00:00
|
|
|
|
|
|
|
static void recordInit(std::string_view setting, std::string_view category);
|
2012-03-30 16:38:33 +00:00
|
|
|
};
|
|
|
|
|
2022-06-18 00:46:47 +00:00
|
|
|
template <>
|
|
|
|
inline int Manager::getImpl<int>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getInt(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline unsigned Manager::getImpl<unsigned>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getUnsigned(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline unsigned long Manager::getImpl<unsigned long>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getUnsignedLong(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline unsigned long long Manager::getImpl<unsigned long long>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getUnsignedLongLong(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline float Manager::getImpl<float>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getFloat(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline double Manager::getImpl<double>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getDouble(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline std::string Manager::getImpl<std::string>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getString(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline bool Manager::getImpl<bool>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getBool(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline osg::Vec2f Manager::getImpl<osg::Vec2f>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getVector2(setting, category);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline osg::Vec3f Manager::getImpl<osg::Vec3f>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getVector3(setting, category);
|
|
|
|
}
|
2023-06-30 21:18:29 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
inline DetourNavigator::CollisionShapeType Manager::getImpl<DetourNavigator::CollisionShapeType>(
|
|
|
|
std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return DetourNavigator::toCollisionShapeType(getInt(setting, category));
|
|
|
|
}
|
2023-07-03 21:47:53 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
inline std::vector<std::string> Manager::getImpl<std::vector<std::string>>(
|
|
|
|
std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return getStringArray(setting, category);
|
|
|
|
}
|
2023-07-16 18:46:54 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
inline MyGUI::Colour Manager::getImpl<MyGUI::Colour>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return MyGUI::Colour::parse(getString(setting, category));
|
|
|
|
}
|
2023-07-21 22:52:37 +00:00
|
|
|
|
|
|
|
GyroscopeAxis parseGyroscopeAxis(std::string_view value);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline GyroscopeAxis Manager::getImpl<GyroscopeAxis>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return parseGyroscopeAxis(getString(setting, category));
|
|
|
|
}
|
2023-10-01 08:36:18 +00:00
|
|
|
|
|
|
|
NavMeshRenderMode parseNavMeshRenderMode(std::string_view value);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline NavMeshRenderMode Manager::getImpl<NavMeshRenderMode>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return parseNavMeshRenderMode(getString(setting, category));
|
|
|
|
}
|
2023-10-08 11:58:49 +00:00
|
|
|
|
|
|
|
SceneUtil::LightingMethod parseLightingMethod(std::string_view value);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline SceneUtil::LightingMethod Manager::getImpl<SceneUtil::LightingMethod>(
|
|
|
|
std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return parseLightingMethod(getString(setting, category));
|
|
|
|
}
|
2023-10-12 18:25:55 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
inline HrtfMode Manager::getImpl<HrtfMode>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
const int value = getInt(setting, category);
|
|
|
|
if (value < 0)
|
|
|
|
return HrtfMode::Auto;
|
|
|
|
if (value > 0)
|
|
|
|
return HrtfMode::Enable;
|
|
|
|
return HrtfMode::Disable;
|
|
|
|
}
|
2023-10-27 10:24:42 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
inline WindowMode Manager::getImpl<WindowMode>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
const int value = getInt(setting, category);
|
|
|
|
if (value < 0 || 2 < value)
|
|
|
|
return WindowMode::Fullscreen;
|
|
|
|
return static_cast<WindowMode>(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline SDLUtil::VSyncMode Manager::getImpl<SDLUtil::VSyncMode>(std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
const int value = getInt(setting, category);
|
|
|
|
if (value < 0 || 2 < value)
|
|
|
|
return SDLUtil::VSyncMode::Disabled;
|
|
|
|
return static_cast<SDLUtil::VSyncMode>(value);
|
|
|
|
}
|
2024-08-18 18:48:22 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
inline VFS::Path::Normalized Manager::getImpl<VFS::Path::Normalized>(
|
|
|
|
std::string_view setting, std::string_view category)
|
|
|
|
{
|
|
|
|
return VFS::Path::Normalized(getString(setting, category));
|
|
|
|
}
|
2012-03-30 16:38:33 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:00:30 +00:00
|
|
|
#endif // COMPONENTS_SETTINGS_H
|