void demo_speed_set(int speed)
{
if (SPEED_NONE <= speed && speed < SPEED_MAX)
- {
- /*
- * I am torn between the desire to fix the division by zero
- * when speed is SPEED_NONE and the knowledge that, on all
- * modern architectures, the result will be an infinity, which
- * seems well suited for our purposes.
- */
- lockstep_scl(&update_step, 1.0f / SPEED_FACTORS[speed]);
- }
+ lockstep_scl(&update_step, SPEED_FACTORS[speed]);
}
/*---------------------------------------------------------------------------*/
void lockstep_run(struct lockstep *ls, float dt)
{
- ls->at += dt;
+ ls->at += dt * ls->ts;
- while (ls->at >= ls->dt * ls->ts)
+ while (ls->at >= ls->dt)
{
ls->step(ls->dt);
- ls->at -= ls->dt * ls->ts;
+ ls->at -= ls->dt;
}
}
void lockstep_scl(struct lockstep *ls, float ts)
{
- /*
- * Depending on the size of the previous time scale, there may be
- * a lot of time left in the accumulator. Mind-blowing hack: just
- * reset the accumulator.
- */
- ls->at = 0;
ls->ts = ts;
}