From: notaz Date: Fri, 27 Jun 2014 23:06:52 +0000 (+0300) Subject: core: different frame limiter implementation X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2%2Fhead;p=mupen64plus-pandora.git core: different frame limiter implementation should avoid useless sleeps while lagging behind --- diff --git a/source/mupen64plus-core/src/main/main.c b/source/mupen64plus-core/src/main/main.c index c1bd208..6b7a632 100755 --- a/source/mupen64plus-core/src/main/main.c +++ b/source/mupen64plus-core/src/main/main.c @@ -673,7 +673,7 @@ void new_frame(void) } } -void new_vi(void) +void new_vi_(void) { int Dif; unsigned int CurrentFPSTime; @@ -724,6 +724,62 @@ void new_vi(void) end_section(IDLE_SECTION); } +#define TOL_FRAMES 3 + +void new_vi(void) +{ + static int prev_vilimit, prev_factor; + static float counter, interval; + unsigned int now, expect; + int diff; + + if (!l_MainSpeedLimit) + return; + + if (ROM_PARAMS.vilimit != prev_vilimit || l_SpeedFactor != prev_factor) + { + double VILimitMilliseconds = 1000.0 / ROM_PARAMS.vilimit; + interval = VILimitMilliseconds * 100.0 / l_SpeedFactor; // adjust for selected emulator speed + prev_vilimit = ROM_PARAMS.vilimit; + prev_factor = l_SpeedFactor; + } + + start_section(IDLE_SECTION); + +#ifdef DBG + if(g_DebuggerActive) DebuggerCallback(DEBUG_UI_VI, 0); +#endif + + now = SDL_GetTicks(); + counter += interval; + expect = (int)counter; + diff = now - expect; + + if (diff < -200 || diff > 200) + { + counter = now - 1 * 17; + return; + } + + if (diff > TOL_FRAMES * 17) + { + //printf("lim %d\n", diff); + counter = now - TOL_FRAMES * 17; + return; + } + + if (diff < 0) + { + int time = -diff; + time -= time / 4; + DebugMessage(M64MSG_VERBOSE, " new_vi(): Waiting %ims", time); + //printf("sleep %2d\n", time); + SDL_Delay(time); + } + + end_section(IDLE_SECTION); +} + /********************************************************************************************************* * emulation thread - runs the core */