]> git.itanic.dy.fi Git - sdl-planets/commitdiff
continuing..
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 10 Apr 2010 19:40:53 +0000 (22:40 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 10 Apr 2010 19:40:53 +0000 (22:40 +0300)
planet.c

index 6172cdbf4281de696a945ab61b43a40a2ab562e2..b43d9b90ca249301d18a032a42dbd35a534f53c5 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -212,12 +212,13 @@ struct planet *move_planet(struct planet *p, const double time)
        struct vector tmp, new_pos;
        struct quadtree *tree_parent;
        struct planet_search_iterator it;
+       int ret;
 
        vector_scale(&p->speed, time, &tmp);
        vector_add(&p->pos, &tmp, &new_pos);
        vector_scale(&p->speed, pow(0.99, time), &p->speed);
 
-       /* 
+       /*
         * Update the quadtree if there are any planets between the
         * old and new position. If there is nothing between the old
         * and new location, there is no need to modify the tree at
@@ -226,14 +227,19 @@ struct planet *move_planet(struct planet *p, const double time)
        it.limit[0] = p->pos;
        it.limit[1] = new_pos;
        it.qt_iterator.head = quadtree_find_parent(&p->tree);
+       it.qt_iterator.direction = planet_search_rectangular;
+       it.qt_iterator.callback = NULL;
 
-       if (walk_quadtree(&it.qt_iterator)) {
-               tree_parent = quadtree_del(&p->tree, planet_spatial_compare);
-               quadtree_add(tree_parent, &p->tree, planet_spatial_compare);
-               return tree_to_planet(tree_parent);
-       }
+       ret = walk_quadtree(&it.qt_iterator);
+       p->pos = new_pos;
+
+       if (ret == 0)
+               return tree_to_planet(it.qt_iterator.head);
 
-       return tree_to_planet(it.qt_iterator.head);
+       printf("Modify tree\n");
+       tree_parent = quadtree_del(&p->tree, planet_spatial_compare);
+       quadtree_add(tree_parent, &p->tree, planet_spatial_compare);
+       return tree_to_planet(tree_parent);
 }
 
 void print_planet(const struct planet *p)