http://www.koonsolo.com/news/dewitters- gameloop/
В последнем игровом цикле из статьи Гленна Фидлера Fix Your Timestep! он использует цикл обновления, который продвигает логику игры на фиксированная разница времени. Поскольку дельта времени фиксирована, почему он интегрирует на основе дельты времени? В игре с фиксированным временным интервалом движение не может быть таким простым, как:
Код: Выделить всё
if ( keyboard pressing "W" ) {
velocity += acceleration
}
position += velocity
Код: Выделить всё
if ( keyboard pressing "W" ) {
velocity += integrated(acceleration, delta_time)
}
position += velocity * delta_time
Код: Выделить всё
double t = 0.0;
double dt = 0.01;
double currentTime = hires_time_in_seconds();
double accumulator = 0.0;
State previous;
State current;
while ( !quit )
{
double newTime = time();
double frameTime = newTime - currentTime;
if ( frameTime > 0.25 )
frameTime = 0.25;
currentTime = newTime;
accumulator += frameTime;
while ( accumulator >= dt )
{
previousState = currentState;
integrate( currentState, t, dt ); // integration
t += dt;
accumulator -= dt;
}
const double alpha = accumulator / dt;
State state = currentState * alpha +
previousState * ( 1.0 - alpha );
render( state );
}
Подробнее здесь: https://stackoverflow.com/questions/433 ... r-on-games