Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2013 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 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.
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 Lesser General Public License for more details.
14 :
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.
18 : */
19 :
20 : /*
21 : Used for tuning constants when developing.
22 :
23 : Eg. if you have this constant somewhere that you just can't get right
24 : by changing it and recompiling all over again:
25 : v3f wield_position = v3f(55, -35, 65);
26 :
27 : Make it look like this:
28 : v3f wield_position = v3f(55, -35, 65);
29 : QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.X, 0, 100);
30 : QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Y, -80, 20);
31 : QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Z, 0, 100);
32 :
33 : Then you can modify the values at runtime, using the keys
34 : keymap_quicktune_prev
35 : keymap_quicktune_next
36 : keymap_quicktune_dec
37 : keymap_quicktune_inc
38 :
39 : Once you have modified the values at runtime and then quit, the game
40 : will print out all the modified values at the end:
41 : Modified quicktune values:
42 : wield_position.X = 60
43 : wield_position.Y = -30
44 : wield_position.Z = 65
45 :
46 : The QUICKTUNE macros shouldn't generally be left in committed code.
47 : */
48 :
49 : #ifndef QUICKTUNE_HEADER
50 : #define QUICKTUNE_HEADER
51 :
52 : #include <string>
53 : #include <map>
54 : #include <vector>
55 :
56 : enum QuicktuneValueType{
57 : QVT_NONE,
58 : QVT_FLOAT
59 : };
60 : struct QuicktuneValue
61 : {
62 : QuicktuneValueType type;
63 : union{
64 : struct{
65 : float current;
66 : float min;
67 : float max;
68 : } value_QVT_FLOAT;
69 : };
70 : bool modified;
71 :
72 0 : QuicktuneValue():
73 : type(QVT_NONE),
74 0 : modified(false)
75 0 : {}
76 : std::string getString();
77 : void relativeAdd(float amount);
78 : };
79 :
80 : std::vector<std::string> getQuicktuneNames();
81 : QuicktuneValue getQuicktuneValue(const std::string &name);
82 : void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
83 :
84 : void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
85 :
86 : #ifndef NDEBUG
87 : #define QUICKTUNE(type_, var, min_, max_, name){\
88 : QuicktuneValue qv;\
89 : qv.type = type_;\
90 : qv.value_##type_.current = var;\
91 : qv.value_##type_.min = min_;\
92 : qv.value_##type_.max = max_;\
93 : updateQuicktuneValue(name, qv);\
94 : var = qv.value_##type_.current;\
95 : }
96 : #else // NDEBUG
97 : #define QUICKTUNE(type, var, min_, max_, name){}
98 : #endif
99 :
100 : #define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
101 : QUICKTUNE(type_, var, min_, max_, #var)
102 :
103 : #endif
104 :
|