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 "sdlinput.h" |
---|
25 | #include "interface.h" |
---|
26 | |
---|
27 | #include "debugfps.h" |
---|
28 | #include "debugrecord.h" |
---|
29 | |
---|
30 | #if defined _WIN32 |
---|
31 | # undef main |
---|
32 | #endif |
---|
33 | |
---|
34 | static float const FPS = 60.0f; |
---|
35 | |
---|
36 | int main(int argc, char **argv) |
---|
37 | { |
---|
38 | /* Initialise SDL */ |
---|
39 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) |
---|
40 | { |
---|
41 | fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError()); |
---|
42 | return EXIT_FAILURE; |
---|
43 | } |
---|
44 | |
---|
45 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
---|
46 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); |
---|
47 | SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); |
---|
48 | if (!video) |
---|
49 | { |
---|
50 | fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError()); |
---|
51 | SDL_Quit(); |
---|
52 | return EXIT_FAILURE; |
---|
53 | } |
---|
54 | |
---|
55 | SDL_WM_SetCaption("Monsterz", NULL); |
---|
56 | SDL_ShowCursor(0); |
---|
57 | |
---|
58 | /* Initialise everything */ |
---|
59 | Ticker::Setup(FPS); |
---|
60 | Video::Setup(video->w, video->h); |
---|
61 | Audio::Setup(2); |
---|
62 | |
---|
63 | /* Create a game */ |
---|
64 | #if defined _WIN32 |
---|
65 | _chdir(".."); /* Temporary Win32 hack */ |
---|
66 | #endif |
---|
67 | |
---|
68 | /* Register an input driver and some debug stuff */ |
---|
69 | new SdlInput(); |
---|
70 | new Interface(); |
---|
71 | new DebugFps(20, 20); |
---|
72 | //new DebugRecord("monsterz.ogm", FPS); |
---|
73 | |
---|
74 | while (!Ticker::Finished()) |
---|
75 | { |
---|
76 | /* Tick the game */ |
---|
77 | Ticker::TickGame(); |
---|
78 | |
---|
79 | /* Tick the renderer, show the frame and clamp to desired framerate. */ |
---|
80 | Ticker::TickDraw(); |
---|
81 | SDL_GL_SwapBuffers(); |
---|
82 | Ticker::ClampFps(); |
---|
83 | } |
---|
84 | |
---|
85 | SDL_Quit(); |
---|
86 | |
---|
87 | return EXIT_SUCCESS; |
---|
88 | } |
---|
89 | |
---|