Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
quicktune.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5/*
6 Used for tuning constants when developing.
7
8 Eg. if you have this constant somewhere that you just can't get right
9 by changing it and recompiling all over again:
10 v3f wield_position = v3f(55, -35, 65);
11
12 Make it look like this:
13 v3f wield_position = v3f(55, -35, 65);
14 QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.X, 0, 100);
15 QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Y, -80, 20);
16 QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Z, 0, 100);
17
18 Then you can modify the values at runtime, using the keys
19 keymap_quicktune_prev
20 keymap_quicktune_next
21 keymap_quicktune_dec
22 keymap_quicktune_inc
23
24 Once you have modified the values at runtime and then quit, the game
25 will print out all the modified values at the end:
26 Modified quicktune values:
27 wield_position.X = 60
28 wield_position.Y = -30
29 wield_position.Z = 65
30
31 The QUICKTUNE macros shouldn't generally be left in committed code.
32*/
33
34#pragma once
35
36#include <string>
37#include <map>
38#include <vector>
39
45{
47 union{
48 struct{
49 float current;
50 float min;
51 float max;
53 };
54 bool modified = false;
55
56 QuicktuneValue() = default;
57
58 std::string getString();
59 void relativeAdd(float amount);
60};
61
62const std::vector<std::string> &getQuicktuneNames();
63QuicktuneValue getQuicktuneValue(const std::string &name);
64void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
65
66void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
67
68#ifndef NDEBUG
69 #define QUICKTUNE(type_, var, min_, max_, name){\
70 QuicktuneValue qv;\
71 qv.type = type_;\
72 qv.value_##type_.current = var;\
73 qv.value_##type_.min = min_;\
74 qv.value_##type_.max = max_;\
75 updateQuicktuneValue(name, qv);\
76 var = qv.value_##type_.current;\
77 }
78#else // NDEBUG
79 #define QUICKTUNE(type, var, min_, max_, name){}
80#endif
81
82#define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
83 QUICKTUNE(type_, var, min_, max_, #var)
QuicktuneValue getQuicktuneValue(const std::string &name)
Definition quicktune.cpp:44
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
Definition quicktune.cpp:63
QuicktuneValueType
Definition quicktune.h:40
@ QVT_NONE
Definition quicktune.h:41
@ QVT_FLOAT
Definition quicktune.h:42
void setQuicktuneValue(const std::string &name, const QuicktuneValue &val)
Definition quicktune.cpp:56
const std::vector< std::string > & getQuicktuneNames()
Definition quicktune.cpp:39
Definition quicktune.h:45
QuicktuneValue()=default
void relativeAdd(float amount)
Definition quicktune.cpp:20
float current
Definition quicktune.h:49
std::string getString()
Definition quicktune.cpp:9
QuicktuneValueType type
Definition quicktune.h:46
struct QuicktuneValue::@35::@37 value_QVT_FLOAT
float max
Definition quicktune.h:51
float min
Definition quicktune.h:50
bool modified
Definition quicktune.h:54