From: Timo Kokkonen Date: Wed, 13 Jul 2011 16:59:05 +0000 (+0300) Subject: quadtree: Reduce excess stats calculation X-Git-Url: http://git.itanic.dy.fi/?p=sdl-planets;a=commitdiff_plain;h=1c146f1ca9a941b66c8d3a45e9a8bdf447208826 quadtree: Reduce excess stats calculation 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 --- diff --git a/quadtree.c b/quadtree.c index 1cb9756..5412b80 100644 --- a/quadtree.c +++ b/quadtree.c @@ -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); - quadtree_recalculate_parent_stats(node, ops); return tree_parent; } /* Move the node into its new location */ node->pos = new_pos; + recalculate_parent_area_stats(node); 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); } - quadtree_recalculate_parent_stats(node, ops); return quadtree_find_parent(node); }