]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Non-optimized version of quadtree is now working fully quadtree-test
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 7 Apr 2010 19:45:34 +0000 (22:45 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Wed, 7 Apr 2010 19:45:34 +0000 (22:45 +0300)
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c
planet.c

diff --git a/main.c b/main.c
index 7bbb8f6d1c022e004e84b31df4c9ad052c1e99e3..be927c7ae1518cea769236b6f5f93c19fcae4f28 100644 (file)
--- a/main.c
+++ b/main.c
@@ -266,10 +266,10 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
                        clear_buf(screen);
                }
 
-               vector_scale(&camera.pos, camera.zoom, &itr.limit[0]);
+               itr.limit[0] = camera.pos;
                vect.x = screen->w / 2;
                vect.y = screen->h / 2;
-               vector_scale(&vect, camera.zoom, &vect);
+               vector_scale(&vect, 1 / camera.zoom, &vect);
                vector_add(&itr.limit[0], &vect, &itr.limit[1]);
                vector_sub(&itr.limit[0], &vect, &itr.limit[0]);
 
index e9dadc0215fdc10958109254f2e371c411d155a4..da83d3a1d491762fb1ae8cbe0196bbae10fd9e06 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -250,33 +250,33 @@ int planet_search_rectangular(struct quadtree *node,
 {
        struct planet_search_iterator *it = qt_itr_to_planet_itr(itr);
        struct planet *p = tree_to_planet(node);
-       int directions = 0, i;
-       int up[2], left[2], right[2], down[2];
+       int direction = 0, i;
+       int up = 0, left = 0, right = 0, down = 0;
 
        for (i = 0; i < 2; i++) {
                if (it->limit[i].x < p->pos.x)
-                       left[i] = 1;
+                       left = 1;
                else
-                       right[i] = 1;
+                       right = 1;
                if (it->limit[i].y < p->pos.y)
-                       up[i] = 1;
+                       up = 1;
                else
-                       down[i] = 1;
+                       down = 1;
        }
 
-       directions |= left[0] | left[1] | up [0] | up[1] ?
-               QUADTREE_UPLEFT : 0;
-       directions |= right[0] | right[1] | up [0] | up[1] ?
-               QUADTREE_UPRIGHT : 0;
-       directions |= left[0]  | left[1]  | down [0] | down[1] ?
-               QUADTREE_DOWNLEFT :0;
-       directions |= right[0] | right[1] | down [0] | down[1] ?
-               QUADTREE_DOWNRIGHT :0;
-       directions |= (directions == (QUADTREE_UPLEFT | QUADTREE_UPRIGHT |
-                                     QUADTREE_DOWNLEFT | QUADTREE_DOWNRIGHT)) ?
-               QUADTREE_SELF : 0;
-
-       return directions;
+       if (left && up)
+               direction |= QUADTREE_UPLEFT;
+       if (right && up)
+               direction |= QUADTREE_UPRIGHT;
+       if (left && down)
+               direction |= QUADTREE_DOWNLEFT;
+       if (right && down)
+               direction |= QUADTREE_DOWNRIGHT;
+       if (direction == (QUADTREE_UPLEFT | QUADTREE_UPRIGHT |
+                         QUADTREE_DOWNLEFT | QUADTREE_DOWNRIGHT))
+               direction |= QUADTREE_SELF;
+
+       return direction;
 }
 
 void planet_draw_iterator(struct quadtree *node, struct quadtree_iterator *it)