]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Add FPS counter
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 6 Feb 2010 09:06:13 +0000 (11:06 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 6 Feb 2010 09:06:13 +0000 (11:06 +0200)
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index b92c5531f62ac3357c25e1e6f0848d16f5b8278e..ba322840960a1cf6ebb5483252db9854d1db3204 100644 (file)
--- a/main.c
+++ b/main.c
@@ -23,8 +23,10 @@ static void loop(SDL_Surface *screen)
        int num_of_planets = 100;
        struct planet planet[num_of_planets];
        SDL_Event event;
-       int i, j, old_ticks, ticks, framecount = 0;
-       double time = 0;
+       int i, j;
+       int old_ticks, ticks, framecount = 0, last_fps_time = 0;
+       int last_framecount = 0;
+       double time = 0, last_fps;
 
        for (i = 0; i < num_of_planets; i++)
                init_planet(screen, &planet[i]);
@@ -60,7 +62,15 @@ static void loop(SDL_Surface *screen)
                old_ticks = ticks;
                ticks = SDL_GetTicks();
                time = (ticks - old_ticks) / 1000.0;
-               printf("\rFrame: %d", framecount++);
+
+               if (last_fps_time + 500 < ticks) {
+                       last_framecount = framecount - last_framecount;
+                       last_fps = last_framecount * 1000 / 
+                               (float)(ticks - last_fps_time);
+                       last_framecount = framecount;
+                       last_fps_time = ticks;
+               }
+               printf("\rFrames/s: %.2f, Frame: %d", last_fps, framecount++);
        }
 }