[100] | 1 | // |
---|
| 2 | // Deus Hax (working title) |
---|
[221] | 3 | // Copyright (c) 2010-2011 Sam Hocevar <sam@hocevar.net> |
---|
[100] | 4 | // |
---|
[13] | 5 | |
---|
[100] | 6 | #if defined HAVE_CONFIG_H |
---|
| 7 | # include "config.h" |
---|
| 8 | #endif |
---|
| 9 | |
---|
[98] | 10 | #include <cstdio> |
---|
| 11 | #include <cmath> |
---|
[218] | 12 | #if defined _WIN32 |
---|
| 13 | # include <direct.h> |
---|
| 14 | #endif |
---|
[98] | 15 | |
---|
[13] | 16 | #include <SDL.h> |
---|
| 17 | |
---|
[150] | 18 | #include "core.h" |
---|
[221] | 19 | #include "game.h" |
---|
[103] | 20 | #include "sdlinput.h" |
---|
[111] | 21 | #include "debugfps.h" |
---|
[132] | 22 | #include "debugsprite.h" |
---|
[208] | 23 | #include "debugsphere.h" |
---|
[144] | 24 | #include "debugrecord.h" |
---|
[203] | 25 | #include "debugstats.h" |
---|
[14] | 26 | |
---|
[622] | 27 | #if defined _WIN32 |
---|
| 28 | # undef main |
---|
| 29 | #endif |
---|
| 30 | |
---|
[118] | 31 | static float const FPS = 30.0f; |
---|
[116] | 32 | |
---|
[38] | 33 | int main(int argc, char **argv) |
---|
| 34 | { |
---|
[108] | 35 | /* Initialise SDL */ |
---|
| 36 | if (SDL_Init(SDL_INIT_VIDEO) < 0) |
---|
| 37 | { |
---|
| 38 | fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError()); |
---|
| 39 | return EXIT_FAILURE; |
---|
| 40 | } |
---|
| 41 | |
---|
[206] | 42 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
---|
| 43 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); |
---|
[108] | 44 | SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); |
---|
| 45 | if (!video) |
---|
| 46 | { |
---|
| 47 | fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError()); |
---|
| 48 | SDL_Quit(); |
---|
| 49 | return EXIT_FAILURE; |
---|
| 50 | } |
---|
| 51 | |
---|
[144] | 52 | SDL_WM_SetCaption("Map Test (SDL)", NULL); |
---|
[108] | 53 | SDL_ShowCursor(0); |
---|
[150] | 54 | //SDL_WM_GrabInput(SDL_GRAB_ON); |
---|
[108] | 55 | |
---|
[617] | 56 | Ticker::Setup(FPS); |
---|
| 57 | |
---|
[108] | 58 | /* Initialise OpenGL */ |
---|
| 59 | Video::Setup(video->w, video->h); |
---|
| 60 | |
---|
| 61 | /* Create a game */ |
---|
[218] | 62 | #if defined _WIN32 |
---|
| 63 | _chdir(".."); /* Temporary Win32 hack */ |
---|
| 64 | #endif |
---|
[208] | 65 | Game *game = new Game("maps/testmap.tmx"); |
---|
[218] | 66 | game->SetMouse(160, 96); |
---|
[13] | 67 | |
---|
[111] | 68 | /* Register an input driver and some debug stuff */ |
---|
[170] | 69 | new SdlInput(); |
---|
[227] | 70 | new DebugFps(10, 10); |
---|
[132] | 71 | new DebugSprite(game); |
---|
[208] | 72 | new DebugSphere(); |
---|
[615] | 73 | //new DebugRecord("lolengine.ogm", FPS); |
---|
[203] | 74 | new DebugStats("stats.txt"); |
---|
[103] | 75 | |
---|
[170] | 76 | while (!Ticker::Finished()) |
---|
[20] | 77 | { |
---|
[108] | 78 | /* Tick the game */ |
---|
[116] | 79 | Ticker::TickGame(); |
---|
[108] | 80 | |
---|
[616] | 81 | /* Tick the renderer, show the frame and clamp to desired framerate. */ |
---|
[154] | 82 | Ticker::TickDraw(); |
---|
[108] | 83 | SDL_GL_SwapBuffers(); |
---|
[617] | 84 | Ticker::ClampFps(); |
---|
[13] | 85 | } |
---|
[14] | 86 | |
---|
[108] | 87 | SDL_Quit(); |
---|
[14] | 88 | |
---|
[18] | 89 | return EXIT_SUCCESS; |
---|
[13] | 90 | } |
---|
| 91 | |
---|