Changeset 108


Ignore:
Timestamp:
Aug 14, 2010, 11:15:41 PM (11 years ago)
Author:
sam
Message:

Get rid of SdlVideo, it was pretty useless.

Location:
trunk/src
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r105 r108  
    1111libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`
    1212
    13 test_map_SOURCES = test-map.cpp sdlvideo.cpp sdlvideo.h sdlinput.cpp sdlinput.h
     13test_map_SOURCES = test-map.cpp sdlinput.cpp sdlinput.h
    1414test_map_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`
    1515test_map_LDADD = libcommon.a
  • trunk/src/test-map.cpp

    r106 r108  
    1313#include <SDL.h>
    1414
    15 #include "sdlvideo.h"
    1615#include "sdlinput.h"
    1716#include "game.h"
    1817#include "ticker.h"
     18#include "video.h"
    1919
    2020int main(int argc, char **argv)
    2121{
    22     SdlVideo *video = new SdlVideo("Deus Hax", 640, 480);
     22    /* Initialise SDL */
     23    if (SDL_Init(SDL_INIT_VIDEO) < 0)
     24    {
     25        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
     26        return EXIT_FAILURE;
     27    }
     28
     29    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
     30    if (!video)
     31    {
     32        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
     33        SDL_Quit();
     34        return EXIT_FAILURE;
     35    }
     36
     37    SDL_WM_SetCaption("Deus Hax (SDL)", NULL);
     38    SDL_ShowCursor(0);
     39    SDL_WM_GrabInput(SDL_GRAB_ON);
     40
     41    /* Initialise timer */
     42    Uint32 start, ticks;
     43    start = ticks = SDL_GetTicks();
     44    int frames = 0;
     45
     46    /* Initialise OpenGL */
     47    Video::Setup(video->w, video->h);
     48
     49    /* Create a game */
    2350    Game *game = new Game("maps/testmap.tmx");
    2451
    25     /* Register the input driver */
     52    /* Register an input driver */
    2653    new SdlInput(game);
    2754
    2855    while (!game->Finished())
    2956    {
    30         Ticker::TickGame(33.33333f);
     57        float const delta_time = 33.33333f;
    3158
    32         video->PreRender();
    33         Ticker::TickRender(33.33333f);
    34         video->PostRender(33.33333f);
     59        /* Tick the game */
     60        Ticker::TickGame(delta_time);
     61
     62        /* Clear the screen, tick the renderer, and show the frame */
     63        Video::Clear();
     64        Ticker::TickRender(delta_time);
     65        SDL_GL_SwapBuffers();
     66
     67        /* Clamp to desired framerate */
     68        while (SDL_GetTicks() < ticks + (delta_time - 0.5f))
     69            SDL_Delay(1);
     70        ticks = SDL_GetTicks();
     71        frames++;
    3572    }
    3673
    37     delete video;
     74    Uint32 total = SDL_GetTicks() - start;
     75    printf("%f fps\n", 1000.0f * frames / total);
     76    SDL_Quit();
    3877
    3978    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.