The latest addition to the GE2 is a new config system. Config system is an important part of any game. This is how all the game parameters that game designer wants can be changed.
For my config system, I did a little research to find the most easy to use API for the engine to create. I first decided to use lua which is really impressive scripting language, however it didn't actually suite my needs for the config system well enough.
So I decided to use the good old similar to xml way. Something like this I have already implemented in the first galactic engine. This time I tried to avoid many possible issues and have redesigned it a little.
This is the actual config file I am using right now (config.cfg) :
width = 640
height = 480
bpp = 32
fullscreen = true
vsync = true
compression = false
preload = false
quality = 1
mode = "GL_MIPMAP_LINEAR"
anisatropyX = 1
The primary point here is that the structure of the config shows the dependency of different engine elements, such as the textureManager on the video system. The parsing of such file would be very straightforward and easy to do.
The config itself consists of 2 parts. The ConfigReader and ConfigWriter. Reader - reads the config and writer writes the config, pretty easy. I treat each config as a collection of blocks. Every config has at-least one block - the root block. Every block can have a number of other blocks - child blocks and fields. Fields are the parameters that block stores.
In order to open the config this is all it is required to do:
ConfigBlock *block = config.reader.Open( filename );
for the writer the operation is mostly the same, however with a few exceptions:
ConfigBlock *block = config.writer.OpenAndReplace(filename);
As you can see here, the config is opened with OpenAndReplace command. It can also be opened with OpenAndMerge command. The difference for the writer is that if the config is opened with replace command, then the old file would be deleted and fully replace with a new one. However if merge is selected, then the data would be merged with an existing config data. This the feature that took me quite some time to make it right, but it is important.
The reason to include merge functionality, was because usually any save in config file doesn't require to save any other data. If we need to save only a small portion of the file, then why do we need to delete the file. This was also one common problem for the quake series configs, which were automatically rewritten everytime the game ran, very annoyoing, because most of the data was sent back to default values.
Anyway when the config is sucessfully opened it returns the ConfigBlock - this is what we are going to use for reading / writing parameters of the config.
This is done also in a straightforward way:
int width = block->GetInt("width", 640 );
int height = block->GetInt("height", 480 );
The other part of using ConfigBlock is to step into another block :
Thats probably all there is.
You should be dancing..(c)
2 days ago