13 #include "input/inputManager.h"
16 /// ***** Private Method Headers *****
23 void updateFPSCounters();
30 /// ***** MAIN Method *****
40 /// ***** Private Variables *****
42 // variable used to determine if it is time to shutdown
45 /* Values for the main game loop
46 * target_UPS := the amount of updates that is wanted in one second
47 * last_Update := stores the time of the last update
48 * update_Sum := used to determine the updates needs for this run
50 * ups := updates per second for the last second
51 * fps := frames per second for the last second
52 * update_Count := counts this seconds updates
53 * draw_Count := counts this seconds draws
54 * last_Second := stores the time of the last second, used for ups and fps
57 long int last_Block_Update;
61 int update_Count, draw_Count;
65 /// ***** Private Methods *****
76 cout << "Initialization Complete" << endl;
79 // create starting entities
82 cout << "World Created" << endl;
89 last_Block_Update = tickCountMicro();
90 last_Second = tickCountMicro();
107 long int start = tickCountMicro();
109 // Calculate the updates that should be run for the next draw
110 update_Sum += (start - last_Block_Update) / (1000000 / (float)target_UPS);
112 // insures the float to int cast is done once.
113 int iupdate_sum = (int)update_Sum;
115 // TODO the main run loop needs to be tested and pruned
118 // Calculate a time step that spreads the updates out as much as possible
119 // used because really quick updates are nearly wasted
120 float time_step = ((float)(start - last_Block_Update)) / iupdate_sum;
123 for (int i = 1; i <= iupdate_sum; i++)
126 update(time_step*i / 1000);
128 // remove the updates that where run from the sum
129 update_Sum -= iupdate_sum;
130 last_Block_Update = tickCountMicro();
134 void updateFPSCounters()
136 // Check if a second has passed to recalculate UPS and FPS
137 if (tickCountMicro() - last_Second >= 1000000)
144 last_Second = tickCountMicro();
154 if(isPressed(SDLK_ESCAPE))
158 void update(float time_step)
162 gameUpdate(time_step);
171 SDL_GL_SwapBuffers();
173 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);