Fix time scaling relying on floating-point quirks
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 12 Nov 2010 10:52:04 +0000 (10:52 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 12 Nov 2010 10:52:04 +0000 (10:52 +0000)
(In other words, actually check what Nuncabola does there.)

git-svn-id: https://s.snth.net/svn/neverball/trunk@3360 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/demo.c
ball/game_common.c

index 55a8a4b..77b0c05 100644 (file)
@@ -469,15 +469,7 @@ void demo_replay_stop(int d)
 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]);
 }
 
 /*---------------------------------------------------------------------------*/
index c85baf6..7675609 100644 (file)
@@ -181,23 +181,17 @@ void lockstep_clr(struct lockstep *ls)
 
 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;
 }