6 #include "handleSignal.h"
11 #include "graphics/graphics.h"
12 #include "input/inputManager.h"
14 /// ***** Private Method Headers *****
18 void sighandler( int sig );
24 void updateFPSCounters();
30 /// ***** Private Variables *****
32 // variable used to determine if it is time to shutdown
35 /* Values for the main game loop
36 * target_UPS := the amount of updates that is wanted in one second
37 * last_Update := stores the time of the last update
38 * update_Sum := used to determine the updates needs for this run
40 * ups := updates per second for the last second
41 * fps := frames per second for the last second
42 * update_Count := counts this seconds updates
43 * draw_Count := counts this seconds draws
44 * last_Second := stores the time of the last second, used for ups and fps
47 long int last_Block_Update;
51 int update_Count, draw_Count;
55 /// ***** MAIN Method *****
64 /// ***** Initializers/Cleaners *****
77 cout << "Initialization Complete" << endl;
84 cout << "Cleaning up" << endl;
94 /// ***** Private Methods *****
99 last_Block_Update = tickCountMicro();
100 last_Second = tickCountMicro();
112 long int start = tickCountMicro();
114 // Calculate the updates that should be run for the next draw
115 update_Sum += (start - last_Block_Update) / (1000000 / (float)target_UPS);
117 // insures the float to int cast is done once.
118 int iupdate_sum = (int)update_Sum;
120 // TODO the main run loop needs to be tested and pruned
123 // Calculate a time step that spreads the updates out as much as possible
124 // used because really quick updates are nearly wasted
125 float time_step = ((float)(start - last_Block_Update)) / iupdate_sum;
128 for (int i = 1; i <= iupdate_sum; i++)
131 update(time_step*i / 1000);
133 // remove the updates that where run from the sum
134 update_Sum -= iupdate_sum;
135 last_Block_Update = tickCountMicro();
139 void updateFPSCounters()
141 // Check if a second has passed to recalculate UPS and FPS
142 if (tickCountMicro() - last_Second >= 1000000)
149 last_Second = tickCountMicro();
152 cout << "ups:\t" << ups << endl;
153 cout << "fps:\t" << fps << endl;
164 if(wasReleased(SDLK_ESCAPE))
168 void update(float time_step)
172 gameUpdate(time_step);
181 SDL_GL_SwapBuffers();
183 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);