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

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

The frame counter is now an asset object.

  • Property svn:keywords set to Id
File size: 1.8 KB
RevLine 
[100]1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
[13]5
[100]6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
[98]10#include <cstdio>
11#include <cmath>
12
[13]13#include <SDL.h>
14
[103]15#include "sdlinput.h"
[111]16#include "debugfps.h"
[79]17#include "game.h"
[96]18#include "ticker.h"
[108]19#include "video.h"
[14]20
[38]21int main(int argc, char **argv)
22{
[108]23    /* Initialise SDL */
24    if (SDL_Init(SDL_INIT_VIDEO) < 0)
25    {
26        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
27        return EXIT_FAILURE;
28    }
29
30    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
31    if (!video)
32    {
33        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
34        SDL_Quit();
35        return EXIT_FAILURE;
36    }
37
38    SDL_WM_SetCaption("Deus Hax (SDL)", NULL);
39    SDL_ShowCursor(0);
40    SDL_WM_GrabInput(SDL_GRAB_ON);
41
42    /* Initialise timer */
43    Uint32 start, ticks;
44    start = ticks = SDL_GetTicks();
45    int frames = 0;
46
47    /* Initialise OpenGL */
48    Video::Setup(video->w, video->h);
49
50    /* Create a game */
[93]51    Game *game = new Game("maps/testmap.tmx");
[13]52
[111]53    /* Register an input driver and some debug stuff */
[103]54    new SdlInput(game);
[111]55    new DebugFps();
[103]56
[102]57    while (!game->Finished())
[20]58    {
[108]59        float const delta_time = 33.33333f;
[96]60
[108]61        /* Tick the game */
62        Ticker::TickGame(delta_time);
63
64        /* Clear the screen, tick the renderer, and show the frame */
65        Video::Clear();
66        Ticker::TickRender(delta_time);
67        SDL_GL_SwapBuffers();
68
69        /* Clamp to desired framerate */
70        while (SDL_GetTicks() < ticks + (delta_time - 0.5f))
71            SDL_Delay(1);
72        ticks = SDL_GetTicks();
73        frames++;
[13]74    }
[14]75
[108]76    Uint32 total = SDL_GetTicks() - start;
77    printf("%f fps\n", 1000.0f * frames / total);
78    SDL_Quit();
[14]79
[18]80    return EXIT_SUCCESS;
[13]81}
82
Note: See TracBrowser for help on using the repository browser.