2 #include "../common/settings.h"
10 static int skip_count = 0;
11 static struct timeval tv_prev;
13 #define tvdiff(tv1, tv2) \
14 ((tv1.tv_sec - tv2.tv_sec) * 1000000 + tv1.tv_usec - tv2.tv_usec)
16 #define tvadd(tv, usec) { \
18 if (tv.tv_usec >= 1000000) { \
20 tv.tv_usec -= 1000000; \
24 #define tvsub(tv, usec) { \
26 if (tv.tv_usec < 0) { \
28 tv.tv_usec += 1000000; \
32 void RefreshThrottleFPS(void)
35 if (Settings.perfect_vsync)
37 gp2x_video_wait_vsync();
39 gettimeofday(&tv_prev, 0);
40 tvsub(tv_prev, PAL ? 19997 : 16639);
43 static void wait_to(struct timeval *tv_aim)
45 struct timeval tv_now;
50 gettimeofday(&tv_now, 0);
51 diff = tvdiff((*tv_aim), tv_now);
57 void SpeedThrottle(void)
59 struct timeval tv_now, tv_aim;
60 int frame_time = PAL ? 19997 : 16639; // ~50.007, 19.997 ms/frame : ~60.1, 16.639 ms/frame
64 tvadd(tv_aim, frame_time);
66 gettimeofday(&tv_now, 0);
67 tdiff = tvdiff(tv_now, tv_aim);
70 if (Settings.frameskip >= 0)
72 if (skip_count >= Settings.frameskip)
79 else if (tdiff >= frame_time)
82 if (/*tdiff < 36*1024 &&*/ skip_count < 6) { // limit frameskip
91 tv_prev = tv_now; // something went wrong, try to recover
101 if (Settings.perfect_vsync)
103 if (tdiff <= (PAL ? 19997/2 : 16639/2))
105 struct timeval tv_tmp = tv_aim;
109 gp2x_video_wait_vsync();
110 gettimeofday(&tv_prev, 0);