I think I learned something as well. Instead of capping FPS you scale the time appropriatel instead so two machines can run on different FPS but at the same game speed.
Instead of something like
Code:
#define FPS 60
int t_prev = SDL_GetTicks();
while (game_loop) {
int t = SDL_GetTicks();
if ((t - t_prev) > 1000/FPS) /* Ticks are in milliseconds so 1000 is used instead of 1 */
next_frame();
t_prev = t;
}
void next_frame (void)
{
some_object.x_pos += some_object.x_velocity;
}
you do
Code:
#define GAME_SPEED 60
int t_prev = SDL_GetTicks();
while (game_loop) {
int t = SDL_GetTicks();
next_frame((t - t_prev)*GAME_SPEED/1000.0);
t_prev = t;
}
void next_frame (double dt)
{
some_object.x_pos += some_object.x_velocity*dt;
}
Instead of incrementing the frames one by one (like integers) you increment them using fractions which scales the changes (which is basically what you do when you increment the frames one by one except that you don't notice it since x*1 = x).