Yesterday I finished by saying that I was working on adding a configuration loader . I added some stub code so that I would be ready to start working right away.
I realized that while I have coded a text parser before, I never had to worry about getting configuration data out of a file. What would I actually need? Before agonizing too much over it, I thought that it was more than likely that a ready-made, well-tested solution already exists. I spent some time looking through books, notes, and Gamedev.net before finding someone asking the same question I was: isn’t there a an easy to use tool so I don’t have to reinvent this obviously already solved problem?
One suggestion was boost::program_options. I looked into it for a little bit, but another suggestion was to use TinyXML. At first, I thought that using XML was a bit overkill for configuration files. At the same time, it would be ideal for holding the levels, and if I could kill two birds with one stone, all the better. The best part? TinyXML is already in my project! It comes with the Kyra Sprite Engine.
I spent the day reading the tutorial and trying out some test code. It took me only a few moments to get an XML configuration file to load successfully, and a bit more code allowed me to view a few of the elements. I spent the evening learning how the library works, and it seems easy so far. I wish there was some better documentation out for it, though.
My configuration file used to look like:
TimerInterval 80 SpriteSize 64 LeftEdge 64 UpperEdge 64 Ball velocity 5 Player velocity 5
and I wrote it before I wrote more than a single function to help parse it.
<?xml version=”1.0″ ?>
<!– Configuration for codename: Oracle’s Eye –>
<Timerinterval interval = “80”/>
<Spritesize dimension = “64”/>
<Border leftEdge = “64” upperEdge= “64”/>
<Ball velocity = “5” />
<Player velocity = “5” />
Unfortunately, I haven’t been able to do more than grab the root element, but I’m still learning how this library works. I’ll hope to be able to finish the configuration loader within the week. Afterwards, it shouldn’t be too much more work to write a level loader with TinyXML as well.