Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Cvars.hpp
1#pragma once
2
3#include <stdint.h>
4#include <string>
5#include <unordered_map>
6
7#include "../HashedString.hpp"
8
9namespace Grindstone {
10 enum class CvarType : uint8_t {
11 Undefined = 0,
12 Integer,
13 Float,
14 String,
15 };
16
17 enum class CvarFlags : uint16_t {
18 None = 0,
19 Hidden = 1 << 1, // Does not show in console and cvar UI
20 ReadOnlyUi = 1 << 2, // Is read-only in the console and cvar UI.
21 ReadOnlyCode = 1 << 3, // Is read-only in the code.
22 ReadOnly = ReadOnlyUi | ReadOnlyCode, // Completely read-only.
23 NotSerialized = 1 << 4, // Cannot be saved/loaded to a file.
24 Advanced = 1 << 5, // Considered advanced functionality.
25 NotCommandLineParameter = 1 << 6, // Cannot be passed to the application as a CLI parameter (ie: editor.exe -parameterName=4)
26 Boolean = 1 << 7, // This int is represented as a boolean.
27 EditorNumberSlider = 1 << 8, // Used for Integers and Floats, uses a slider in Cvar UI.
28 };
29
31 public:
32 friend class CvarSystemImpl;
33
34 int32_t arrayIndex;
35
36 CvarType type = CvarType::Undefined;
37 CvarFlags flags = CvarFlags::None;
38 std::string name;
39 std::string description;
40 };
41
42 class CvarSystem {
43 public:
44 static CvarSystem* GetInstance();
45 static void SetInstance(CvarSystem* ptr);
46 virtual CvarParameter* GetCvar(Grindstone::HashedString name) = 0;
47 virtual ~CvarSystem() {}
48
49 virtual size_t GetFloatCount() const = 0;
50 virtual size_t GetIntCount() const = 0;
51 virtual size_t GetStringCount() const = 0;
52
53 virtual double* GetFloatCvar(Grindstone::HashedString name) = 0;
54 virtual int32_t* GetIntCvar(Grindstone::HashedString name) = 0;
55 virtual const char* GetStringCvarCstring(Grindstone::HashedString name) = 0;
56 virtual std::string* GetStringCvar(Grindstone::HashedString name) = 0;
57
58 virtual void SetFloatCvar(Grindstone::HashedString name, double value) = 0;
59 virtual void SetIntCvar(Grindstone::HashedString name, int32_t value) = 0;
60 virtual void SetStringCvar(Grindstone::HashedString name, const char* value) = 0;
61
62 virtual double* GetFloatCvar(size_t arrayIndex) = 0;
63 virtual int32_t* GetIntCvar(size_t arrayIndex) = 0;
64 virtual const char* GetStringCvarCstring(size_t arrayIndex) = 0;
65 virtual std::string* GetStringCvar(size_t arrayIndex) = 0;
66
67 virtual void SetFloatCvar(size_t arrayIndex, double value) = 0;
68 virtual void SetIntCvar(size_t arrayIndex, int32_t value) = 0;
69 virtual void SetStringCvar(size_t arrayIndex, const char* value) = 0;
70
71 virtual CvarParameter* CreateFloatCvar(const char* name, const char* description, double defaultValue, double currentValue, CvarFlags flags = CvarFlags::None) = 0;
72 virtual CvarParameter* CreateIntCvar(const char* name, const char* description, int32_t defaultValue, int32_t currentValue, CvarFlags flags = CvarFlags::None) = 0;
73 virtual CvarParameter* CreateBooleanCvar(const char* name, const char* description, bool defaultValue, bool currentValue, CvarFlags flags = CvarFlags::None) = 0;
74 virtual CvarParameter* CreateStringCvar(const char* name, const char* description, const char* defaultValue, const char* currentValue, CvarFlags flags = CvarFlags::None) = 0;
75
76 using Iterator = std::unordered_map<Grindstone::HashValue, CvarParameter>::iterator;
77 using ConstIterator = std::unordered_map<Grindstone::HashValue, CvarParameter>::const_iterator;
78
79 virtual Iterator begin() noexcept = 0;
80 virtual Iterator end() noexcept = 0;
81
82 virtual ConstIterator begin() const noexcept = 0;
83 virtual ConstIterator end() const noexcept = 0;
84 };
85
86 CvarSystem* CreateCvarSystemInstance();
87}
Definition Cvars.hpp:30
Definition Cvars.hpp:42
Definition HashedString.hpp:9