18 /// ***** Private Method Headers *****
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;
79 // create starting entities
81 cout << "World Created" << endl;
87 last_Block_Update = tickCountMicro();
88 last_Second = tickCountMicro();
105 long int start = tickCountMicro();
107 // Calculate the updates that should be run for the next draw
108 update_Sum += (start - last_Block_Update) / (1000000 / (float)target_UPS);
110 // insures the float to int cast is done once.
111 int iupdate_sum = (int)update_Sum;
113 // TODO the main run loop needs to be tested and pruned
116 // Calculate a time step that spreads the updates out as much as possible
117 // used because really quick updates are nearly wasted
118 float time_step = ((float)(start - last_Block_Update)) / iupdate_sum;
121 for (int i = 1; i <= iupdate_sum; i++)
124 update(time_step*i / 1000);
126 // remove the updates that where run from the sum
127 update_Sum -= iupdate_sum;
128 last_Block_Update = tickCountMicro();
132 void updateFPSCounters()
134 // Check if a second has passed to recalculate UPS and FPS
135 if (tickCountMicro() - last_Second >= 1000000)
142 last_Second = tickCountMicro();
156 void update(float time_step)
160 gameUpdate(time_step);
169 SDL_GL_SwapBuffers();
171 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);