mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-29 03:36:40 +00:00
Support reload for settings values
Convert local static variables into unique_ptr static members of StaticValues. Add clear member function to reset them. Use it when settings have to be reloaded.
This commit is contained in:
parent
d84caff94d
commit
ebfcb661ee
3 changed files with 24 additions and 13 deletions
|
@ -128,6 +128,8 @@ namespace Settings
|
||||||
|
|
||||||
void Manager::clear()
|
void Manager::clear()
|
||||||
{
|
{
|
||||||
|
sInitialized.clear();
|
||||||
|
StaticValues::clear();
|
||||||
mDefaultSettings.clear();
|
mDefaultSettings.clear();
|
||||||
mUserSettings.clear();
|
mUserSettings.clear();
|
||||||
mChangedSettings.clear();
|
mChangedSettings.clear();
|
||||||
|
|
|
@ -4,24 +4,29 @@
|
||||||
|
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
Index* StaticValues::sIndex = nullptr;
|
std::unique_ptr<Index> StaticValues::sIndex;
|
||||||
Values* StaticValues::sValues = nullptr;
|
std::unique_ptr<Values> StaticValues::sDefaultValues;
|
||||||
|
std::unique_ptr<Values> StaticValues::sValues;
|
||||||
|
|
||||||
void StaticValues::initDefaults()
|
void StaticValues::initDefaults()
|
||||||
{
|
{
|
||||||
if (sValues != nullptr)
|
if (sDefaultValues != nullptr)
|
||||||
throw std::logic_error("Default settings already initialized");
|
throw std::logic_error("Default settings are already initialized");
|
||||||
static Index index;
|
sIndex = std::make_unique<Index>();
|
||||||
static Values values(index);
|
sDefaultValues = std::make_unique<Values>(*sIndex);
|
||||||
sIndex = &index;
|
|
||||||
sValues = &values;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticValues::init()
|
void StaticValues::init()
|
||||||
{
|
{
|
||||||
if (sValues == nullptr)
|
if (sDefaultValues == nullptr)
|
||||||
throw std::logic_error("Default settings are not initialized");
|
throw std::logic_error("Default settings are not initialized");
|
||||||
static Values values(std::move(*sValues));
|
sValues = std::make_unique<Values>(std::move(*sDefaultValues));
|
||||||
sValues = &values;
|
}
|
||||||
|
|
||||||
|
void StaticValues::clear()
|
||||||
|
{
|
||||||
|
sValues = nullptr;
|
||||||
|
sDefaultValues = nullptr;
|
||||||
|
sIndex = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "settingvalue.hpp"
|
#include "settingvalue.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <memory>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace Settings
|
namespace Settings
|
||||||
|
@ -71,9 +72,12 @@ namespace Settings
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
|
static void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Index* sIndex;
|
static std::unique_ptr<Index> sIndex;
|
||||||
static Values* sValues;
|
static std::unique_ptr<Values> sDefaultValues;
|
||||||
|
static std::unique_ptr<Values> sValues;
|
||||||
|
|
||||||
friend Values& values();
|
friend Values& values();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue