]> git.itanic.dy.fi Git - sdl-planets/blobdiff - quadtree.h
quadtree: Allow updating other than just quadtree stats
[sdl-planets] / quadtree.h
index 917abd501b34dec4e6fea636c51590ddfef44bc4..0784147d50c58264ee08b02296b59eea3bbde3b9 100644 (file)
@@ -15,7 +15,16 @@ struct quadtree {
 };
 
 struct quadtree_ops {
+       /*
+        * Comparison function that is needed to find out the correct
+        * location for a node in the tree
+        */
        int (*compare)(struct quadtree *a, struct quadtree *b);
+
+       /*
+        * Calculates required statistical information for a node
+        */
+       void (*recalculate_stats)(struct quadtree *node);
 };
 
 static inline void init_quadtree(struct quadtree *t)
@@ -59,7 +68,8 @@ static inline struct quadtree *quadtree_find_parent(const struct quadtree *node)
  * Recursively walk through the tree and propagate changes made to the
  * given node up until the highest parent.
  */
-static inline void quadtree_recalculate_parent_stats(struct quadtree *node)
+static inline void quadtree_recalculate_parent_stats(struct quadtree *node,
+                                                    struct quadtree_ops *ops)
 {
        int i;
 
@@ -76,6 +86,9 @@ static inline void quadtree_recalculate_parent_stats(struct quadtree *node)
                        node->children += node->child[i]->children + 1;
                }
 
+               if (ops->recalculate_stats)
+                       ops->recalculate_stats(node);
+
                node = node->parent;
        }
 }