]> git.itanic.dy.fi Git - sdl-planets/commitdiff
quadtree: Pass quadtree iterator structure to the callback functions quadtree-dev
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Thu, 8 Apr 2010 16:23:24 +0000 (19:23 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Thu, 8 Apr 2010 16:34:12 +0000 (19:34 +0300)
This is better than plain void pointer, since now the iterator can be
embedded as part of some other struct. This simplifies the design.

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

index 327ee2092b44a2646c39b1b2189a28b1e1ea4768..66cdf2847a146f291d95fb40cf288e68847140ae 100644 (file)
@@ -212,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);
@@ -227,7 +227,7 @@ 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++;
        }
 
index a97619b20d0ab8e6ecb33f1c78dc9099b8e28477..23b79cebd7595d51875618fadedc42129fd0d5b8 100644 (file)
@@ -25,8 +25,8 @@ struct quadtree_iterator {
        struct quadtree *head;
        void *ptr;
 
-       int (*direction)(struct quadtree *head, void *ptr);
-       void (*callback)(struct quadtree *head, void *ptr);
+       int (*direction)(struct quadtree *head, struct quadtree_iterator *it);
+       void (*callback)(struct quadtree *head, struct quadtree_iterator *it);
 };
 
 struct quadtree *quadtree_add(struct quadtree *parent,