double range)
{
struct sim_status status;
- struct planet *planet, *pl1, *pl2;
+ struct planet *planet, *pl1, *pl2, *planet_root;
struct camera camera;
+ struct planet_search_iterator itr;
+ struct vector vect;
+
int planets;
int framecount = 0, last_fps_time = 0;
int last_framecount = 0, last_step_count = 0;
unsigned long step_count = 0;
double last_fps = 0, last_sps = 0, fade_amount;
double step_time = 0, true_time = 0;
+ int visible_planets;
init_camera(&camera);
status.screen = screen;
status.tracers_enabled = 0;
+ itr.screen = screen;
+ itr.cam = &camera;
+ itr.qt_iterator.direction = planet_search_rectangular;
+ itr.qt_iterator.callback = planet_draw_iterator;
+
planet = malloc(sizeof(*planet));
init_planet(planet);
create_planets(planet, num_of_planets, total_mass, range);
pl2 = ptmp;
}
- move_planet(pl1, step_time);
+ planet_root = move_planet(pl1, step_time);
+ planets++;
}
move_camera(&camera, true_time);
clear_buf(screen);
}
- list_for_each_entry(pl1, &planet->list, list) {
- draw_planet(screen, pl1, &camera);
- planets++;
- }
+ itr.limit[0] = camera.pos;
+ vect.x = screen->w / 2;
+ vect.y = screen->h / 2;
+ 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]);
+
+ itr.qt_iterator.head = &planet_root->tree;
+
+ visible_planets = walk_quadtree(&itr.qt_iterator);
SDL_UnlockSurface(screen);
last_fps_time = ticks;
}
-
printf(" \rFrames/s: %.2f, steps/s: %.2f, planets: %d"
- ", scale %.2f, zoom %.2f, step %ld",
+ ", scale %.2f, zoom %.2f, step %ld, visible %d",
last_fps, last_sps, planets, status.time_scale,
- camera.zoom, step_count);
+ camera.zoom, step_count, visible_planets);
fflush(stdout);