Ignore:
Timestamp:
Feb 21, 2011, 6:11:36 PM (11 years ago)
Author:
sam
Message:

Create the SdlApp class to avoid code duplication. Ensure USE_SDL is
tested wherever relevant.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/monsterz.cpp

    r622 r680  
    1313#endif
    1414
    15 #include <cstdio>
    16 #include <cmath>
    1715#if defined _WIN32
    1816#   include <direct.h>
    1917#endif
    2018
    21 #include <SDL.h>
     19#include "core.h"
    2220
    23 #include "core.h"
     21#include "sdlapp.h"
    2422#include "sdlinput.h"
    2523#include "interface.h"
     
    2927
    3028#if defined _WIN32
    31 #   undef main
     29#   undef main /* FIXME: still needed? */
    3230#endif
    33 
    34 static float const FPS = 60.0f;
    3531
    3632int main(int argc, char **argv)
    3733{
    38     /* Initialise SDL */
    39     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
    40     {
    41         fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
    42         return EXIT_FAILURE;
    43     }
     34    SdlApp app("Monsterz", vec2i(640, 480), 60.0f);
    4435
    45     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    46     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    47     SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
    48     if (!video)
    49     {
    50         fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
    51         SDL_Quit();
    52         return EXIT_FAILURE;
    53     }
    54 
    55     SDL_WM_SetCaption("Monsterz", NULL);
    56     SDL_ShowCursor(0);
    57 
    58     /* Initialise everything */
    59     Ticker::Setup(FPS);
    60     Video::Setup(video->w, video->h);
    61     Audio::Setup(2);
    62 
    63     /* Create a game */
    6436#if defined _WIN32
    6537    _chdir(".."); /* Temporary Win32 hack */
     
    7244    //new DebugRecord("monsterz.ogm", FPS);
    7345
    74     while (!Ticker::Finished())
    75     {
    76         /* Tick the game */
    77         Ticker::TickGame();
    78 
    79         /* Tick the renderer, show the frame and clamp to desired framerate. */
    80         Ticker::TickDraw();
    81         SDL_GL_SwapBuffers();
    82         Ticker::ClampFps();
    83     }
    84 
    85     SDL_Quit();
     46    app.Run();
    8647
    8748    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.