Mercurial > audlegacy-plugins
diff src/paranormal/plugin.c @ 268:a1be19f8de1f trunk
[svn] - calculate FPS for frame limiter
- avoid math overflows when drawing lines
author | nenolod |
---|---|
date | Sun, 19 Nov 2006 08:12:42 -0800 |
parents | 57ec651ac031 |
children | b223e71e7024 |
line wrap: on
line diff
--- a/src/paranormal/plugin.c Sun Nov 19 07:36:02 2006 -0800 +++ b/src/paranormal/plugin.c Sun Nov 19 08:12:42 2006 -0800 @@ -126,6 +126,9 @@ static int draw_thread_fn (gpointer data) { + gfloat fps = 0.0; + guint last_time = 0, last_second = 0; + guint this_time; pn_init (); /* Used when pn_quit is called from this thread */ @@ -152,6 +155,17 @@ pn_render (); SDL_mutexV (config_mutex); + /* Compute the FPS */ + this_time = SDL_GetTicks (); + + fps = fps * .95 + (1000. / (gfloat) (this_time - last_time)) * .05; + if (this_time > 2000 + last_second) + { + last_second = this_time; + g_print ("FPS: %f\n", fps); + } + last_time = this_time; + #ifdef _POSIX_PRIORITY_SCHEDULING sched_yield(); #endif