diff --git a/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs b/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs index c28283d0bb..428d605a99 100644 --- a/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs +++ b/osu.Game/Rulesets/Mods/ModAdaptiveSpeed.cs @@ -87,21 +87,9 @@ namespace osu.Game.Rulesets.Mods /// When time is elapsing forward, items are dequeued from the start and enqueued onto the end of the list. /// When time is being rewound, items are dequeued from the end and enqueued onto the start of the list. /// - private readonly List recentRates = Enumerable.Repeat(1d, recent_rate_count).ToList(); - - /// - /// For each given in the map, this dictionary maps the object onto the latest end time of any other object - /// that precedes the end time of the given object. - /// This can be loosely interpreted as the end time of the preceding hit object in rulesets that do not have overlapping hit objects. - /// - private readonly Dictionary precedingEndTimes = new Dictionary(); - - /// - /// For each given in the map, this dictionary maps the object onto the approximated track rate with which the user hit it. - /// /// /// - /// The approximation is calculated as follows: + /// The track rate approximation is calculated as follows: /// /// /// Consider a hitobject which ends at 1000ms, and assume that its preceding hitobject ends at 500ms. @@ -116,7 +104,21 @@ namespace osu.Game.Rulesets.Mods /// Therefore, the approximated target rate for this object would be equal to 500 / 480 * . /// /// - private readonly Dictionary approximatedRates = new Dictionary(); + private readonly List recentRates = Enumerable.Repeat(1d, recent_rate_count).ToList(); + + /// + /// For each given in the map, this dictionary maps the object onto the latest end time of any other object + /// that precedes the end time of the given object. + /// This can be loosely interpreted as the end time of the preceding hit object in rulesets that do not have overlapping hit objects. + /// + private readonly Dictionary precedingEndTimes = new Dictionary(); + + /// + /// For each given in the map, this dictionary maps the object onto the track rate dequeued from + /// (i.e. the oldest value in the queue) when the object is hit. If the hit is then reverted, + /// the mapped value can be re-introduced to to properly rewind the queue. + /// + private readonly Dictionary ratesForRewinding = new Dictionary(); public ModAdaptiveSpeed() { @@ -154,26 +156,27 @@ namespace osu.Game.Rulesets.Mods { drawable.OnNewResult += (o, result) => { - if (approximatedRates.ContainsKey(result.HitObject)) return; + if (ratesForRewinding.ContainsKey(result.HitObject)) return; if (!shouldProcessResult(result)) return; double prevEndTime = precedingEndTimes[result.HitObject]; - recentRates.Add(Math.Clamp((result.HitObject.GetEndTime() - prevEndTime) / (result.TimeAbsolute - prevEndTime) * SpeedChange.Value, min_allowable_rate, max_allowable_rate)); - - approximatedRates.Add(result.HitObject, recentRates[0]); + ratesForRewinding.Add(result.HitObject, recentRates[0]); recentRates.RemoveAt(0); + recentRates.Add(Math.Clamp((result.HitObject.GetEndTime() - prevEndTime) / (result.TimeAbsolute - prevEndTime) * SpeedChange.Value, min_allowable_rate, max_allowable_rate)); + targetRate = recentRates.Average(); }; drawable.OnRevertResult += (o, result) => { - if (!approximatedRates.ContainsKey(result.HitObject)) return; + if (!ratesForRewinding.ContainsKey(result.HitObject)) return; if (!shouldProcessResult(result)) return; - recentRates.Insert(0, approximatedRates[result.HitObject]); + recentRates.Insert(0, ratesForRewinding[result.HitObject]); + ratesForRewinding.Remove(result.HitObject); + recentRates.RemoveAt(recentRates.Count - 1); - approximatedRates.Remove(result.HitObject); targetRate = recentRates.Average(); };