]> git.itanic.dy.fi Git - sdl-planets/commitdiff
main.c: Skip simulation when time step is zero
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 13 Jun 2010 13:04:57 +0000 (16:04 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 13 Jun 2010 13:04:57 +0000 (16:04 +0300)
When user has set the simulation speed to zero, there is no need to
run the simulation at all, as it won't be changing anyway. This makes
it possible to run excessively large simulations and occassionally
freeze the simulation. Then, for example, inspecting the tree topology
(if draw_lines variable is enabled) becomes easier without need to
worry about slow camera movement.

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

diff --git a/main.c b/main.c
index f2a012cf50d24036580df98f060e70e9c8e776aa..eb1b127c14058c2c3a5cce379d51c17134826d06 100644 (file)
--- a/main.c
+++ b/main.c
@@ -221,23 +221,25 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
        while (1) {
                planets = 0;
 
-               list_for_each_entry(pl1, &planet->list, list) {
-                       pl2 = list_to_planet(pl1->list.next);
-                       list_for_each_entry_from(pl2, &planet->list, list) {
-                               struct planet *ptmp;
-                               if (!gravitize_planets(pl1, pl2,
-                                                      step_time))
-                                       continue;
-
-                               ptmp = list_to_planet(pl2->list.prev);
-                               merge_planets(pl1, pl2);
-                               pl2 = ptmp;
+               if (status.time_scale > 0) {
+                       list_for_each_entry(pl1, &planet->list, list) {
+                               pl2 = list_to_planet(pl1->list.next);
+                               list_for_each_entry_from(pl2, &planet->list,
+                                                        list) {
+                                       struct planet *ptmp;
+                                       if (!gravitize_planets(pl1, pl2,
+                                                              step_time))
+                                               continue;
+
+                                       ptmp = list_to_planet(pl2->list.prev);
+                                       merge_planets(pl1, pl2);
+                                       pl2 = ptmp;
+                               }
+
+                               planet_root = move_planet(pl1, step_time);
+                               planets++;
                        }
-
-                       planet_root = move_planet(pl1, step_time);
-                       planets++;
                }
-
                move_camera(&camera, true_time);
 
                if (poll_events(&status, true_time))