Skip to content

Commit

Permalink
core: fix issue that would make the game run too fast if the speed li…
Browse files Browse the repository at this point in the history
…miter

was set too low.
  • Loading branch information
fzurita committed Apr 9, 2016
1 parent 63b05f4 commit 3c9304e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions jni/mupen64plus-core/src/main/main.c
Expand Up @@ -738,11 +738,13 @@ static void apply_speed_limiter(void)
static int resetOnce = 0;
static int lastSpeedFactor = 100;
static unsigned int StartFPSTime = 0;
static const double defaultSpeedFactor = 100.0;
unsigned int CurrentFPSTime = SDL_GetTicks();

// calculate frame duration based upon ROM setting (50/60hz) and mupen64plus speed adjustment
const double VILimitMilliseconds = 1000.0 / (double)ROM_PARAMS.vilimit;
const double AdjustedLimit = VILimitMilliseconds * 100.0 / l_SpeedFactor;
const double SpeedFactorMultiple = defaultSpeedFactor/l_SpeedFactor;
const double AdjustedLimit = VILimitMilliseconds * SpeedFactorMultiple;

//if this is the first time or we are resuming from pause
if(StartFPSTime == 0 || !resetOnce || lastSpeedFactor != l_SpeedFactor)
Expand Down Expand Up @@ -771,7 +773,7 @@ static void apply_speed_limiter(void)
//Reset if the sleep needed is an unreasonable value
static const double minSleepNeeded = -50;
static const double maxSleepNeeded = 50;
if(sleepTime < minSleepNeeded || sleepTime > maxSleepNeeded)
if(sleepTime < minSleepNeeded || sleepTime > (maxSleepNeeded*SpeedFactorMultiple))
{
resetOnce = 0;
}
Expand Down

0 comments on commit 3c9304e

Please sign in to comment.