source: trunk/monsterz/monsterz.cpp @ 221

Last change on this file since 221 was 221, checked in by sam, 10 years ago

Complete Lol Engine / Deus Hax / Monsterz split.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1//
2// Monsterz
3//
4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16#include <cmath>
17#if defined _WIN32
18#   include <direct.h>
19#endif
20
21#include <SDL.h>
22
23#include "core.h"
24#include "game.h"
25#include "sdlinput.h"
26#include "debugfps.h"
27#include "debugboard.h"
28
29static float const FPS = 30.0f;
30
31int main(int argc, char **argv)
32{
33    /* Initialise SDL */
34    if (SDL_Init(SDL_INIT_VIDEO) < 0)
35    {
36        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
37        return EXIT_FAILURE;
38    }
39
40    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
41    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
42    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
43    if (!video)
44    {
45        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
46        SDL_Quit();
47        return EXIT_FAILURE;
48    }
49
50    SDL_WM_SetCaption("Monsterz", NULL);
51
52    /* Initialise OpenGL */
53    Video::Setup(video->w, video->h);
54
55    /* Create a game */
56#if defined _WIN32
57    _chdir(".."); /* Temporary Win32 hack */
58#endif
59    Game *game = new Game();
60
61    /* Register an input driver and some debug stuff */
62    new SdlInput();
63    new DebugFps();
64    new DebugBoard(game);
65
66    while (!Ticker::Finished())
67    {
68        /* Tick the game */
69        Ticker::TickGame();
70
71        /* Clear the screen, tick the renderer, show the frame and
72         * clamp to desired framerate. */
73        Video::Clear();
74        Ticker::TickDraw();
75        SDL_GL_SwapBuffers();
76        Ticker::ClampFps(1000.0f / FPS);
77    }
78
79    SDL_Quit();
80
81    return EXIT_SUCCESS;
82}
83
Note: See TracBrowser for help on using the repository browser.