]> git.itanic.dy.fi Git - sdl-planets/blobdiff - quadtree.c
Non-optimized version of quadtree is now working fully
[sdl-planets] / quadtree.c
index 94a37c1775f438bbc0e44bbc1fafc402c5dc480d..66cdf2847a146f291d95fb40cf288e68847140ae 100644 (file)
@@ -1,10 +1,18 @@
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "quadtree.h"
 
-void trap(void )
+#ifdef DEBUG
+#define debug 1
+#else
+#define debug 0
+#endif
+
+static void trap(void )
 {
-       exit(1);
+       if (debug)
+               exit(1);
 }
 
 static void validate_subtree(const struct quadtree *node)
@@ -36,9 +44,8 @@ static void validate_subtree(const struct quadtree *node)
 
 static void validate_tree(const struct quadtree *node)
 {
-       const struct quadtree *parent = quadtree_find_parent(node);
-
-       validate_subtree(parent);
+       if (debug)
+               validate_subtree(quadtree_find_parent(node));
 }
 
 /**
@@ -205,7 +212,7 @@ static int _walk_tree(struct quadtree *head, const struct quadtree_iterator *it)
 {
        int direction, count = 0;
 
-       direction = it->direction(head, it->ptr);
+       direction = it->direction(head, (struct quadtree_iterator *)it);
 
        if ((direction & QUADTREE_UPLEFT) && head->child[0])
                count += _walk_tree(head->child[0], it);
@@ -220,14 +227,14 @@ static int _walk_tree(struct quadtree *head, const struct quadtree_iterator *it)
                count += _walk_tree(head->child[3], it);
 
        if ((direction & QUADTREE_SELF) && it->callback) {
-               it->callback(head, it->ptr);
+               it->callback(head, (struct quadtree_iterator *)it);
                count++;
        }
 
        return count;
 }
 
-int walk_tree(const struct quadtree_iterator *it)
+int walk_quadtree(const struct quadtree_iterator *it)
 {
        return _walk_tree(it->head, it);
 }