From a9cb214aa908a2fbbce3742d34c2f69b9f4093f4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 21 Jun 2018 16:21:08 +0900 Subject: [PATCH] Replace usage of GetEnumerator --- .../Difficulty/CatchDifficultyCalculator.cs | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs index 4dd9cd10db..20bdaf875d 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchDifficultyCalculator.cs @@ -9,7 +9,6 @@ using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.UI; -using osu.Game.Rulesets.Objects; namespace osu.Game.Rulesets.Catch.Difficulty { @@ -53,17 +52,7 @@ namespace osu.Game.Rulesets.Catch.Difficulty difficultyHitObjects.Add(new CatchDifficultyHitObject((CatchHitObject)hitObject, halfCatchWidth)); } if (hitObject is JuiceStream) - { - IEnumerator nestedHitObjectsEnumerator = hitObject.NestedHitObjects.GetEnumerator(); - while (nestedHitObjectsEnumerator.MoveNext()) - { - CatchHitObject objectInJuiceStream = (CatchHitObject)nestedHitObjectsEnumerator.Current; - if (!(objectInJuiceStream is TinyDroplet)) - difficultyHitObjects.Add(new CatchDifficultyHitObject(objectInJuiceStream, halfCatchWidth)); - } - // Dispose the enumerator after counting all fruits. - nestedHitObjectsEnumerator.Dispose(); - } + difficultyHitObjects.AddRange(hitObject.NestedHitObjects.OfType().Where(o => !(o is TinyDroplet)).Select(o => new CatchDifficultyHitObject(o, halfCatchWidth))); } difficultyHitObjects.Sort((a, b) => a.BaseHitObject.StartTime.CompareTo(b.BaseHitObject.StartTime)); @@ -86,23 +75,20 @@ namespace osu.Game.Rulesets.Catch.Difficulty private bool calculateStrainValues(List objects, double timeRate) { + CatchDifficultyHitObject lastObject = null; + + if (!objects.Any()) return false; + // Traverse hitObjects in pairs to calculate the strain value of NextHitObject from the strain value of CurrentHitObject and environment. - using (var hitObjectsEnumerator = objects.GetEnumerator()) + foreach (var currentObject in objects) { - if (!hitObjectsEnumerator.MoveNext()) return false; + if (lastObject != null) + currentObject.CalculateStrains(lastObject, timeRate); - CatchDifficultyHitObject currentHitObject = hitObjectsEnumerator.Current; - - // First hitObject starts at strain 1. 1 is the default for strain values, so we don't need to set it here. See DifficultyHitObject. - while (hitObjectsEnumerator.MoveNext()) - { - CatchDifficultyHitObject nextHitObject = hitObjectsEnumerator.Current; - nextHitObject?.CalculateStrains(currentHitObject, timeRate); - currentHitObject = nextHitObject; - } - - return true; + lastObject = currentObject; } + + return true; } private double calculateDifficulty(List objects, double timeRate)