Lesson 00 - Initializing And Shutting Down The Engine

 *//* 
This lesson will show you how to initialize the basic systems needed by XuqRijBuh -- initializing video mode and Singleton and shutting down. If you're reading the source file directly, instead of the doxygen-generated document, then pay no attention to the "code" and "endcode" tags in each comment.

Procedural Overview

Code Diving!

To start off, the "xrb.hpp" header MUST be included in every source and header file, as it contains definitions necessary for the correct usage and operation of the game engine.

 */
#include "xrb.hpp"

#include "xrb_screen.hpp" // For use of the necessary Screen widget class.
#include "xrb_sdlpal.hpp" // For use of the SDLPal platform abstraction layer.

/* 
Every declaration in the game engine library is within the Xrb namespace. Although this is pedantic, it is used to avoid any possible naming collision. It turns out not to be inconvenient, because of C++'s using keyword. This using statement is used so we don't need to qualify every library type/class/etc with Xrb::
 */
using namespace Xrb;

// This is just a helper function to group all the shutdown code together.
void CleanUp ()
{
    fprintf(stderr, "CleanUp();\n");

    // Shutdown the platform abstraction layer.
    Singleton::Pal().Shutdown();
    // Shutdown the game engine singletons.  This is necessary for the
    // game engine to shutdown cleanly.
    Singleton::Shutdown();
}

int main (int argc, char **argv)
{
    fprintf(stderr, "main();\n");

    /* 
This call initializes the game engine singleton facilities. This must be done, or the engine will just not work. The singletons include:
 */
    Singleton::Initialize(SDLPal::Create, "none");

    /* 
Initialize the platform abstraction layer (Pal). Then set the window caption.
 */
    if (Singleton::Pal().Initialize() != Pal::SUCCESS)
        return 1;

    Singleton::Pal().SetWindowCaption("XuqRijBuh Lesson 00");

    /* 
This call creates the Screen object and initializes the given video mode (800x600, 32 bit color). There is no constraint on the size or aspect ratio of the screen, apart from the ability of your video hardware to handle it. The Screen object is the root widget of the GUI widget hierarchy, and does a bunch of special handling to draw its child widgets properly.
 */
    Screen *screen = Screen::Create(
        800,    // video mode/screen width
        600,    // video mode/screen height
        32,     // video mode pixel bitdepth
        false); // not fullscreen -- for now
    /* 
If the Screen failed to initialize for whatever reason (probably because the system was unable to set the video mode), screen will be NULL. If this happens, print an error message and quit with an error code.
 */
    if (screen == NULL)
    {
        // this shuts down the Pal and singletons.
        CleanUp();
        // return with an error value.
        return 2;
    }

    /* 
Here is where the game code goes. To avoid overloading your brain, for now we'll just pause for 5 seconds.
 */
    {
        fprintf(stderr, "pausing for 5000 milliseconds...\n");
        Singleton::Pal().Sleep(5000);
    }

    /* 
Delete the Screen object, and with it the entire GUI widget hierarchy.
 */
    Delete(screen);
    // this shuts down the Pal and the singletons.
    CleanUp();
    // return with success value.
    return 0;
}
/* 

Exercises

Thus concludes lesson00. Did it hurt? The fuck it didn't.


Hosted by SourceForge.net Logo -- Generated on Fri Aug 21 21:46:38 2009 for XuqRijBuh by doxygen 1.5.8