]> git.itanic.dy.fi Git - sdl-planets/commitdiff
quadtree: Reduce excess stats calculation
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 13 Jul 2011 16:59:05 +0000 (19:59 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 13 Jul 2011 17:05:06 +0000 (20:05 +0300)
There is no need to explicitly recalculate the tree stats when a node
is moved from one place from the into another. As the node is added to
the tree, the stats are being recalculated automatically.

When the node is merely moved within the tree and the tree topology
doesn't change, it is sufficient to only recalculate the tree area
statistics. When some other usage is implemented for the tree
statistics, the need for more accurate statistics might change.

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

index 1cb97563874d51770f73a89c7183883d934dbd43..5412b8031cf2fe3007aa8a350105473931a5ca50 100644 (file)
@@ -820,12 +820,12 @@ struct quadtree *quadtree_move(struct quadtree *node, struct vector new_pos,
                tree_parent = quadtree_del(node, ops);
                node->pos = new_pos;
                quadtree_add(tree_parent, node, ops);
                tree_parent = quadtree_del(node, ops);
                node->pos = new_pos;
                quadtree_add(tree_parent, node, ops);
-               quadtree_recalculate_parent_stats(node, ops);
                return tree_parent;
        }
 
        /* Move the node into its new location */
        node->pos = new_pos;
                return tree_parent;
        }
 
        /* Move the node into its new location */
        node->pos = new_pos;
+       recalculate_parent_area_stats(node);
 
        if (node->children) {
                /*
 
        if (node->children) {
                /*
@@ -840,7 +840,6 @@ struct quadtree *quadtree_move(struct quadtree *node, struct vector new_pos,
                check_for_crossed_subnodes(node, limit, ops);
        }
 
                check_for_crossed_subnodes(node, limit, ops);
        }
 
-       quadtree_recalculate_parent_stats(node, ops);
        return quadtree_find_parent(node);
 
 }
        return quadtree_find_parent(node);
 
 }