source: trunk/src/test-map.cpp @ 108

Last change on this file since 108 was 108, checked in by sam, 11 years ago

Get rid of SdlVideo, it was pretty useless.

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdio>
11#include <cmath>
12
13#include <SDL.h>
14
15#include "sdlinput.h"
16#include "game.h"
17#include "ticker.h"
18#include "video.h"
19
20int main(int argc, char **argv)
21{
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 */
50    Game *game = new Game("maps/testmap.tmx");
51
52    /* Register an input driver */
53    new SdlInput(game);
54
55    while (!game->Finished())
56    {
57        float const delta_time = 33.33333f;
58
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++;
72    }
73
74    Uint32 total = SDL_GetTicks() - start;
75    printf("%f fps\n", 1000.0f * frames / total);
76    SDL_Quit();
77
78    return EXIT_SUCCESS;
79}
80
Note: See TracBrowser for help on using the repository browser.