]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Optimize tree handling
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Tue, 13 Apr 2010 17:00:21 +0000 (20:00 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Tue, 13 Apr 2010 17:00:21 +0000 (20:00 +0300)
planet.c

index 02249fe1113857f808b34d929c782569572b0b2a..0d2c6d57a2b43d21a13fb09c740a1348b08f58fa 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -360,6 +360,9 @@ void planet_move_iterator(struct quadtree *node, struct quadtree_iterator *it)
 {
        struct quadtree *parent;
 
+       if (node == it->head)
+               return;
+
        parent = quadtree_del(node, &planet_ops);
        quadtree_add(parent, node, &planet_ops);
 }
@@ -400,17 +403,18 @@ struct planet *move_planet(struct planet *p, const double time)
                return tree_to_planet(tree_parent);
        }
 
-       /*
-        * Now, search the subtree for any crossed children and move
-        * them into correct place within the tree.
-        */
-       it.qt_iterator.head = &p->tree;
-       it.limit[0] = p->pos;
-       it.limit[1] = new_pos;
-       it.qt_iterator.direction = planet_search_when_moving;
-       it.qt_iterator.callback = planet_move_iterator;
-       walk_quadtree(&it.qt_iterator);
-
+       if(p->tree.children) {
+               /*
+                * Now, search the subtree for any crossed children and move
+                * them into correct place within the tree.
+                */
+               it.qt_iterator.head = &p->tree;
+               it.limit[0] = p->pos;
+               it.limit[1] = new_pos;
+               it.qt_iterator.direction = planet_search_when_moving;
+               it.qt_iterator.callback = planet_move_iterator;
+               walk_quadtree(&it.qt_iterator);
+       }
        p->pos = new_pos;
 
        return tree_to_planet(quadtree_find_parent(&p->tree));