-
Notifications
You must be signed in to change notification settings - Fork 22
Global configuration
Configuration files can be either in JSON or INI format. JSON file loading is done by inbuilt Urho3D JSON file reading/saving functionality, INI files are processed by https://github.com/carnalis/ConfigManager library (https://discourse.urho3d.io/t/a-more-advanced-ini-parser/1449).
When game is launched a config file located in Data/Config/config.cfg
is loaded. These values are globally used in the system which can specifiy all sorts of settings that users may want to change and use between game sessions. For instance it can contain all the user configured game settings - shadow quality, texture quality, resolution, sound settings etc.
Config file content looks like this:
[engine]
// Logging
LogLevel = 1
LogName = File.log
LogQuiet = false
// Resource directories
ResourcePaths = Data;CoreData
// Window parameters
WindowWidth = 1024
WindowHeight = 768
FullScreen = false
Borderless = false
Monitor = 1
// Graphics parameters
LowQualityShadows = true
MaterialQuality = 1 // 1 - 16
MultiSample = 4 // 1-16, default 1 = none
Shadows = true
TextureAnisotropy = 16
TextureQuality = 2
TripleBuffer = true
/*
FILTER_NEAREST = 0,
FILTER_BILINEAR,
FILTER_TRILINEAR,
FILTER_ANISOTROPIC,
FILTER_NEAREST_ANISOTROPIC,
FILTER_DEFAULT,
MAX_FILTERMODES
*/
TextureFilterMode = 5
VerticalSync = true
//Audio settings
Sound = true
SoundBuffer = 100
SoundInterpolation = true
SoundMixRate = 44100
SoundStereo = true
BaseApplication::LoadINIConfig()
is the method that loads this file after starting game. To retrieve any values in the code you have to call one of these methods:
GetGlobalVar("FullScreen").GetBool();
GetGlobalVar("WindowHeight").GetInt();
GetGlobalVar("ResourcePaths").GetString();
There might be cases where you would like to load custom configuration file for specific mod or addon. You can load custom configuration file in the following way.
C++ and AngelScript
VariantMap data;
data["Filepath"] = "Data/Mods/Helpers/Config.json";
data["Prefix"] = "Debugger_";
SendEvent("LoadConfig", data);
LoadConfig
event accepts 2 parameters - Filepath and Prefix
Filepath - config file location relative to executable file
Prefix - prefix for configuration values
Data/Mods/Helpers/Config.json
file content:
{
"Developer": "Arnis"
}
In the sample all the values which will be loaded from the Data/Mods/Helpers/Config.json
file will be accessible like this:
C++ and AngelScript
GetGlobalVar("Debugger_Developer").GetString()