All pastes #411077 Raw Edit

Unnamed

public text v1 · immutable
#411077 ·published 2007-03-26 20:54 UTC
rendered paste body
#include <SDL/SDL_main.h>
#include <SDL/SDL.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "BilliardZ.h"

/* Evil global. */
ImageLoader *imageLoader;

static bool closeSplash = false;

static SDL_Surface *
setupSDL()
{
        SDL_Surface *screen;

        imageLoader = new ImageLoader();

        /* Initialize SDL */
        if (SDL_Init(SDL_INIT_VIDEO | SDL_HWSURFACE | SDL_DOUBLEBUF |
                                 SDL_INIT_TIMER) < 0)
        {
                printf("Unable to init SDL: %s\n", SDL_GetError());
                exit(1);
        }

        atexit(SDL_Quit);

        /* Set the video mode. */
        screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, 0);

        if (screen == NULL)
        {
                printf("Unable to set video mode to 240x320: %s\n", SDL_GetError());
                exit(1);
        }

        SDL_WM_SetCaption("BilliardZ", "BilliardZ");

        return screen;
}

static Uint32
cancelSplashScreen(Uint32 interval, void *)
{
        printf("Splash canceled\n");
        closeSplash = true;

        return interval;
}

#ifdef __cplusplus
extern "C" {
#endif
int
main(int, char **)
{
        PoolGame *game;
        SDL_Surface *screen;
        SDL_TimerID timerId;
        SDL_Event event;
        SplashScreen *splash;

#if 0
        printf("%u\n", 12);
        printf("%u\n", F_FROMINT(12));
        printf("%lu\n", F_FRACT(12));
        printf("%u\n", F_INT(F_FROMINT(12)));
        return 0;
#endif

        screen = setupSDL();

        /* Create the splash screen. */
        splash = new SplashScreen(screen);
        splash->render();

        timerId = SDL_AddTimer(3000, cancelSplashScreen, NULL);

        /* Create the pool game */
        game = new PoolGame(screen);

        /* Let the user cancel it. */
        while (!closeSplash)
        {
                while (SDL_PollEvent(&event))
                {
                        if (event.type == SDL_KEYDOWN ||
                                event.type == SDL_MOUSEBUTTONDOWN)
                        {
                                closeSplash = true;
                        }
                }
        }

        /* Now remove that timer. */
        SDL_RemoveTimer(timerId);

        /* Nuke the splash screen. */
        delete splash;

        /* Start the game. */
        game->start();

        /* Clean up! */
        delete game;
        delete imageLoader;

        return 0;
}
#ifdef __cplusplus
}
#endif