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

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

Implement the profiling system.

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