![]() |
Plasma Engine
2.0
|
This resource loads config files containing key/value pairs. More...
#include <ConfigFileResource.h>
Public Member Functions | |
plInt32 | GetInt (plTempHashedString sName) const |
Returns the 'int' variable with the given name. Logs an error, if the variable doesn't exist in the config file. | |
float | GetFloat (plTempHashedString sName) const |
Returns the 'float' variable with the given name. Logs an error, if the variable doesn't exist in the config file. | |
bool | GetBool (plTempHashedString sName) const |
Returns the 'bool' variable with the given name. Logs an error, if the variable doesn't exist in the config file. | |
plStringView | GetString (plTempHashedString sName) const |
Returns the 'string' variable with the given name. Logs an error, if the variable doesn't exist in the config file. | |
plInt32 | GetInt (plTempHashedString sName, plInt32 iFallback) const |
Returns the 'int' variable with the given name. Returns the 'fallback' value, if the variable doesn't exist in the config file. | |
float | GetFloat (plTempHashedString sName, float fFallback) const |
Returns the 'float' variable with the given name. Returns the 'fallback' value, if the variable doesn't exist in the config file. | |
bool | GetBool (plTempHashedString sName, bool bFallback) const |
Returns the 'bool' variable with the given name. Returns the 'fallback' value, if the variable doesn't exist in the config file. | |
plStringView | GetString (plTempHashedString sName, plStringView sFallback) const |
Returns the 'string' variable with the given name. Returns the 'fallback' value, if the variable doesn't exist in the config file. | |
![]() | |
PL_ALWAYS_INLINE const plString & | GetResourceID () const |
Returns the unique ID that identifies this resource. On a file resource this might be a path. Can also be a GUID or any other scheme that uniquely identifies the resource. | |
PL_ALWAYS_INLINE plUInt64 | GetResourceIDHash () const |
Returns the hash of the unique ID. | |
void | SetResourceDescription (plStringView sDescription) |
The resource description allows to store an additional string that might be more descriptive during debugging, than the unique ID. | |
const plString & | GetResourceDescription () const |
The resource description allows to store an additional string that might be more descriptive during debugging, than the unique ID. | |
const plString & | GetResourceIdOrDescription () const |
The returns the resource description, if available, otherwise the resource ID. | |
PL_ALWAYS_INLINE plResourceState | GetLoadingState () const |
Returns the current state in which this resource is in. | |
PL_ALWAYS_INLINE plUInt8 | GetNumQualityLevelsDiscardable () const |
Returns the current maximum quality level that the resource could have. | |
PL_ALWAYS_INLINE plUInt8 | GetNumQualityLevelsLoadable () const |
Returns how many quality levels the resource may additionally load. | |
float | GetLoadingPriority (plTime now) const |
Returns the priority that is used by the resource manager to determine which resource to load next. | |
plResourcePriority | GetPriority () const |
Returns the current resource priority. | |
void | SetPriority (plResourcePriority priority) |
Changes the current resource priority. | |
PL_ALWAYS_INLINE const plBitflags< plResourceFlags > & | GetBaseResourceFlags () const |
Returns the basic flags for the resource type. Mostly used the resource manager. | |
PL_ALWAYS_INLINE const MemoryUsage & | GetMemoryUsage () const |
Returns the information about the current memory usage of the resource. | |
PL_ALWAYS_INLINE plTime | GetLastAcquireTime () const |
Returns the time at which the resource was (tried to be) acquired last. If a resource is acquired using plResourceAcquireMode::PointerOnly, this does not update the last acquired time, since the resource is not acquired for full use. | |
PL_ALWAYS_INLINE plInt32 | GetReferenceCount () const |
Returns the reference count of this resource. | |
PL_ALWAYS_INLINE const plTimestamp & | GetLoadedFileModificationTime () const |
Returns the modification date of the file from which this resource was loaded. | |
PL_ALWAYS_INLINE plUInt32 | GetCurrentResourceChangeCounter () const |
Returns the current value of the resource change counter. Can be used to detect whether the resource has changed since using it last time. | |
PL_ALWAYS_INLINE void | IncResourceChangeCounter () |
Allows to manually increase the resource change counter to signal that dependent code might need to update. | |
virtual void | ResetResource () |
If the resource has modifications from the original state, it should reset itself to that state now (or force a reload on itself). | |
void | PrintHandleStackTraces () |
Prints the stack-traces for all handles that currently reference this resource. | |
![]() | |
virtual const plRTTI * | GetDynamicRTTI () const |
bool | IsInstanceOf (const plRTTI *pType) const |
Returns whether the type of this instance is of the given type or derived from it. | |
template<typename T > | |
PL_ALWAYS_INLINE bool | IsInstanceOf () const |
Returns whether the type of this instance is of the given type or derived from it. | |
Protected Member Functions | |
virtual plResourceLoadDesc | UnloadData (Unload WhatToUnload) override |
Requests the resource to unload another quality level. If bFullUnload is true, the resource should unload all data, because it is going to be deleted afterwards. | |
virtual plResourceLoadDesc | UpdateContent (plStreamReader *Stream) override |
Called whenever more data for the resource is available. The resource must read the stream to update it's data. | |
virtual void | UpdateMemoryUsage (MemoryUsage &out_NewMemoryUsage) override |
This function must be overridden by all resource types. | |
![]() | |
plResource (DoUpdate ResourceUpdateThread, plUInt8 uiQualityLevelsLoadable) | |
Default constructor. | |
virtual | ~plResource () |
virtual destructor. | |
MemoryUsage & | ModifyMemoryUsage () |
Non-const version for resources that want to write this variable directly. | |
void | SetIsReloadable (bool bIsReloadable) |
Call this to specify whether a resource is reloadable. | |
void | SetHasLoadingFallback (bool bHasLoadingFallback) |
Used internally by the code injection macros. | |
Friends | |
class | plConfigFileResourceLoader |
Additional Inherited Members | |
![]() | |
static const plRTTI * | GetStaticRTTI () |
![]() | |
plEvent< const plResourceEvent &, plMutex > | m_ResourceEvents |
![]() | |
enum class | DoUpdate { OnMainThread , OnAnyThread } |
enum class | Unload { AllQualityLevels , OneQualityLevel } |
This resource loads config files containing key/value pairs.
The config files usually use the file extension '.plConfig'.
The file format looks like this:
To declare a key/value pair for the first time, write its type, name and value: int i = 1 float f = 2.3 bool b = false string s = "hello"
To set a variable to a different value than before, it has to be marked with 'override':
override i = 4
The format supports C preprocessor features like #include, #define, #ifdef, etc. This can be used to build hierarchical config files:
#include "BaseConfig.plConfig" override int SomeValue = 7
It can also be used to define 'enum types':
#define SmallValue 3 #define BigValue 5 int MyValue = BigValue
Since resources can be reloaded at runtime, config resources are a convenient way to define game parameters that you may want to tweak at any time. Using C preprocessor logic (#define, if, #else, etc) you can quickly select between different configuration sets.
Once loaded, accessing the data is very efficient.
|
overrideprotectedvirtual |
Requests the resource to unload another quality level. If bFullUnload is true, the resource should unload all data, because it is going to be deleted afterwards.
Implements plResource.
|
overrideprotectedvirtual |
Called whenever more data for the resource is available. The resource must read the stream to update it's data.
pStream may be nullptr in case the resource data could not be found.
Implements plResource.
|
overrideprotectedvirtual |
This function must be overridden by all resource types.
It has to compute the memory used by this resource. It is called by the resource manager whenever the resource's data has been loaded or unloaded.
Implements plResource.