Allegro and custom configuration and startup
Neil Walker

Just finished the second part to my AXL project (see sig for link, or http://retrospec.sgn.net/game-links.php?link=axl).

This one is quite simple and small, it takes an XML file (or just a parameter if you can't be arsed with xml, though that isn't the point) and stores all the stuff you'd need in allegro, like colour depth, window mode, fps, which basic modules you need running and allows you to easily load/save/modify them and it also starts up allegro in a graphical mode for you using the XML values (if you want as you might just want to use them without using the startup method). The startup method does all the stuff you usually can't be bothered to do like going through a whole series of permutations of modes you allow if the main mode fails (e.g. fullscreen//windowed/32bit/16bit) it goes through it's list you've said is ok and gets one. You can also add/remove/read custom config values. All entries auto save so there isn't anything needed once you make changes, e.g. the following code sets up windows using the XML file, reads some custom settings, writes back existing and new entries and saves the XML again.

Configuration* myConfig=new Configuration("config.xml"); //load up and set everything
int ret=myConfig->AllegroStart(); //start allegro if we wish

//get set existing and new. can be int, float, string
string name=myConfig->GetCustom("author","not set");
int lives=myConfig->GetCustom("lives",-1);
myConfig->SetCustom("lives",3);
myConfig->SetCustom("newentry",34.456);
myConfig->CapsSystem->Depth=24;
myConfig->CapsGraphics.WindowMode="fullscreen";

delete myConfig;

That's about it to start up allegro using external configurations, reading and setting new custom stuff and when you delete the object at the bottom it automatically saves everything. The XML is something like:

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <system fps="60" debugon="1" autowritemain="1" autowritecustom="1"
        enablejoystick="0" enablekeyboard="1" enablemouse="1" enablesound="1" enablemidi="1"
    />
    <graphics vsync="0" graphicsmode="1" depthpreferred="32" depthfallback="16" />
    <window width="640" height="480" autodetect="windowed" />
    <sound maxvoicearray="32" samplevolume="150" musicvolume="128" />
    <custom name="author" valuestring="Neil" />
    <custom name="badger" valuestring="badger badger badger" />
    <custom name="game" valuestring="turnips from space" />
    <custom name="score" valueint="3" />
    <custom name="gravity" valuefloat="-9.8" />
</config>

The config stuff is in the Config directory and is detailed in the updated instructions.

Thread #554793. Printed from Allegro.cc