6 #include "handleSignal.h"
11 #include "graphics/graphics.h"
12 #include "input/inputManager.h"
16 /// ***** Private Method Headers *****
19 void sighandler( int sig );
25 void updateFPSCounters();
32 /// ***** MAIN Method *****
42 /// ***** Private Variables *****
44 // variable used to determine if it is time to shutdown
47 /* Values for the main game loop
48 * target_UPS := the amount of updates that is wanted in one second
49 * last_Update := stores the time of the last update
50 * update_Sum := used to determine the updates needs for this run
52 * ups := updates per second for the last second
53 * fps := frames per second for the last second
54 * update_Count := counts this seconds updates
55 * draw_Count := counts this seconds draws
56 * last_Second := stores the time of the last second, used for ups and fps
59 long int last_Block_Update;
63 int update_Count, draw_Count;
67 /// ***** Private Methods *****
77 cout << "Initialization Complete" << endl;
84 cout << "Cleaning up" << endl;
95 last_Block_Update = tickCountMicro();
96 last_Second = tickCountMicro();
108 long int start = tickCountMicro();
110 // Calculate the updates that should be run for the next draw
111 update_Sum += (start - last_Block_Update) / (1000000 / (float)target_UPS);
113 // insures the float to int cast is done once.
114 int iupdate_sum = (int)update_Sum;
116 // TODO the main run loop needs to be tested and pruned
119 // Calculate a time step that spreads the updates out as much as possible
120 // used because really quick updates are nearly wasted
121 float time_step = ((float)(start - last_Block_Update)) / iupdate_sum;
124 for (int i = 1; i <= iupdate_sum; i++)
127 update(time_step*i / 1000);
129 // remove the updates that where run from the sum
130 update_Sum -= iupdate_sum;
131 last_Block_Update = tickCountMicro();
135 void updateFPSCounters()
137 // Check if a second has passed to recalculate UPS and FPS
138 if (tickCountMicro() - last_Second >= 1000000)
145 last_Second = tickCountMicro();
147 //cout << "ups:\t" << ups << endl;
148 //cout << "fps:\t" << fps << endl;
158 if(wasReleased(SDLK_ESCAPE))
162 void update(float time_step)
166 gameUpdate(time_step);
175 SDL_GL_SwapBuffers();
177 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);