]> git.itanic.dy.fi Git - sdl-planets/commitdiff
some more stuff
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 11 Apr 2010 18:27:44 +0000 (21:27 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 11 Apr 2010 18:27:44 +0000 (21:27 +0300)
main.c
planet.c
planet.h

diff --git a/main.c b/main.c
index ad9bbe6814a50b9ac0201d78ebc8f307bfc50494..04321d365170be81bf507476b6335bca6b8af1ea 100644 (file)
--- a/main.c
+++ b/main.c
@@ -210,15 +210,18 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
        itr.qt_iterator.direction = planet_search_rectangular;
        itr.qt_iterator.callback = planet_draw_iterator;
 
-       planet = malloc(sizeof(*planet));
+       planet_root = planet = malloc(sizeof(*planet));
        init_planet(planet);
        create_planets(planet, num_of_planets, total_mass, range);
 
        ticks = SDL_GetTicks();
        while (1) {
                planets = 0;
+               gravitations = 0;
 
-               gravitize_planet_tree(planet, step_time);
+               gravitize_planet_tree(planet_root, step_time);
+
+               prune_planet_tree(planet_root);
 
                list_for_each_entry(pl1, &planet_root->list, list) {
                        planet_root = move_planet(pl1, step_time);
@@ -289,11 +292,12 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
 
                printf("  \rfps: %.2f, steps/s: %.2f, planets: %d"
                       ", scale %.2f, zoom %.2f, step %ld, visible %d,"
-                      " depth %ld, c:%ld, mass %.f, area: %.f",
+                      " depth %ld, c:%ld, mass %.f, area: %.f, g: %.2f",
                       last_fps, last_sps, planets, status.time_scale,
                       camera.zoom, step_count, visible_planets,
                       planet_root->tree.depth, planet_root->tree.children,
-                      planet_root->tree_mass, planet_root->tree_area);
+                      planet_root->tree_mass, planet_root->tree_area,
+                      gravitations / (float) planets);
                fflush(stdout);
 
 
index efd96ad587360ce0524318a1376c32945027f973..96833221b1d1893692b210b6e31dff34f492dc6e 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -5,6 +5,7 @@
 #include "utils.h"
 
 struct quadtree_ops planet_ops;
+int gravitations;
 
 static void putpixel(struct SDL_Surface *screen, const int x, const int y,
                     const unsigned char r, const unsigned char g,
@@ -144,6 +145,11 @@ int gravitize_planet_with_planet(struct planet *a, struct planet *b,
        struct vector distance, sum;
        double dist, f, acc;
 
+       if (a->to_be_deleted || b->to_be_deleted)
+               return 0;
+
+       gravitations++;
+
        vector_sub(&a->pos, &b->pos, &distance);
 
        dist = vector_abs(&distance);
@@ -170,6 +176,11 @@ int gravitize_planet_with_tree(struct planet *a, struct planet *b,
        struct vector distance, sum;
        double dist, f, acc;
 
+       if (a->to_be_deleted || b->to_be_deleted)
+               return 0;
+
+       gravitations++;
+
        vector_sub(&a->pos, &b->pos, &distance);
 
        dist = vector_abs(&distance);
index 8db856a79dbddd01fee8016d8d8d1cf59b7c8fb0..446ad406c76ce26e3f514fdeded172b05db75e68 100644 (file)
--- a/planet.h
+++ b/planet.h
@@ -31,6 +31,8 @@ struct planet_search_iterator {
        SDL_Surface *screen;
 };
 
+extern int gravitations;
+
 #define list_to_planet(list_head) container_of((list_head), struct planet, list)
 
 #define tree_to_planet(qt) container_of((qt), struct planet, tree)
@@ -46,6 +48,7 @@ void gravitize_planet_tree(struct planet *p, double time);
 struct planet *merge_planets(struct planet *a, struct planet *b);
 struct planet *move_planet(struct planet *p, const double time);
 void print_planet(const struct planet *p);
+struct planet *prune_planet_tree(struct planet *p);
 
 int planet_spatial_compare(struct quadtree *a, struct quadtree *b);
 int planet_search_rectangular(struct quadtree *node,