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

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

Get the timer to talk milliseconds instead of seconds.

  • Property svn:keywords set to Id
File size: 1.6 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"
[132]17#include "debugsprite.h"
[144]18#include "debugrecord.h"
[79]19#include "game.h"
[96]20#include "ticker.h"
[122]21#include "profiler.h"
[108]22#include "video.h"
[14]23
[118]24static float const FPS = 30.0f;
[116]25
[38]26int main(int argc, char **argv)
27{
[108]28    /* Initialise SDL */
29    if (SDL_Init(SDL_INIT_VIDEO) < 0)
30    {
31        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
32        return EXIT_FAILURE;
33    }
34
35    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
36    if (!video)
37    {
38        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
39        SDL_Quit();
40        return EXIT_FAILURE;
41    }
42
[144]43    SDL_WM_SetCaption("Map Test (SDL)", NULL);
[108]44    SDL_ShowCursor(0);
45    SDL_WM_GrabInput(SDL_GRAB_ON);
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();
[132]56    new DebugSprite(game);
[145]57    //new DebugRecord("lolengine.ogg");
[103]58
[102]59    while (!game->Finished())
[20]60    {
[108]61        /* Tick the game */
[116]62        Ticker::TickGame();
[108]63
[122]64        /* Clear the screen, tick the renderer, show the frame and
65         * clamp to desired framerate. */
[108]66        Video::Clear();
[116]67        Ticker::TickRender();
[108]68        SDL_GL_SwapBuffers();
[149]69        Ticker::ClampFps(1000.0f / FPS);
[13]70    }
[14]71
[108]72    SDL_Quit();
[14]73
[18]74    return EXIT_SUCCESS;
[13]75}
76
Note: See TracBrowser for help on using the repository browser.