Configuration file access functions. The configuration file is compiled version of the game.project file.
Namespace: | dmConfigFile |
Include: | #include <dmsdk/dlib/configfile.h> |
TYPES | |
---|---|
dmConfigFile::HConfig | HConfig type definition |
FUNCTIONS | |
---|---|
const char* dmConfigFile::GetString(dmConfigFile::HConfig config, const char* key, const char* default_value) | get config value as string |
int32_t dmConfigFile::GetInt(dmConfigFile::HConfig config, const char* key, int32_t default_value) | get config value as int |
float dmConfigFile::GetFloat(dmConfigFile::HConfig config, const char* key, float default_value) | get config value as float |
MACROS | |
---|---|
DM_DECLARE_CONFIGFILE_EXTENSION(symbol, name, init, get_string, get_int, get_float) | declare a new config file extension |
const char* dmConfigFile::GetString(dmConfigFile::HConfig config, const char* key, const char* default_value)
Get config value as string, returns default if the key isn't found
PARAMETERS
dmConfigFile::HConfig |
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 dmExtension::Result AppInitialize(dmExtension::AppParams* params)
{
const char* projectTitle = dmConfigFile::GetString(params->m_ConfigFile, "project.title", "Untitled");
}
int32_t dmConfigFile::GetInt(dmConfigFile::HConfig config, const char* key, int32_t default_value)
Get config value as int, returns default if the key isn't found Note: default_value is returned for invalid integer values
PARAMETERS
dmConfigFile::HConfig |
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 dmExtension::Result AppInitialize(dmExtension::AppParams* params)
{
int32_t displayWidth = dmConfigFile::GetInt(params->m_ConfigFile, "display.width", 640);
}
float dmConfigFile::GetFloat(dmConfigFile::HConfig config, const char* key, float default_value)
Get config value as float, returns default if the key isn't found Note: default_value is returned for invalid float values
PARAMETERS
dmConfigFile::HConfig |
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 |
RETURNS
float |
found value or default value |
EXAMPLES
static dmExtension::Result AppInitialize(dmExtension::AppParams* params)
{
float gravity = dmConfigFile::GetFloat(params->m_ConfigFile, "physics.gravity_y", -9.8f);
}
typedef struct Config* HConfig;
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);