Luanti 5.15.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 <vector>
38
45{
47 union {
48 struct {
49 float current, min, max;
51 struct {
54 };
55 bool modified = false;
56
57 QuicktuneValue() = default;
58
59 std::string getString();
60 void relativeAdd(float amount);
61};
62
63const std::vector<std::string> &getQuicktuneNames();
64QuicktuneValue getQuicktuneValue(const std::string &name);
65void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
66
67void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
68
69#define QUICKTUNE(type_, var, min_, max_, name) do { \
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 } while (0)
78
79#define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
80 QUICKTUNE(type_, var, min_, max_, #var)
QuicktuneValue getQuicktuneValue(const std::string &name)
Definition quicktune.cpp:55
void updateQuicktuneValue(const std::string &name, QuicktuneValue &val)
Definition quicktune.cpp:71
QuicktuneValueType
Definition quicktune.h:39
@ QVT_NONE
Definition quicktune.h:40
@ QVT_INT
Definition quicktune.h:42
@ QVT_FLOAT
Definition quicktune.h:41
void setQuicktuneValue(const std::string &name, const QuicktuneValue &val)
Definition quicktune.cpp:64
const std::vector< std::string > & getQuicktuneNames()
Definition quicktune.cpp:50
Definition quicktune.h:45
QuicktuneValue()=default
struct QuicktuneValue::@36::@38 value_QVT_FLOAT
void relativeAdd(float amount)
Definition quicktune.cpp:24
float current
Definition quicktune.h:49
std::string getString()
Definition quicktune.cpp:11
int current
Definition quicktune.h:52
QuicktuneValueType type
Definition quicktune.h:46
struct QuicktuneValue::@36::@39 value_QVT_INT
float max
Definition quicktune.h:49
float min
Definition quicktune.h:49
bool modified
Definition quicktune.h:55