incrementaltp: respect physics overrides
[waspsaliva.git] / src / util / quicktune.cpp
blob37d4933de5605b0a69b37839250ff6219da1432d
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "quicktune.h"
21 #include "threading/mutex_auto_lock.h"
22 #include "util/string.h"
24 std::string QuicktuneValue::getString()
26 switch(type){
27 case QVT_NONE:
28 return "(none)";
29 case QVT_FLOAT:
30 return ftos(value_QVT_FLOAT.current);
32 return "<invalid type>";
34 void QuicktuneValue::relativeAdd(float amount)
36 switch(type){
37 case QVT_NONE:
38 break;
39 case QVT_FLOAT:
40 value_QVT_FLOAT.current += amount * (value_QVT_FLOAT.max - value_QVT_FLOAT.min);
41 if(value_QVT_FLOAT.current > value_QVT_FLOAT.max)
42 value_QVT_FLOAT.current = value_QVT_FLOAT.max;
43 if(value_QVT_FLOAT.current < value_QVT_FLOAT.min)
44 value_QVT_FLOAT.current = value_QVT_FLOAT.min;
45 break;
49 static std::map<std::string, QuicktuneValue> g_values;
50 static std::vector<std::string> g_names;
51 std::mutex *g_mutex = NULL;
53 static void makeMutex()
55 if(!g_mutex){
56 g_mutex = new std::mutex();
60 std::vector<std::string> getQuicktuneNames()
62 return g_names;
65 QuicktuneValue getQuicktuneValue(const std::string &name)
67 makeMutex();
68 MutexAutoLock lock(*g_mutex);
69 std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
70 if(i == g_values.end()){
71 QuicktuneValue val;
72 val.type = QVT_NONE;
73 return val;
75 return i->second;
78 void setQuicktuneValue(const std::string &name, const QuicktuneValue &val)
80 makeMutex();
81 MutexAutoLock lock(*g_mutex);
82 g_values[name] = val;
83 g_values[name].modified = true;
86 void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
88 makeMutex();
89 MutexAutoLock lock(*g_mutex);
90 std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
91 if(i == g_values.end()){
92 g_values[name] = val;
93 g_names.push_back(name);
94 return;
96 QuicktuneValue &ref = i->second;
97 if(ref.modified)
98 val = ref;
99 else{
100 ref = val;
101 ref.modified = false;