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 size_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 SetBoolCvar(Grindstone::HashedString name, bool value) = 0;
61 virtual void SetStringCvar(Grindstone::HashedString name, const char* value) = 0;
62
63 virtual double* GetFloatCvar(size_t arrayIndex) = 0;
64 virtual int32_t* GetIntCvar(size_t arrayIndex) = 0;
65 virtual bool GetBoolCvar(size_t arrayIndex) const = 0;
66 virtual const char* GetStringCvarCstring(size_t arrayIndex) = 0;
67 virtual std::string* GetStringCvar(size_t arrayIndex) = 0;
68
69 virtual void SetFloatCvar(size_t arrayIndex, double value) = 0;
70 virtual void SetIntCvar(size_t arrayIndex, int32_t value) = 0;
71 virtual void SetStringCvar(size_t arrayIndex, const char* value) = 0;
72
73 virtual CvarParameter* CreateFloatCvar(const char* name, const char* description, double defaultValue, double currentValue, CvarFlags flags = CvarFlags::None) = 0;
74 virtual CvarParameter* CreateIntCvar(const char* name, const char* description, int32_t defaultValue, int32_t currentValue, CvarFlags flags = CvarFlags::None) = 0;
75 virtual CvarParameter* CreateBooleanCvar(const char* name, const char* description, bool defaultValue, bool currentValue, CvarFlags flags = CvarFlags::None) = 0;
76 virtual CvarParameter* CreateStringCvar(const char* name, const char* description, const char* defaultValue, const char* currentValue, CvarFlags flags = CvarFlags::None) = 0;
77
78 using Iterator = std::unordered_map<Grindstone::HashValue, CvarParameter>::iterator;
79 using ConstIterator = std::unordered_map<Grindstone::HashValue, CvarParameter>::const_iterator;
80
81 virtual Iterator begin() noexcept = 0;
82 virtual Iterator end() noexcept = 0;
83
84 virtual ConstIterator begin() const noexcept = 0;
85 virtual ConstIterator end() const noexcept = 0;
86 };
87
88 CvarSystem* CreateCvarSystemInstance();
89}
Definition Cvars.hpp:30
Definition Cvars.hpp:42
Definition HashedString.hpp:9