#include "random.h"
#include "planet.h"
+#define MAX_FPS 60
+
static void fade_buf(SDL_Surface *screen, double amount)
{
int i;
struct camera camera;
int planets;
int framecount = 0, last_fps_time = 0;
- int last_framecount = 0;
- unsigned long long old_ticks, ticks;
- double time = 0, last_fps = 0, time_scale = 1;
+ int last_framecount = 0, last_step_count = 0;
+ unsigned long old_ticks, ticks = 0, last_frame_tick = 0;
+ unsigned long step_count = 0;
+ double time = 0, last_fps = 0, time_scale = 1, last_sps = 0;
init_camera(&camera);
move_planet(pl1, time * time_scale);
}
- SDL_LockSurface(screen);
+ move_camera(&camera, time);
+
+ if (poll_events(&screen, &camera, &time_scale, time))
+ return;
+ old_ticks = ticks;
+ ticks = gettime();
+ time = (ticks - old_ticks) / (1000.0 * 1000.0) ;
+ time = MIN(time, 0.02);
+ step_count++;
+
+ /*
+ * Do not draw to the screen more often than MAS_FPS
+ * per second
+ */
+ if (last_frame_tick + (1000 * 1000) / MAX_FPS > ticks)
+ continue;
+
+ last_frame_tick = ticks;
+
+ SDL_LockSurface(screen);
clear_buf(screen);
list_for_each_entry(pl1, &planet->list, list) {
SDL_Flip(screen);
- move_camera(&camera, time);
-
- if (poll_events(&screen, &camera, &time_scale, time))
- return;
-
- old_ticks = ticks;
- ticks = gettime();
- time = (ticks - old_ticks) / 1000.0;
- time = MIN(time, 0.02);
-
- if (last_fps_time + 500 < ticks) {
+ if (last_fps_time + (500 * 1000) < ticks) {
last_framecount = framecount - last_framecount;
- last_fps = last_framecount * 1000 /
+ last_fps = last_framecount * 1000 * 1000 /
(float)(ticks - last_fps_time);
last_framecount = framecount;
+
+ last_step_count = step_count - last_step_count;
+ last_sps = last_step_count * 1000 * 1000 /
+ (float)(ticks - last_fps_time);
+ last_step_count = step_count;
+
last_fps_time = ticks;
}
- printf(" \rFrames/s: %.2f, Frame: %d, planets: %d"
- ", scale %.2f, zoom %.2f",
- last_fps, framecount++, planets, time_scale,
- camera.zoom);
+
+
+ printf(" \rFrames/s: %.2f, planets: %d"
+ ", scale %.2f, zoom %.2f, steps/s: %.2f, %ld",
+ last_fps, planets, time_scale,
+ camera.zoom, last_sps, step_count);
+
+
+ framecount++;
}
}