diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index 0deba009..03ae579d 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -412,7 +412,7 @@ namespace QSB.TimeSync return; } - var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds); + var mappedTimescale = diff.Map(-PauseOrFastForwardThreshold, PauseOrFastForwardThreshold, 1 + TimescaleBounds, 1 - TimescaleBounds, true); if (mappedTimescale > 100f) { DebugLog.ToConsole($"Warning - CheckTimeDifference() returned over 100 - should have switched into fast-forward!", MessageType.Warning); diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index 9ef15f17..d56e0804 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -100,8 +100,14 @@ namespace QSB.Utility } } - public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo) - => ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom; + public static float Map(this float value, float inputFrom, float inputTo, float outputFrom, float outputTo, bool clamp) + { + var mappedValue = ((value - inputFrom) / (inputTo - inputFrom) * (outputTo - outputFrom)) + outputFrom; + + return clamp + ? Mathf.Clamp(mappedValue, outputTo, outputFrom) + : mappedValue; + } public static void ForEach(this IEnumerable enumerable, Action action) {