Home Saving/restoring rendering window configuration
Post
Cancel

Saving/restoring rendering window configuration

I've added startup loading/saving capability today in my configuration class. I'm writing everything to simple xml file, it's structure looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<configuration>
<window width="800" height="600" xpos="0" ypos="0" 
hz="75" bpp="32" FSAA="0" fullscreen="true" vsync="true"/>
	<startupDialog>true</startupDialog>
	<paths>
		<material>material</material>
		<music>music</music>
		<sfx>sfx</sfx>
		<maps>maps</maps>
		<scripts>scripts</scripts>
		<models>models</models>
		<fonts>fonts</fonts>
		<movies>movies</movies>
	</paths>
</configuration>

Paths are not used yet and hold example values. For XML parsing I've used rapidXML. It was really easy to include it into my project. Firstly I've considered tinyXML, but rapidXML is alot faster and it is contained in single header file. (thanks to Sqward for pointing me out this parser! ;))

The only issue that I had was with example from documentation depicting iterating through nodes and attributes. Sample below is for nodes only, but for attribute case looks pretty similar, only methods are a bit different:

1
2
3
4
for (rapidxml::xml_node<> *node = doc.first_node("nodeName"); node; node = node->next_sibling())
{
   // do something with node 
}

The code above resulted in endless loop in Visual Studio 2010 express compiler. I didn't tried it with gcc yet - it looked like node==0 case was skipped and node was set to the first one resulting in a loop. So I had to replace it with something like this:

1
2
3
4
5
rapidxml::xml_node<> *node = doc.first_node("nodeName");
 while(node){
                 //do something for each node
         node=node->next_sibling();
 }

With above XML structure I can specify desired resolution, window size and it's position (if not in fullscreen mode), enable/disable fullscreen, set up paths to various engine resources such us scripts, material, textures, prerendered movies, background music and so on. I can also disable startup dialog and depend only on settings from configuration file.

The only two, three things are still missing. One is setting custom base directory, so all resources would be searched in paths relative to base directory. At this moment I've set the base directory as the application directory for Windows and user $HOME under Linux.

Second thing is overriding some configuration variables from commandline. But I will save it for later. Third thing, XML could have a validation of some sort during load, to eliminate disaster if file is edited by hand or in case some settings are missing.

The logic behind saving/restoring configuration is simple. If no "config.ini' (my default configuration file) is present configuration is set up with default, most common values. After that there is a check if startup dialog has to be shown (which looks like in my previous post). If yes, values are used to set up desired resolution, windowed/fullscreen and so on. Else user is prompted to choose various options from dialog. Configuration is updated afterwards, so the same settings will be used on the next launch.

Anyway this was a very boring part, I’m glad it’s over ;).

This post is licensed under CC BY 4.0 by the author.