summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
authorgregorycu <gregory.currie@gmail.com>2015-01-24 20:40:27 +1100
committerCraig Robbins <kde.psych@gmail.com>2015-01-25 15:23:37 +1000
commited7c9c4cb83da887a2a7f1b7f5fc1656057977e7 (patch)
tree62455be3c1be6a0d4040c770a37d8dcc82ad867b /src/settings.cpp
parent2c4a5e18619a69159bcace8c03b4ea5642f46836 (diff)
downloadminetest-ed7c9c4cb83da887a2a7f1b7f5fc1656057977e7.tar.gz
minetest-ed7c9c4cb83da887a2a7f1b7f5fc1656057977e7.tar.bz2
minetest-ed7c9c4cb83da887a2a7f1b7f5fc1656057977e7.zip
Settings fixes Make the GameGlobalShaderConstantSetter use the settings callback (8% perf improvement in game loop) Ensure variable is set Ensure settings callback is threadsafe
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 2f515caba..7339af62b 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -963,28 +963,39 @@ void Settings::clearNoLock()
m_defaults.clear();
}
-
void Settings::registerChangedCallback(std::string name,
- setting_changed_callback cbf)
+ setting_changed_callback cbf, void *userdata)
{
- m_callbacks[name].push_back(cbf);
+ JMutexAutoLock lock(m_callbackMutex);
+ m_callbacks[name].push_back(std::make_pair(cbf, userdata));
}
+void Settings::deregisterChangedCallback(std::string name, setting_changed_callback cbf, void *userdata)
+{
+ JMutexAutoLock lock(m_callbackMutex);
+ std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
+ if (iterToVector != m_callbacks.end())
+ {
+ std::vector<std::pair<setting_changed_callback, void*> > &vector = iterToVector->second;
+
+ std::vector<std::pair<setting_changed_callback, void*> >::iterator position =
+ std::find(vector.begin(), vector.end(), std::make_pair(cbf, userdata));
+
+ if (position != vector.end())
+ vector.erase(position);
+ }
+}
void Settings::doCallbacks(const std::string name)
{
- std::vector<setting_changed_callback> tempvector;
+ JMutexAutoLock lock(m_callbackMutex);
+ std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
+ if (iterToVector != m_callbacks.end())
{
- JMutexAutoLock lock(m_mutex);
- if (m_callbacks.find(name) != m_callbacks.end())
+ std::vector<std::pair<setting_changed_callback, void*> >::iterator iter;
+ for (iter = iterToVector->second.begin(); iter != iterToVector->second.end(); iter++)
{
- tempvector = m_callbacks[name];
+ (iter->first)(name, iter->second);
}
}
-
- std::vector<setting_changed_callback>::iterator iter;
- for (iter = tempvector.begin(); iter != tempvector.end(); iter++)
- {
- (*iter)(name);
- }
}