An example of a main.cpp-file with the class XmlApp

If you want to use XmlApp for the initialisation and basic management of your application, it is probably the best way to just copy this code into your main.cpp. Maybe little changes make sense, but are not required.

Here the code:

#define APP_XMLFILE     "data/main.xml"
#define APP_NAME        "netrinjo-example"

int the_main( int argc, char *argv[] );
int main( int argc, char *argv[] )
{
    return the_main( argc, argv );
}

#include "SDL/SDL.h"// "SDL.h" cannot be included before main, if compiling with mingw
#include "xmlapp.h"
#include "sdlmanager.h"
#include <iostream>

int the_main( int argc, char *argv[] )
{
    // attach SDL_Quit to the exit routine, to make sure, that (in X11 fullscreen-mode)
    // the desktop will appear when the program quits (even if the app crashes).
    // You can also call SDL_Quit when closing the app, but the X11-fullscreen-mode will
    // not be quitted, if the app crashes!
    atexit( SDL_Quit );
    // Construct the GameApp class (derived from BasicApp), using the program arguments
    XmlApp app( argc, argv );
    string s = string(BasicApp::getThe()->getExePath()) + APP_XMLFILE;
    // if initialisation failed, exit the program
    if( !app.init(s.c_str()) )
        return -1;
    // start the application's main loop
    return app.mainLoop();
}

For details on how the XML-file has to look like, etc. have a look at the example at http://netrinjo.sourceforge.net/


Generated on Wed May 9 17:36:09 2007 for netrinjo by  doxygen 1.5.1