1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
#ifndef COMPONENTS_SETTINGS_H
#define COMPONENTS_SETTINGS_H
#include "categories.hpp"
#include "gyroscopeaxis.hpp"
#include "hrtfmode.hpp"
#include "navmeshrendermode.hpp"
#include "windowmode.hpp"
#include <components/detournavigator/collisionshapetype.hpp>
#include <components/sceneutil/lightingmethod.hpp>
#include <components/sdlutil/vsyncmode.hpp>
#include <components/vfs/pathutil.hpp>
#include <filesystem>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include <osg/Vec2f>
#include <osg/Vec3f>
#include <MyGUI_Colour.h>
namespace Files
{
struct ConfigurationManager;
}
namespace Settings
{
///
/// \brief Settings management (can change during runtime)
///
class Manager
{
public:
static CategorySettingValueMap mDefaultSettings;
static CategorySettingValueMap mUserSettings;
static CategorySettingVector mChangedSettings;
///< tracks all the settings that were changed since the last apply() call
static void clear();
///< clears all settings and default settings
static std::filesystem::path load(const Files::ConfigurationManager& cfgMgr, bool loadEditorSettings = false);
///< load settings from all active config dirs. Returns the path of the last loaded file.
static void saveUser(const std::filesystem::path& file);
///< save user settings to file
static void resetPendingChanges();
///< resets the list of all pending changes
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
static int getInt(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 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);
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);
static std::vector<std::string> getStringArray(std::string_view setting, std::string_view category);
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);
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);
}
template <class T>
static T get(std::string_view setting, std::string_view category)
{
recordInit(setting, category);
return getImpl<T>(setting, category);
}
static void setInt(std::string_view setting, std::string_view category, int 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);
static void setStringArray(
std::string_view setting, std::string_view category, const std::vector<std::string>& value);
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);
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);
static void set(std::string_view setting, std::string_view category, DetourNavigator::CollisionShapeType value);
static void set(std::string_view setting, std::string_view category, const std::vector<std::string>& value);
static void set(std::string_view setting, std::string_view category, const MyGUI::Colour& value);
static void set(std::string_view setting, std::string_view category, SceneUtil::LightingMethod value);
static void set(std::string_view setting, std::string_view category, HrtfMode value);
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);
private:
static std::set<std::pair<std::string_view, std::string_view>> sInitialized;
template <class T>
static T getImpl(std::string_view setting, std::string_view category) = delete;
static void recordInit(std::string_view setting, std::string_view category);
};
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);
}
template <>
inline DetourNavigator::CollisionShapeType Manager::getImpl<DetourNavigator::CollisionShapeType>(
std::string_view setting, std::string_view category)
{
return DetourNavigator::toCollisionShapeType(getInt(setting, category));
}
template <>
inline std::vector<std::string> Manager::getImpl<std::vector<std::string>>(
std::string_view setting, std::string_view category)
{
return getStringArray(setting, category);
}
template <>
inline MyGUI::Colour Manager::getImpl<MyGUI::Colour>(std::string_view setting, std::string_view category)
{
return MyGUI::Colour::parse(getString(setting, category));
}
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));
}
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));
}
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));
}
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;
}
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);
}
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));
}
}
#endif // COMPONENTS_SETTINGS_H
|