]> git.lizzy.rs Git - minetest.git/blob - src/quicktune.cpp
66b9804dfcb7749e4b0cb5681950e192c3e27e23
[minetest.git] / src / quicktune.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
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 General Public License for more details.
14
15 You should have received a copy of the GNU 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.
18 */
19
20 #include "quicktune.h"
21 #include <jmutex.h>
22 #include <jmutexautolock.h>
23
24 static std::map<std::string, QuicktuneValue> g_values;
25 static std::vector<std::string> g_names;
26 JMutex *g_mutex = NULL;
27
28 static void makeMutex()
29 {
30         if(!g_mutex){
31                 g_mutex = new JMutex();
32                 g_mutex->Init();
33         }
34 }
35
36 std::vector<std::string> getQuicktuneNames()
37 {
38         return g_names;
39 }
40
41 /*std::map<std::string, QuicktuneValue> getQuicktuneValues()
42 {
43         makeMutex();
44         JMutexAutoLock lock(*g_mutex);
45         return g_values;
46 }*/
47
48 QuicktuneValue getQuicktuneValue(const std::string &name)
49 {
50         makeMutex();
51         JMutexAutoLock lock(*g_mutex);
52         std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
53         if(i == g_values.end()){
54                 QuicktuneValue val;
55                 val.type = QUICKTUNE_NONE;
56                 return val;
57         }
58         return i->second;
59 }
60
61 void setQuicktuneValue(const std::string &name, const QuicktuneValue &val)
62 {
63         makeMutex();
64         JMutexAutoLock lock(*g_mutex);
65         g_values[name] = val;
66 }
67
68 void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
69 {
70         makeMutex();
71         JMutexAutoLock lock(*g_mutex);
72         std::map<std::string, QuicktuneValue>::iterator i = g_values.find(name);
73         if(i == g_values.end()){
74                 g_values[name] = val;
75                 g_names.push_back(name);
76                 return;
77         }
78         QuicktuneValue &ref = i->second;
79         switch(val.type){
80         case QUICKTUNE_NONE:
81                 break;
82         case QUICKTUNE_FLOAT:
83                 val.value_float.current = ref.value_float.current;
84                 break;
85         }
86 }
87