]> git.itanic.dy.fi Git - sdl-planets/commitdiff
main loop: Fade correctly when simulation runs fast
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Apr 2010 16:33:53 +0000 (19:33 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Apr 2010 16:33:53 +0000 (19:33 +0300)
There was a bug that buffer fade amount was relative to the time it
took to run one simulation step, not relatively to the time interval
between two drawn frame. This patch fixes the issue.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index 87150f8f6d939e6f5e4ed6e927dcb3989acc03dd..7256fa48c3bac21ade6972d20b38cf684b2564b0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -168,7 +168,7 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
        int last_framecount = 0, last_step_count = 0;
        unsigned long old_ticks, ticks = 0, last_frame_tick = 0;
        unsigned long step_count = 0;
-       double last_fps = 0, last_sps = 0;
+       double last_fps = 0, last_sps = 0, fade_amount;
        double step_time = 0, true_time = 0;
 
        init_camera(&camera);
@@ -221,14 +221,14 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
                if (last_frame_tick + (1000 * 1000) / MAX_FPS > ticks)
                        continue;
 
-               last_frame_tick = ticks;
-
                SDL_LockSurface(screen);
 
                if (status.tracers_enabled &&
                    !camera.speed.x && !camera.speed.y &&
                    camera.zoom_rate == 1) {
-                       fade_buf(screen, 10 * true_time);
+                       fade_amount = (ticks - last_frame_tick) /
+                               (1000 * 1000.0) * 20;
+                       fade_buf(screen, fade_amount);
                } else {
                        clear_buf(screen);
                }
@@ -242,6 +242,8 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
 
                SDL_Flip(screen);
 
+               last_frame_tick = ticks;
+
                if (last_fps_time + (500 * 1000) < ticks) {
                        last_framecount = framecount - last_framecount;
                        last_fps = last_framecount * 1000 * 1000 /