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 | #if defined _WIN32 |
---|
13 | # include <direct.h> |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <SDL.h> |
---|
17 | |
---|
18 | #include "core.h" |
---|
19 | #include "sdlinput.h" |
---|
20 | #include "debugfps.h" |
---|
21 | #include "debugboard.h" |
---|
22 | #include "debugsprite.h" |
---|
23 | #include "debugsphere.h" |
---|
24 | #include "debugrecord.h" |
---|
25 | #include "debugstats.h" |
---|
26 | |
---|
27 | static float const FPS = 30.0f; |
---|
28 | |
---|
29 | int main(int argc, char **argv) |
---|
30 | { |
---|
31 | /* Initialise SDL */ |
---|
32 | if (SDL_Init(SDL_INIT_VIDEO) < 0) |
---|
33 | { |
---|
34 | fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError()); |
---|
35 | return EXIT_FAILURE; |
---|
36 | } |
---|
37 | |
---|
38 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
---|
39 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); |
---|
40 | SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); |
---|
41 | if (!video) |
---|
42 | { |
---|
43 | fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError()); |
---|
44 | SDL_Quit(); |
---|
45 | return EXIT_FAILURE; |
---|
46 | } |
---|
47 | |
---|
48 | SDL_WM_SetCaption("Map Test (SDL)", NULL); |
---|
49 | SDL_ShowCursor(0); |
---|
50 | //SDL_WM_GrabInput(SDL_GRAB_ON); |
---|
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("maps/testmap.tmx"); |
---|
60 | game->SetMouse(160, 96); |
---|
61 | |
---|
62 | /* Register an input driver and some debug stuff */ |
---|
63 | new SdlInput(); |
---|
64 | new DebugFps(); |
---|
65 | new DebugSprite(game); |
---|
66 | new DebugBoard(game); |
---|
67 | new DebugSphere(); |
---|
68 | //new DebugRecord("lolengine.ogg"); |
---|
69 | new DebugStats("stats.txt"); |
---|
70 | |
---|
71 | while (!Ticker::Finished()) |
---|
72 | { |
---|
73 | /* Tick the game */ |
---|
74 | Ticker::TickGame(); |
---|
75 | |
---|
76 | /* Clear the screen, tick the renderer, show the frame and |
---|
77 | * clamp to desired framerate. */ |
---|
78 | Video::Clear(); |
---|
79 | Ticker::TickDraw(); |
---|
80 | SDL_GL_SwapBuffers(); |
---|
81 | Ticker::ClampFps(1000.0f / FPS); |
---|
82 | } |
---|
83 | |
---|
84 | SDL_Quit(); |
---|
85 | |
---|
86 | return EXIT_SUCCESS; |
---|
87 | } |
---|
88 | |
---|