]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Move quadtree comparison code inside quadtree.c
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 30 Oct 2010 18:56:59 +0000 (21:56 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 30 Oct 2010 19:01:23 +0000 (22:01 +0300)
The .compare function can also be removed now from the quadtree_ops
structure.

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

index 39f8c35b3a7e8084303bcdc76f04b263c6f724d5..24b2d21da259f90d280ee6fd76bfb475d23221ee 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -374,25 +374,6 @@ void print_planet(const struct planet *p)
               p->tree.pos.x, p->tree.pos.y, p->speed.x, p->speed.y, p->mass, p->radius);
 }
 
-int planet_spatial_compare(struct quadtree *ta, struct quadtree *tb)
-{
-       struct planet *a, *b;
-       int up, left;
-       a = tree_to_planet(ta);
-       b = tree_to_planet(tb);
-
-       up = b->tree.pos.y < a->tree.pos.y;
-       left = b->tree.pos.x < a->tree.pos.x;
-
-       if (up && left)
-               return 0;
-       if (up && !left)
-               return 1;
-       if (left)
-               return 2;
-       return 3;
-}
-
 int planet_search_rectangular(struct quadtree *node,
                              struct quadtree_iterator *itr)
 {
@@ -460,7 +441,6 @@ static void planet_recalculate_stats(struct quadtree *node)
 }
 
 struct quadtree_ops planet_ops = {
-       .compare = planet_spatial_compare,
        .recalculate_stats = planet_recalculate_stats,
 };
 
index 61a26997c1555a7ee5c3419633d67164051bee28..10c4ec86f3ec3d93baae1b9543e578516c3922c3 100644 (file)
@@ -99,22 +99,29 @@ static void validate_tree(const struct quadtree *node)
                validate_subtree(quadtree_find_parent(node));
 }
 
+static int quadtree_compare(struct quadtree *a, struct quadtree *b)
+{
+       int up, left;
+
+       up = b->pos.y < a->pos.y;
+       left = b->pos.x < a->pos.x;
+
+       if (up && left)
+               return 0;
+       if (up && !left)
+               return 1;
+       if (left)
+               return 2;
+       return 3;
+}
+
 /**
  * quadtree_add - add a node to a quadtree
  * @parent: parent node
  * @new: the new node to be added
- * @compare: pointer to a comparison function
  *
  * Add a node to a quadtree. The tree is kept in order, the new node
- * is placed in the end of appropriate branch. The compare function is
- * used to compare the new node against a branch in the tree. The
- * comparison function must have following return value depending on
- * the position of node a compared to the position of node b:
- *
- * 0: upper left
- * 1: upper right
- * 2: lower left
- * 3: lower right
+ * is placed in the end of appropriate branch.
  *
  * The case of nodes sharing identical coordinates is not taken into
  * account at all.
@@ -129,7 +136,7 @@ struct quadtree *quadtree_add(struct quadtree *parent, struct quadtree *new,
 
        validate_tree(parent);
 
-       ret = ops->compare(parent, new);
+       ret = quadtree_compare(parent, new);
 
        if (ret < 0 || ret >= 4) {
                printf("Invalid comparison result of %d\n", ret);
index 87f3b8c0ba2f536dc8b2276f47ec19fc315b13e8..619a67574fc045f69ed3f7ea959f42d2e1046e7a 100644 (file)
@@ -17,12 +17,6 @@ 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
         */