Plasma Engine  2.0
Loading...
Searching...
No Matches
CVar_inl.h
1#pragma once
2
3#include <Foundation/Configuration/CVar.h>
4
5template <typename Type, plCVarType::Enum CVarType>
7 : plCVar(sName, flags, sDescription)
8{
9 PL_ASSERT_DEBUG(sName.FindSubString(" ") == nullptr, "CVar names must not contain whitespace");
10
11 for (plUInt32 i = 0; i < plCVarValue::ENUM_COUNT; ++i)
12 m_Values[i] = value;
13}
14
15template <typename Type, plCVarType::Enum CVarType>
17{
18 return (m_Values[plCVarValue::Current]);
19}
20
21template <typename Type, plCVarType::Enum CVarType>
23{
24 return CVarType;
25}
26
27template <typename Type, plCVarType::Enum CVarType>
29{
30 if (m_Values[plCVarValue::Current] == m_Values[plCVarValue::DelayedSync])
31 return;
32
33 // this will NOT trigger a 'restart value changed' event
35
36 plCVarEvent e(this);
37 e.m_EventType = plCVarEvent::ValueChanged;
38 m_CVarEvents.Broadcast(e);
39
40 // broadcast the same to the 'all CVars' event handlers
41 s_AllCVarEvents.Broadcast(e);
42}
43
44template <typename Type, plCVarType::Enum CVarType>
46{
47 return (m_Values[val]);
48}
49
50template <typename Type, plCVarType::Enum CVarType>
52{
53 plCVarEvent e(this);
54
55 if (GetFlags().IsAnySet(plCVarFlags::RequiresDelayedSync))
56 {
57 if (value == m_Values[plCVarValue::DelayedSync]) // no change
58 return;
59
61 }
62 else
63 {
64 if (m_Values[plCVarValue::Current] == value) // no change
65 return;
66
67 m_Values[plCVarValue::Current] = value;
68 e.m_EventType = plCVarEvent::ValueChanged;
69 }
70
71 m_Values[plCVarValue::DelayedSync] = value;
72
73 m_CVarEvents.Broadcast(e);
74
75 // broadcast the same to the 'all cvars' event handlers
76 s_AllCVarEvents.Broadcast(e);
77}
CVars are global variables that are used for configuring the engine.
Definition CVar.h:109
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
const char * FindSubString(plStringView sStringToFind, const char *szStartSearchAt=nullptr) const
Definition StringView.cpp:60
[internal] Helper class to implement plCVarInt, plCVarFlag, plCVarBool and plCVarString.
Definition CVar.h:267
void operator=(const Type &value)
Changes the CVar's value and broadcasts the proper events.
Definition CVar_inl.h:51
virtual void SetToDelayedSyncValue() override
Copies the 'DelayedSync' value into the 'Current' value.
Definition CVar_inl.h:28
const Type & GetValue(plCVarValue::Enum val=plCVarValue::Current) const
Returns the internal values of the CVar.
Definition CVar_inl.h:45
virtual plCVarType::Enum GetType() const override
Returns the type of the CVar.
Definition CVar_inl.h:22
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
The data that is broadcast whenever a cvar is changed.
Definition CVar.h:65
@ DelayedSyncValueChanged
Sent whenever the 'DelayedSync' value of the CVar changes. It might actually change back to the 'Curr...
Definition CVar.h:74
@ ValueChanged
Sent whenever the 'Current' value of the CVar is changed.
Definition CVar.h:73
@ RequiresDelayedSync
If the CVar value is changed, the new value will not be visible by default, until SetToDelayedSyncVal...
Definition CVar.h:40
Enum
Definition CVar.h:15
Enum
Definition CVar.h:255
@ Current
The value that should be used.
Definition CVar.h:256
@ DelayedSync
The state that will be stored for later. This is identical to 'Current' unless the 'RequiresDelayedSy...
Definition CVar.h:259