2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "handleSignal.h"
28 #include "graphics/graphics.h"
29 #include "input/inputManager.h"
30 #include "config/config.h"
32 /// ***** Private Method Headers *****
36 void sighandler( int sig );
41 void updateFPSCounters();
47 /// ***** Private Variables *****
49 // variable used to determine if it is time to shutdown
52 /* Values for the main game loop
53 * target_UPS := the amount of updates that is wanted in one second
55 * ups := updates per second for the last second
56 * fps := frames per second for the last second
57 * update_Count := counts this seconds updates
58 * draw_Count := counts this seconds draws
59 * last_Second := stores the time of the last second, used for ups and fps
64 int update_Count, draw_Count;
67 int startUpdateThread(void*);
68 int startDrawThread(void*);
70 /// ***** MAIN Method *****
71 int main(int argc, char** args)
79 /// ***** Initializers/Cleaners *****
86 DPF(0, "Graphics initialized");
89 DPF(0, "Game initialized");
92 DPF(0, "Input initialized");
95 DPF(0, "Configs initialized");
97 DPF(0, "Initialization Complete");
102 DPF(0, "Cleaning up");
113 /// ***** Private Methods *****
119 SDL_Thread* updates = SDL_CreateThread(startUpdateThread, NULL);
121 startDrawThread(NULL);
123 SDL_WaitThread(updates, NULL);
126 void updateFPSCounters()
128 // Check if a second has passed to recalculate UPS and FPS
129 if (tickCountMicro() - last_Second >= 1000000)
134 // NOT thread safe, but they're estimates anyways
138 last_Second = tickCountMicro();
141 cout << "ups:\t" << ups << endl;
142 cout << "fps:\t" << fps << endl;
157 void update(float time_step)
159 game::update(time_step);
167 SDL_GL_SwapBuffers();
169 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
174 int startUpdateThread(void*)
189 int startDrawThread(void*)