comparison 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
comparison
equal deleted inserted replaced
267:89e1003e5e84 268:a1be19f8de1f
124 } 124 }
125 125
126 static int 126 static int
127 draw_thread_fn (gpointer data) 127 draw_thread_fn (gpointer data)
128 { 128 {
129 gfloat fps = 0.0;
130 guint last_time = 0, last_second = 0;
131 guint this_time;
129 pn_init (); 132 pn_init ();
130 133
131 /* Used when pn_quit is called from this thread */ 134 /* Used when pn_quit is called from this thread */
132 if (setjmp (quit_jmp) != 0) 135 if (setjmp (quit_jmp) != 0)
133 pn_done = TRUE; 136 pn_done = TRUE;
149 } 152 }
150 SDL_mutexV (sound_data_mutex); 153 SDL_mutexV (sound_data_mutex);
151 SDL_mutexP (config_mutex); 154 SDL_mutexP (config_mutex);
152 pn_render (); 155 pn_render ();
153 SDL_mutexV (config_mutex); 156 SDL_mutexV (config_mutex);
157
158 /* Compute the FPS */
159 this_time = SDL_GetTicks ();
160
161 fps = fps * .95 + (1000. / (gfloat) (this_time - last_time)) * .05;
162 if (this_time > 2000 + last_second)
163 {
164 last_second = this_time;
165 g_print ("FPS: %f\n", fps);
166 }
167 last_time = this_time;
154 168
155 #ifdef _POSIX_PRIORITY_SCHEDULING 169 #ifdef _POSIX_PRIORITY_SCHEDULING
156 sched_yield(); 170 sched_yield();
157 #endif 171 #endif
158 } 172 }