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