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