9 static int usec_aim = 0, usec_done = 0;
10 static int skip_count = 0;
12 void RefreshThrottleFPS(void)
14 usec_aim = usec_done = skip_count = 0;
17 void SpeedThrottle(void)
19 static struct timeval tv_prev;
20 struct timeval tv_now;
21 int delta_nom = PAL ? 19997 : 16639; // ~50.007, 19.997 ms/frame : ~60.1, 16.639 ms/frame
24 if (usec_done == 0) { // first time
26 gettimeofday(&tv_prev, 0);
30 gettimeofday(&tv_now, 0);
32 usec_aim += delta_nom;
33 if (tv_now.tv_sec != tv_prev.tv_sec)
35 usec_done += tv_now.tv_usec - tv_prev.tv_usec;
38 if (Settings.frameskip >= 0)
40 if (skip_count >= Settings.frameskip)
47 else if (usec_done > usec_aim + 1024*4)
50 if (usec_done - usec_aim > 1024*32)
51 usec_done = usec_aim = 1; // too much behind, try to recover..
60 while (usec_done < usec_aim)
62 gettimeofday(&tv_now, 0);
64 if (tv_now.tv_sec != tv_prev.tv_sec)
66 usec_done += tv_now.tv_usec - tv_prev.tv_usec;
69 usec_done = usec_done - usec_aim + 1; // reset to prevent overflows