Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
quicktune.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 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#pragma once
50
51#include <string>
52#include <map>
53#include <vector>
54
58};
60{
62 union{
63 struct{
64 float current;
65 float min;
66 float max;
68 };
69 bool modified = false;
70
71 QuicktuneValue() = default;
72
73 std::string getString();
74 void relativeAdd(float amount);
75};
76
77const std::vector<std::string> &getQuicktuneNames();
78QuicktuneValue getQuicktuneValue(const std::string &name);
79void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
80
81void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
82
83#ifndef NDEBUG
84 #define QUICKTUNE(type_, var, min_, max_, name){\
85 QuicktuneValue qv;\
86 qv.type = type_;\
87 qv.value_##type_.current = var;\
88 qv.value_##type_.min = min_;\
89 qv.value_##type_.max = max_;\
90 updateQuicktuneValue(name, qv);\
91 var = qv.value_##type_.current;\
92 }
93#else // NDEBUG
94 #define QUICKTUNE(type, var, min_, max_, name){}
95#endif
96
97#define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
98 QUICKTUNE(type_, var, min_, max_, #var)
QuicktuneValue getQuicktuneValue(const std::string &name)
Definition: quicktune.cpp:59
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
Definition: quicktune.cpp:78
QuicktuneValueType
Definition: quicktune.h:55
@ QVT_NONE
Definition: quicktune.h:56
@ QVT_FLOAT
Definition: quicktune.h:57
void setQuicktuneValue(const std::string &name, const QuicktuneValue &val)
Definition: quicktune.cpp:71
const std::vector< std::string > & getQuicktuneNames()
Definition: quicktune.cpp:54
Definition: quicktune.h:60
QuicktuneValue()=default
void relativeAdd(float amount)
Definition: quicktune.cpp:35
float current
Definition: quicktune.h:64
std::string getString()
Definition: quicktune.cpp:24
QuicktuneValueType type
Definition: quicktune.h:61
struct QuicktuneValue::@35::@37 value_QVT_FLOAT
float max
Definition: quicktune.h:66
float min
Definition: quicktune.h:65
bool modified
Definition: quicktune.h:69