Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
CVar.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2020 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
23
24#pragma once
25
26#include "BitFlags.h"
27
28#include <Ogre.h>
29#include <string>
30
31namespace RoR {
32
35
44
52class CVar
53{
54public:
55
56 CVar(std::string const& name, std::string const& long_name, int flags):
57 m_name(name),
59 m_flags(flags),
60 m_value_num(0.f)
61 {
62 // Initialize string representation
64 {
66 }
67 }
68
69 // Data setters
70
71 template <typename T>
72 void setVal(T val)
73 {
74 if ((T)m_value_num != val)
75 {
76 std::string str = this->convertStr((float)val);
77 this->logUpdate(str);
80 }
81 }
82
83 void setStr(std::string const& str)
84 {
85 if (m_value_str != str)
86 {
87 this->logUpdate(str);
88 m_value_num = 0;
90 }
91 }
92
93 // Data getters
94
95 std::string const& getStr() const { return m_value_str; }
96 float getFloat() const { return m_value_num; }
97 int getInt() const { return (int)m_value_num; }
98 bool getBool() const { return (bool)m_value_num; }
99 template<typename T> T getEnum() const { return (T)this->getInt(); }
100
101 // Info getters
102
103 std::string const& getName() const { return m_name; }
104 std::string const& getLongName() const { return m_long_name; }
105 bool hasFlag(int f) const { return m_flags & f; }
106
107private:
108 void logUpdate(std::string const& new_val);
109 std::string convertStr(float val);
110
111 // Variables
112
113 std::string m_name;
114 std::string m_long_name;
115
116 std::string m_value_str;
119};
120
122
123} // namespace RoR
Bit operations.
#define BITMASK(OFFSET)
Definition BitFlags.h:10
Quake-style console variable, defined in RoR.cfg or crated via Console UI and scripts.
Definition CVar.h:53
int m_flags
Definition CVar.h:118
std::string const & getName() const
Definition CVar.h:103
std::string m_value_str
Definition CVar.h:116
std::string m_long_name
Definition CVar.h:114
std::string m_name
Definition CVar.h:113
std::string convertStr(float val)
Definition CVar.cpp:318
std::string const & getLongName() const
Definition CVar.h:104
T getEnum() const
Definition CVar.h:99
float getFloat() const
Definition CVar.h:96
std::string const & getStr() const
Definition CVar.h:95
bool getBool() const
Definition CVar.h:98
CVar(std::string const &name, std::string const &long_name, int flags)
Definition CVar.h:56
void setStr(std::string const &str)
Definition CVar.h:83
void setVal(T val)
Definition CVar.h:72
float m_value_num
Definition CVar.h:117
bool hasFlag(int f) const
Definition CVar.h:105
void logUpdate(std::string const &new_val)
Definition CVar.cpp:306
int getInt() const
Definition CVar.h:97
CVarFlags
Definition CVar.h:37
@ CVAR_ARCHIVE
Will be written to RoR.cfg.
Definition CVar.h:41
@ CVAR_TYPE_INT
Definition CVar.h:39
@ CVAR_NO_LOG
Will not be written to RoR.log.
Definition CVar.h:42
@ CVAR_TYPE_FLOAT
Definition CVar.h:40
@ CVAR_TYPE_BOOL
Definition CVar.h:38