6
\$\begingroup\$

I have been working on a game for quite a while, and I am using Ogre3D for the rendering engine. It is getting to the point I need to move adjustable settings to a configuration file such as video settings/options, player keybindings, etc.

I am using RapidXML for parsing and loading my scenes, but I am not sure this is the best way to go about doing configurations. As a long time fan of Valve games, I know there's are just a long list of settings, basically no grouping, just a list. Where as UT games do something like

[VideoOptions] ... ...

[GameSettings] ... ...

Anyways, I am just wondering what the best way to go about this is.

\$\endgroup\$
  • 4
    \$\begingroup\$ XML is not the answer to everything. Actually, it's rarely the correct answer whatever the question is. \$\endgroup\$ – o0'. Sep 27 '10 at 13:39
  • 3
    \$\begingroup\$ XML is like violence: if it doesn't work, use more. :) \$\endgroup\$ – dash-tom-bang Sep 27 '10 at 19:27
5
\$\begingroup\$

This probably isn't the optimal solution, but I'm currently using Ogre's ConfigFile class (here is the API ref for it) for simple gfx/control/whatever config settings. Not a terribly robust solution, but it's worked fine for simple stuff.

Its format is similar to the UT example you gave, for instance:

[GraphicsSettings]
Resolution=1024 x 768
Antialiasing=2

[ControlSettings]
InvertLook=No
Sensitivity=2.0
...
\$\endgroup\$
  • \$\begingroup\$ The thing with this is that it's super easy to parse, so it's easy to write code to read it. It's also easy to change settings, you don't need to match tags or anything like that. \$\endgroup\$ – dash-tom-bang Sep 27 '10 at 19:29
4
\$\begingroup\$

You may also be interested in Boost.PropertyTree. It let's you access properties in a hierarchical manner, e.g. settings.get<int>("Graphics.Resolution.Width"). The are parsers/loaders available for XML, JSON, and more.

\$\endgroup\$
1
\$\begingroup\$

Another option is to embed a simple language like Lua and expose the configuration values you want to Lua. Then your configuration file becomes a series of assignments, and can be as complex or as simple as you like. I probably wouldn't do this just for loading configuration files, but scripting languages do come in very handy for many aspects of game development so it's worth considering.

\$\endgroup\$
  • \$\begingroup\$ This is how the excellent SciTE editor does its configuration, and while documentation on the settings could be better it's pretty convenient to be able to edit in such a "computer friendly" format. \$\endgroup\$ – dash-tom-bang Sep 29 '10 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.