13 #include "graphics/graphics.h"
14 #include "input/inputManager.h"
17 /// ***** Private Method Headers *****
24 void updateFPSCounters();
31 /// ***** MAIN Method *****
41 /// ***** Private Variables *****
43 // variable used to determine if it is time to shutdown
46 /* Values for the main game loop
47 * target_UPS := the amount of updates that is wanted in one second
48 * last_Update := stores the time of the last update
49 * update_Sum := used to determine the updates needs for this run
51 * ups := updates per second for the last second
52 * fps := frames per second for the last second
53 * update_Count := counts this seconds updates
54 * draw_Count := counts this seconds draws
55 * last_Second := stores the time of the last second, used for ups and fps
58 long int last_Block_Update;
62 int update_Count, draw_Count;
66 /// ***** 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);