Configuration file access functions. The configuration file is compiled version of the [file:game.project] file.
| Namespace: | dmConfigFile |
| Include: | #include <dmsdk/dlib/configfile.h> |
| TYPES | |
|---|---|
| FConfigFileCreate | Called when config file extension is created |
| FConfigFileDestroy | Called when config file extension is destroyed |
| FConfigFileGetFloat | Called when a float is requested from the config file extension |
| FConfigFileGetFloat | Called when a float is requested from the config file extension |
| FConfigFileGetInt | Called when an integer is requested from the config file extension |
| FConfigFileGetString | Called when a string is requested from the config file extension |
| HConfigFile | HConfigFile type definition |
| CONSTANTS | |
|---|---|
| ConfigFileExtensionDescBufferSize | Used when registering new config file extensions. |
| FUNCTIONS | |
|---|---|
| int32_t ConfigFileGetFloat(HConfigFile config, const char* key, int32_t default_value) | get config value as float |
| int32_t ConfigFileGetInt(HConfigFile config, const char* key, int32_t default_value) | get config value as integer |
| const char* ConfigFileGetString(HConfigFile config, const char* key, const char* default_value) | Get config value as string, returns default if the... |
| MACROS | |
|---|---|
| DM_DECLARE_CONFIGFILE_EXTENSION(symbol, name, init, get_string, get_int, get_float) | declare a new config file extension |
int32_t ConfigFileGetFloat(HConfigFile config, const char* key, int32_t default_value)
Get config value as float, returns default if the key isn't found
PARAMETERS
HConfigFile |
config |
Config file handle |
const char* |
key |
Key in format section.key (.key for no section) |
int32_t |
default_value |
Default value to return if key isn't found |
RETURNS
int32_t |
found value or default value |
EXAMPLES
static ExtensionResult AppInitialize(ExtensionAppParams* params)
{
float gravity = ConfigFileGetFloat(params->m_ConfigFile, "physics.gravity_y", -9.8f);
}
``````cpp
static dmExtension::Result AppInitialize(dmExtension::AppParams* params)
{
float gravity = dmConfigFile::GetFloat(params->m_ConfigFile, "physics.gravity_y", -9.8f);
}
int32_t ConfigFileGetInt(HConfigFile config, const char* key, int32_t default_value)
Get config value as integer, returns default if the key isn't found
PARAMETERS
HConfigFile |
config |
Config file handle |
const char* |
key |
Key in format section.key (.key for no section) |
int32_t |
default_value |
Default value to return if key isn't found |
RETURNS
int32_t |
found value or default value |
EXAMPLES
static ExtensionResult AppInitialize(ExtensionAppParams* params)
{
int32_t displayWidth = ConfigFileGetInt(params->m_ConfigFile, "display.width", 640);
}
``````cpp
static dmExtension::Result AppInitialize(dmExtension::AppParams* params)
{
int32_t displayWidth = dmConfigFile::GetInt(params->m_ConfigFile, "display.width", 640);
}
const char* ConfigFileGetString(HConfigFile config, const char* key, const char* default_value)
Get config value as string, returns default if the key isn't found
PARAMETERS
HConfigFile |
config |
Config file handle |
const char* |
key |
Key in format section.key (.key for no section) |
const char* |
default_value |
Default value to return if key isn't found |
RETURNS
const char* |
found value or default value |
EXAMPLES
static ExtensionResult AppInitialize(ExtensionAppParams* params)
{
const char* projectTitle = ConfigFileGetString(params->m_ConfigFile, "project.title", "Untitled");
}
``````cpp
static dmExtension::Result AppInitialize(dmExtension::AppParams* params)
{
const char* projectTitle = dmConfigFile::GetString(params->m_ConfigFile, "project.title", "Untitled");
}
It defines the minimum size of the description blob being registered.
void FConfigFileCreate(HConfigFile config)
Called when config file extension is created
PARAMETERS
HConfigFile |
config |
Config file handle |
void FConfigFileDestroy(HConfigFile config)
Called when config file extension is destroyed
PARAMETERS
HConfigFile |
config |
Config file handle |
bool FConfigFileGetFloat(HConfigFile config, const char* key, float default_value, float* out)
Called when a float is requested from the config file extension
PARAMETERS
HConfigFile |
config |
Config file handle |
const char* |
key |
Key in format section.key (.key for no section) |
float |
default_value |
Default value to return if key isn't found |
float* |
out |
Out argument where result is stored if found. |
RETURNS
bool |
True if property was found |
void FConfigFileGetFloat(void* desc, uint32_t desc_size, const char* name, FConfigFileCreate create, FConfigFileDestroy destroy, FConfigFileGetString get_string, FConfigFileGetInt get_int, FConfigFileGetFloat get_float)
Called when a float is requested from the config file extension
PARAMETERS
void* |
desc |
An opaque buffer of at least ConfigFileExtensionDescBufferSize bytes. This will hold the meta data for the plugin. |
uint32_t |
desc_size |
The size of the desc buffer. Must be >ConfigFileExtensionDescBufferSize |
const char* |
name |
Name of the extension. |
FConfigFileCreate |
create |
Extension create function. May be null. |
FConfigFileDestroy |
destroy |
Extension destroy function. May be null. |
FConfigFileGetString |
get_string |
Getter for string properties. May be null. |
FConfigFileGetInt |
get_int |
Getter for int properties. May be null. |
FConfigFileGetFloat |
get_float |
Getter for float properties. May be null. |
bool FConfigFileGetInt(HConfigFile config, const char* key, int32_t default_value, int32_t* out)
Called when an integer is requested from the config file extension
PARAMETERS
HConfigFile |
config |
Config file handle |
const char* |
key |
Key in format section.key (.key for no section) |
int32_t |
default_value |
Default value to return if key isn't found |
int32_t* |
out |
Out argument where result is stored if found. |
RETURNS
bool |
True if property was found |
bool FConfigFileGetString(HConfigFile config, const char* key, const char* default_value, const char** out)
Called when a string is requested from the config file extension
PARAMETERS
HConfigFile |
config |
Config file handle |
const char* |
key |
Key in format section.key (.key for no section) |
const char* |
default_value |
Default value to return if key isn't found |
const char** |
out |
Out argument where result is stored if found. Caller must free() this memory. |
RETURNS
bool |
True if property was found |
void HConfigFile()
Each game session has a single config file that holds all parameters from game.project and any overridden values.
PARAMETERS
Declare and register new config file extension to the engine. Each get function should return true if it sets a proper value. Otherwise return false.
symbol |
external extension symbol description (no quotes). |
name |
extension name. Human readable. |
init |
init function. May be null. |
get_string |
Gets a string property. May be null. |
get_int |
Gets an int property. May be null. |
get_float |
Gets a float property. May be null. |
EXAMPLES
Register a new config file extension:DM_DECLARE_CONFIGFILE_EXTENSION(MyConfigfileExtension, "MyConfigfileExtension", create, destroy, get_string, get_int, get_float);