X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fsettings.h;h=0af861a58683b79db16e587097091ac341b6e34c;hb=d1df09841d0eac7a88f638676b80ec848522cca5;hp=89f7589dfddc1bd40932133009ba1c52d6be25e1;hpb=d3dc88fe6bae0371c3e314cfc6db4ca8a06a4ab6;p=dragonfireclient.git diff --git a/src/settings.h b/src/settings.h index 89f7589df..0af861a58 100644 --- a/src/settings.h +++ b/src/settings.h @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_bloated.h" #include "util/string.h" -#include "jthread/jmutex.h" +#include "threading/mutex.h" #include #include #include @@ -31,8 +31,21 @@ with this program; if not, write to the Free Software Foundation, Inc., class Settings; struct NoiseParams; -/** function type to register a changed callback */ -typedef void (*setting_changed_callback)(const std::string); +// Global objects +extern Settings *g_settings; +extern std::string g_settings_path; + +// Type for a settings changed callback function +typedef void (*SettingsChangedCallback)(const std::string &name, void *data); + +typedef std::vector< + std::pair< + SettingsChangedCallback, + void * + > +> SettingsCallbackList; + +typedef std::map SettingsCallbackMap; enum ValueType { VALUETYPE_STRING, @@ -202,22 +215,32 @@ class Settings { // remove a setting bool remove(const std::string &name); void clear(); + void clearDefaults(); void updateValue(const Settings &other, const std::string &name); void update(const Settings &other); - void registerChangedCallback(std::string name, setting_changed_callback cbf); -private: + void registerChangedCallback(const std::string &name, + SettingsChangedCallback cbf, void *userdata = NULL); + void deregisterChangedCallback(const std::string &name, + SettingsChangedCallback cbf, void *userdata = NULL); +private: void updateNoLock(const Settings &other); void clearNoLock(); + void clearDefaultsNoLock(); - void doCallbacks(std::string name); + void doCallbacks(const std::string &name) const; std::map m_settings; std::map m_defaults; - std::map > m_callbacks; + + SettingsCallbackMap m_callbacks; + + mutable Mutex m_callback_mutex; + // All methods that access m_settings/m_defaults directly should lock this. - mutable JMutex m_mutex; + mutable Mutex m_mutex; + }; #endif