Do not even try to draw more than 60FPS. If we have time left, do some
extra simulation steps.
As an extra bonus this patch fixes the timer usage which was broken
since we moved to higher clock resolution.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
#include "random.h"
#include "planet.h"
#include "random.h"
#include "planet.h"
static void fade_buf(SDL_Surface *screen, double amount)
{
int i;
static void fade_buf(SDL_Surface *screen, double amount)
{
int i;
struct camera camera;
int planets;
int framecount = 0, last_fps_time = 0;
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;
move_planet(pl1, time * time_scale);
}
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) {
clear_buf(screen);
list_for_each_entry(pl1, &planet->list, list) {
- 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_framecount = framecount - last_framecount;
- last_fps = last_framecount * 1000 /
+ last_fps = last_framecount * 1000 * 1000 /
(float)(ticks - last_fps_time);
last_framecount = framecount;
(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;
+
- 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++;