Changeset 680 for trunk/deushax


Ignore:
Timestamp:
Feb 21, 2011, 6:11:36 PM (10 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/deushax/deushax.cpp

    r622 r680  
    88#endif
    99
    10 #include <cstdio>
    11 #include <cmath>
    1210#if defined _WIN32
    1311#   include <direct.h>
    1412#endif
    1513
    16 #include <SDL.h>
     14#include "core.h"
    1715
    18 #include "core.h"
    1916#include "game.h"
     17#include "sdlapp.h"
    2018#include "sdlinput.h"
    2119#include "debugfps.h"
     
    2624
    2725#if defined _WIN32
    28 #   undef main
     26#   undef main /* FIXME: still needed? */
    2927#endif
    30 
    31 static float const FPS = 30.0f;
    3228
    3329int main(int argc, char **argv)
    3430{
    35     /* Initialise SDL */
    36     if (SDL_Init(SDL_INIT_VIDEO) < 0)
    37     {
    38         fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
    39         return EXIT_FAILURE;
    40     }
     31    SdlApp app("Map Test (SDL)", vec2i(640, 480), 30.0f);
    4132
    42     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    43     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    44     SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
    45     if (!video)
    46     {
    47         fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
    48         SDL_Quit();
    49         return EXIT_FAILURE;
    50     }
    51 
    52     SDL_WM_SetCaption("Map Test (SDL)", NULL);
    53     SDL_ShowCursor(0);
    54     //SDL_WM_GrabInput(SDL_GRAB_ON);
    55 
    56     Ticker::Setup(FPS);
    57 
    58     /* Initialise OpenGL */
    59     Video::Setup(video->w, video->h);
    60 
    61     /* Create a game */
    6233#if defined _WIN32
    6334    _chdir(".."); /* Temporary Win32 hack */
     
    7445    new DebugStats("stats.txt");
    7546
    76     while (!Ticker::Finished())
    77     {
    78         /* Tick the game */
    79         Ticker::TickGame();
    80 
    81         /* Tick the renderer, show the frame and clamp to desired framerate. */
    82         Ticker::TickDraw();
    83         SDL_GL_SwapBuffers();
    84         Ticker::ClampFps();
    85     }
    86 
    87     SDL_Quit();
     47    app.Run();
    8848
    8949    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.