]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Work in proggress, will crash and burn
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Tue, 18 May 2010 16:50:28 +0000 (19:50 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 23 May 2010 15:21:27 +0000 (18:21 +0300)
quadtree.c

index 9e4164464b4a5c8ab72641d7b3866ba979a9f8e3..c7a8d57104fd00d73a2731e54eca206fd250574c 100644 (file)
@@ -235,6 +235,11 @@ static int add_to_relocation_list(struct quadtree *node,
        if (node->child[1])
                nodes += add_to_relocation_list(node->child[1], head);
 
+       if (debug) {
+               printf("Adding node %p to relocation list\n", node);
+               fflush(stdout);
+       }
+
        list_add(&node->list, head);
        nodes++;
 
@@ -251,7 +256,33 @@ static void relocate_from_list(struct quadtree *start, struct quadtree *end,
                               struct quadtree_ops *ops)
 {
        struct quadtree *tmp = start, *node;
-       int i;
+       int i, d = nodes / 2;
+
+       while (nodes) {
+               if (debug) {
+                       printf("stepping %d, %d nodes left\n", d, nodes);
+                       fflush(stdout);
+               }
+
+               for (i = 0; i < d; i++)
+                       tmp = list_to_tree(tmp->list.next);
+
+               if (debug) {
+                       printf("Now moving mode %p\n", tmp);
+                       fflush(stdout);
+               }
+
+               node = list_to_tree(tmp->list.next);
+               list_del(&node->list);
+               quadtree_add(parent, node, ops);
+               nodes--;
+
+               d /= 2;
+               if (d == 0)
+                       d = nodes / 2;
+       }
+
+       return;
 
        for (i = 0; i < nodes / 2; i++)
                tmp = list_to_tree(tmp->list.next);
@@ -261,6 +292,7 @@ static void relocate_from_list(struct quadtree *start, struct quadtree *end,
        tmp = list_to_tree(node->list.prev);
 
        if (debug) {
+               printf("%d nodes to move, now at %d\n", nodes, i);
                printf("Moving node %p\n", node);
                fflush(stdout);
        }
@@ -290,9 +322,12 @@ struct quadtree *quadtree_del(struct quadtree *node,
        struct list_head *head = NULL;
        int i, nodes = 0;
 
+       validate_tree(node);
+
        if (debug) {
                printf("Deleting node %p under parent %p\n",
                               node, node->parent);
+               printf("Relocating %d children\n", node->children);
                fflush(stdout);
        }
        /*