File use_old_vi_interrupt_speed_limiter.diff of Package mupen64plus
--- source/mupen64plus-core/src/main/main.c.orig 2015-03-18 17:19:58.000000000 +0100
+++ source/mupen64plus-core/src/main/main.c 2015-03-19 15:57:17.724412932 +0100
@@ -734,60 +734,52 @@
static void apply_speed_limiter(void)
{
+ int Dif;
unsigned int CurrentFPSTime;
static unsigned int LastFPSTime = 0;
- static int VITotalDelta;
- static int VIDeltas[64];
- static unsigned int VIDeltasIndex;
+ static unsigned int CounterTime = 0;
+ static unsigned int CalculatedTime ;
+ static int VI_Counter = 0;
double VILimitMilliseconds = 1000.0 / ROM_PARAMS.vilimit;
double AdjustedLimit = VILimitMilliseconds * 100.0 / l_SpeedFactor; // adjust for selected emulator speed
- int ThisFrameDelta, IntegratedDelta, TimeToWait;
+ int time;
timed_section_start(TIMED_SECTION_IDLE);
+ VI_Counter++;
#ifdef DBG
if(g_DebuggerActive) DebuggerCallback(DEBUG_UI_VI, 0);
#endif
- // if this is the first frame, initialize our data structures
if(LastFPSTime == 0)
{
- LastFPSTime = SDL_GetTicks();
- VITotalDelta = 0;
- memset(VIDeltas, 0, sizeof(VIDeltas));
- VIDeltasIndex = 0;
+ LastFPSTime = CounterTime = SDL_GetTicks();
return;
}
-
- // calculate # of milliseconds that have passed since the last video interrupt
CurrentFPSTime = SDL_GetTicks();
- ThisFrameDelta = CurrentFPSTime - LastFPSTime - (int) AdjustedLimit;
-
- // are we too fast?
- if (ThisFrameDelta < 0)
+
+ Dif = CurrentFPSTime - LastFPSTime;
+
+ if (Dif < AdjustedLimit)
{
- // calculate the total time error over the last 64 frames
- IntegratedDelta = VITotalDelta + ThisFrameDelta;
- // if we are still too fast, and then speed limiter is on, then we should wait
- if (IntegratedDelta < 0 && l_MainSpeedLimit)
+ CalculatedTime = (unsigned int) (CounterTime + AdjustedLimit * VI_Counter);
+ time = (int)(CalculatedTime - CurrentFPSTime);
+ if (time > 0 && l_MainSpeedLimit)
{
- TimeToWait = (IntegratedDelta > ThisFrameDelta) ? -IntegratedDelta : -ThisFrameDelta;
- DebugMessage(M64MSG_VERBOSE, " apply_speed_limiter(): Waiting %ims", TimeToWait);
- SDL_Delay(TimeToWait);
- // recalculate # of milliseconds that have passed since the last video interrupt,
- // taking into account the time we just waited
- CurrentFPSTime = SDL_GetTicks();
- ThisFrameDelta = CurrentFPSTime - LastFPSTime - (int) AdjustedLimit;
+ DebugMessage(M64MSG_VERBOSE, " apply_speed_limiter(): Waiting %ims", time);
+ SDL_Delay(time);
}
+ CurrentFPSTime = CurrentFPSTime + time;
}
- // update our data structures
+ if (CurrentFPSTime - CounterTime >= 1000.0 )
+ {
+ CounterTime = SDL_GetTicks();
+ VI_Counter = 0 ;
+ }
+
LastFPSTime = CurrentFPSTime ;
- VITotalDelta += ThisFrameDelta - VIDeltas[VIDeltasIndex];
- VIDeltas[VIDeltasIndex] = ThisFrameDelta;
- VIDeltasIndex = (VIDeltasIndex + 1) & 63;
-
timed_section_end(TIMED_SECTION_IDLE);
}