GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


SDL_GetTicks() overlfow by taby
1
 
// floating point representation of the timestep
static float dt_fp = static_cast<float>(dt) / 1000.0f; // ~1000 ticks per second using SDL_GetTicks()

static Uint32 previous_time = 0;
static Uint32 accumulated_time = 0;
Uint32 current_time = SDL_GetTicks();

// handle integer overflow from SDL_GetTicks()
if(current_time < previous_time)
{
    previous_time = current_time;
    continue;
}

accumulated_time += current_time - previous_time;
previous_time = current_time;

// while the accumulated time is larger than or equal to our time slice,
// proceed forward in time
while(accumulated_time >= dt)
{
    accumulated_time -= dt;

    advance_sim(dt_fp);
}

// Call the user defined Draw function
OpenGL_Draw();