1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Some globals (un-)init fixes

This commit is contained in:
sfan5 2024-04-11 13:54:09 +02:00
parent 2af5191070
commit d8190e1c5f
16 changed files with 58 additions and 62 deletions

View file

@ -31,6 +31,7 @@ std::string QuicktuneValue::getString()
}
return "<invalid type>";
}
void QuicktuneValue::relativeAdd(float amount)
{
switch(type){
@ -48,24 +49,16 @@ void QuicktuneValue::relativeAdd(float amount)
static std::map<std::string, QuicktuneValue> g_values;
static std::vector<std::string> g_names;
std::mutex *g_mutex = NULL;
static std::mutex g_mutex;
static void makeMutex()
{
if(!g_mutex){
g_mutex = new std::mutex();
}
}
std::vector<std::string> getQuicktuneNames()
const std::vector<std::string> &getQuicktuneNames()
{
return g_names;
}
QuicktuneValue getQuicktuneValue(const std::string &name)
{
makeMutex();
MutexAutoLock lock(*g_mutex);
MutexAutoLock lock(g_mutex);
std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
if(i == g_values.end()){
QuicktuneValue val;
@ -77,17 +70,15 @@ QuicktuneValue getQuicktuneValue(const std::string &name)
void setQuicktuneValue(const std::string &name, const QuicktuneValue &val)
{
makeMutex();
MutexAutoLock lock(*g_mutex);
MutexAutoLock lock(g_mutex);
g_values[name] = val;
g_values[name].modified = true;
}
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
{
makeMutex();
MutexAutoLock lock(*g_mutex);
std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
MutexAutoLock lock(g_mutex);
auto i = g_values.find(name);
if(i == g_values.end()){
g_values[name] = val;
g_names.push_back(name);