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

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

Implement a better timing mechanism for fixed framerate. Accuracy is
sub-millisecond but can be improved if we get rid of SDL timers.

  • Property svn:keywords set to Id
File size: 1.4 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 "debugfps.h"
17#include "game.h"
18#include "ticker.h"
19#include "video.h"
20
21static int const FPS = 30.0f;
22
23int main(int argc, char **argv)
24{
25    /* Initialise SDL */
26    if (SDL_Init(SDL_INIT_VIDEO) < 0)
27    {
28        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
29        return EXIT_FAILURE;
30    }
31
32    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
33    if (!video)
34    {
35        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
36        SDL_Quit();
37        return EXIT_FAILURE;
38    }
39
40    SDL_WM_SetCaption("Deus Hax (SDL)", NULL);
41    SDL_ShowCursor(0);
42    SDL_WM_GrabInput(SDL_GRAB_ON);
43
44    /* Initialise OpenGL */
45    Video::Setup(video->w, video->h);
46
47    /* Create a game */
48    Game *game = new Game("maps/testmap.tmx");
49
50    /* Register an input driver and some debug stuff */
51    new SdlInput(game);
52    new DebugFps();
53
54    while (!game->Finished())
55    {
56        /* Tick the game */
57        Ticker::TickGame();
58
59        /* Clear the screen, tick the renderer, and show the frame */
60        Video::Clear();
61        Ticker::TickRender();
62        SDL_GL_SwapBuffers();
63
64        /* Clamp to desired framerate */
65        Ticker::ClampFps(FPS);
66    }
67
68    SDL_Quit();
69
70    return EXIT_SUCCESS;
71}
72
Note: See TracBrowser for help on using the repository browser.