return ret - start;
}
-static int poll_events(SDL_Surface **screen, struct camera *cam,
- double *time_scale, double time)
+struct sim_status {
+ SDL_Surface *screen;
+ struct camera *cam;
+ double time_scale;
+};
+
+static int poll_events(struct sim_status *status, double time)
{
static double time_scale_rate = 1;
SDL_Event event;
+ struct camera *cam = status->cam;
- *time_scale *= pow(time_scale_rate, time);
+ status->time_scale *= pow(time_scale_rate, time);
while (SDL_PollEvent(&event)) {
switch (event.type) {
}
break;
case SDL_VIDEORESIZE:
- *screen = SDL_SetVideoMode(event.resize.w,
- event.resize.h,
- 32,
- screen[0]->flags);
+ status->screen = SDL_SetVideoMode(event.resize.w,
+ event.resize.h,
+ 32,
+ status->screen->flags);
break;
case SDL_QUIT:
goto quit;
static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
double range)
{
+ struct sim_status status;
struct planet *planet, *pl1, *pl2;
struct camera camera;
int planets;
int last_framecount = 0, last_step_count = 0;
unsigned long old_ticks, ticks = 0, last_frame_tick = 0;
unsigned long step_count = 0;
- double last_fps = 0, time_scale = 1, last_sps = 0;
+ double last_fps = 0, last_sps = 0;
double step_time = 0, true_time = 0;
init_camera(&camera);
+ status.cam = &camera;
+ status.time_scale = 1;
+ status.screen = screen;
+
planet = malloc(sizeof(*planet));
init_planet(planet);
create_planets(planet, num_of_planets, total_mass, range);
move_camera(&camera, true_time);
- if (poll_events(&screen, &camera, &time_scale, true_time))
+ if (poll_events(&status, true_time))
return;
old_ticks = ticks;
ticks = gettime();
true_time = (ticks - old_ticks) / (1000.0 * 1000.0) ;
- step_time = true_time * time_scale;
+ step_time = true_time * status.time_scale;
step_time = MIN(step_time, 0.02);
step_count++;
printf(" \rFrames/s: %.2f, steps/s: %.2f, planets: %d"
", scale %.2f, zoom %.2f, step %d",
- last_fps, last_sps, planets, time_scale,
+ last_fps, last_sps, planets, status.time_scale,
camera.zoom, step_count);
fflush(stdout);