3#include <Foundation/Communication/Event.h>
4#include <Foundation/Configuration/Plugin.h>
5#include <Foundation/Strings/String.h>
6#include <Foundation/Types/Bitflags.h>
7#include <Foundation/Utilities/EnumerableClass.h>
27 using StorageType = plUInt8;
42 ShowRequiresRestartMsg = PL_BIT(2),
56 StorageType RequiresDelayedSync : 1;
57 StorageType ShowRequiresRestartMsg : 1;
110 PL_DECLARE_ENUMERABLE_CLASS(
plCVar);
129 static void SaveCVars();
137 static void SaveCVarsToFile(
plStringView sPath,
bool bIgnoreSaveFlag =
false);
140 static void LoadCVars(
bool bOnlyNewOnes =
true,
bool bSetAsCurrentValue =
true);
161 static void LoadCVarsFromFile(
bool bOnlyNewOnes =
true,
bool bSetAsCurrentValue =
true,
plDynamicArray<plCVar*>* pOutCVars =
nullptr);
182 static void LoadCVarsFromFile(
plStringView sPath,
bool bOnlyNewOnes =
true,
bool bSetAsCurrentValue =
true,
bool bIgnoreSaveFlag =
false,
plDynamicArray<plCVar*>* pOutCVars =
nullptr);
192 static void LoadCVarsFromCommandLine(
bool bOnlyNewOnes =
true,
bool bSetAsCurrentValue =
true,
plDynamicArray<plCVar*>* pOutCVars =
nullptr);
225 static void ListOfCVarsChanged(
plStringView sSetPluginNameTo);
231 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(Foundation, CVars);
233 static void AssignSubSystemPlugin(
plStringView sPluginName);
234 static void PluginEventHandler(
const plPluginEvent& EventData);
242 bool m_bHasNeverBeenLoaded =
true;
265template <
typename Type, plCVarType::Enum CVarType>
272 operator const Type&()
const;
295 Type m_Values[plCVarValue::ENUM_COUNT];
312#include <Foundation/Configuration/Implementation/CVar_inl.h>
CVars are global variables that are used for configuring the engine.
Definition CVar.h:109
virtual void SetToDelayedSyncValue()=0
Copies the 'DelayedSync' value into the 'Current' value.
static plEvent< const plCVarEvent & > s_AllCVarEvents
Broadcasts changes to ANY CVar. Thus code that needs to update when any one of them changes can use t...
Definition CVar.h:217
plStringView GetPluginName() const
Returns the name of the plugin which this CVar is declared in.
Definition CVar.h:220
plStringView GetName() const
Returns the (display) name of the CVar.
Definition CVar.h:202
plBitflags< plCVarFlags > GetFlags() const
Returns all the CVar flags.
Definition CVar.h:211
plStringView GetDescription() const
Returns the description of the CVar.
Definition CVar.h:208
virtual plCVarType::Enum GetType() const =0
Returns the type of the CVar.
plEvent< const plCVarEvent &, plNoMutex, plStaticsAllocatorWrapper > m_CVarEvents
Code that needs to be execute whenever a cvar is changed can register itself here to be notified of s...
Definition CVar.h:214
Definition DynamicArray.h:81
Base class to add the ability to another class to enumerate all active instance of it,...
Definition EnumerableClass.h:28
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
[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
bool HasDelayedSyncValueChanged() const
Checks whether a new value was set and now won't be visible until SetToDelayedSyncValue() is called.
Definition CVar.h:287
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
@ ListOfVarsChanged
A CVar was added or removed dynamically (not just by loading a plugin), some stuff may need to update...
Definition CVar.h:75
@ 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
plCVar * m_pCVar
Which CVar is involved. This is only for convenience, it is always the CVar on which the event is tri...
Definition CVar.h:82
Type m_EventType
The type of this event.
Definition CVar.h:79
The flags that can be used on an plCVar.
Definition CVar.h:26
@ Default
By default CVars are not saved.
Definition CVar.h:50
@ RequiresRestart
Indicates that changing this CVar will only take effect after the proper subsystem has been reinitial...
Definition CVar.h:47
@ Save
If this flag is set, the CVar will be stored on disk and loaded again. Otherwise all changes to it wi...
Definition CVar.h:35
@ RequiresDelayedSync
If the CVar value is changed, the new value will not be visible by default, until SetToDelayedSyncVal...
Definition CVar.h:40
Describes of which type a CVar is. Use that info to cast an plCVar* to the proper derived class.
Definition CVar.h:13
@ String
Can cast the plCVar* to plCVarString*.
Definition CVar.h:19
@ Bool
Can cast the plCVar* to plCVarBool*.
Definition CVar.h:18
@ Int
Can cast the plCVar* to plCVarInt*.
Definition CVar.h:16
@ Float
Can cast the plCVar* to plCVarFloat*.
Definition CVar.h:17
Each CVar stores several values internally. The 'Current' value is the most important one.
Definition CVar.h:253
Enum
Definition CVar.h:255
@ Stored
The value that was read from disk (or the default). Can be used to reset a CVar to the 'saved' state,...
Definition CVar.h:258
@ 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
@ Default
The 'default' value of the CVar. Can be used to reset a variable to its default state.
Definition CVar.h:257
The data that is broadcast whenever a plugin is (un-) loaded.
Definition Plugin.h:11