10 static int skip_count = 0;
11 static struct timeval tv_prev;
13 void RefreshThrottleFPS(void)
16 if (Settings.perfect_vsync)
18 gp2x_video_wait_vsync();
20 gettimeofday(&tv_prev, 0);
23 #define tvdiff(tv1, tv2) \
24 ((tv1.tv_sec - tv2.tv_sec) * 1000000 + tv1.tv_usec - tv2.tv_usec)
26 #define tvadd(tv, usec) { \
28 if (tv.tv_usec >= 1000000) { \
30 tv.tv_usec -= 1000000; \
34 #define tvsub(tv, usec) { \
36 if (tv.tv_usec < 0) { \
38 tv.tv_usec += 1000000; \
42 static void wait_to(struct timeval *tv_aim)
44 struct timeval tv_now;
49 gettimeofday(&tv_now, 0);
50 diff = tvdiff((*tv_aim), tv_now);
56 void SpeedThrottle(void)
58 struct timeval tv_now, tv_aim;
62 tvadd(tv_aim, PAL ? 19997 : 16639); // ~50.007, 19.997 ms/frame : ~60.1, 16.639 ms/frame
64 gettimeofday(&tv_now, 0);
65 tdiff = tvdiff(tv_now, tv_aim);
68 if (Settings.frameskip >= 0)
70 if (skip_count >= Settings.frameskip)
81 if (tdiff < 1024*16) // limit frameskip
84 tvsub(tv_prev, tdiff);
93 if (Settings.perfect_vsync)
95 if (tdiff <= (PAL ? 19997/2 : 16639/2))
97 struct timeval tv_tmp = tv_aim;
101 gp2x_video_wait_vsync();
102 gettimeofday(&tv_prev, 0);