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
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)