From e9b319f4c6e43d2488cf4ebee2c9d56f7f828b70 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 12 Apr 2024 00:11:54 +0900 Subject: [PATCH] Ensure all remaining objects are added in the last iteration --- .../TestSceneTimedDifficultyCalculation.cs | 27 +++++++++++++++++++ .../Difficulty/DifficultyCalculator.cs | 9 ++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/NonVisual/TestSceneTimedDifficultyCalculation.cs b/osu.Game.Tests/NonVisual/TestSceneTimedDifficultyCalculation.cs index 4c32d3bf1c..1a75f735ef 100644 --- a/osu.Game.Tests/NonVisual/TestSceneTimedDifficultyCalculation.cs +++ b/osu.Game.Tests/NonVisual/TestSceneTimedDifficultyCalculation.cs @@ -99,6 +99,33 @@ namespace osu.Game.Tests.NonVisual assertEquals(attribs[1], beatmap.HitObjects[0]); } + [Test] + public void TestSkippedLastObjectAddedInLastIteration() + { + var beatmap = new Beatmap + { + HitObjects = + { + new TestHitObject { StartTime = 1 }, + new TestHitObject + { + StartTime = 2, + Skip = true + }, + new TestHitObject + { + StartTime = 3, + Skip = true + }, + } + }; + + List attribs = new TestDifficultyCalculator(new TestWorkingBeatmap(beatmap)).CalculateTimed(); + + Assert.That(attribs.Count, Is.EqualTo(1)); + assertEquals(attribs[0], beatmap.HitObjects[0], beatmap.HitObjects[1], beatmap.HitObjects[2]); + } + private void assertEquals(TimedDifficultyAttributes attribs, params HitObject[] expected) { Assert.That(((TestDifficultyAttributes)attribs.Attributes).Objects, Is.EquivalentTo(expected)); diff --git a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs index 5d608deae2..1599dff8d9 100644 --- a/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/DifficultyCalculator.cs @@ -107,15 +107,16 @@ namespace osu.Game.Rulesets.Difficulty var skills = CreateSkills(Beatmap, playableMods, clockRate); var progressiveBeatmap = new ProgressiveCalculationBeatmap(Beatmap); + var difficultyObjects = getDifficultyHitObjects().ToArray(); - foreach (var hitObject in getDifficultyHitObjects()) + foreach (var obj in difficultyObjects) { // Implementations expect the progressive beatmap to only contain top-level objects from the original beatmap. // At the same time, we also need to consider the possibility DHOs may not be generated for any given object, // so we'll add all remaining objects up to the current point in time to the progressive beatmap. for (int i = progressiveBeatmap.HitObjects.Count; i < Beatmap.HitObjects.Count; i++) { - if (Beatmap.HitObjects[i].StartTime > hitObject.BaseObject.StartTime) + if (obj != difficultyObjects[^1] && Beatmap.HitObjects[i].StartTime > obj.BaseObject.StartTime) break; progressiveBeatmap.HitObjects.Add(Beatmap.HitObjects[i]); @@ -124,10 +125,10 @@ namespace osu.Game.Rulesets.Difficulty foreach (var skill in skills) { cancellationToken.ThrowIfCancellationRequested(); - skill.Process(hitObject); + skill.Process(obj); } - attribs.Add(new TimedDifficultyAttributes(hitObject.EndTime * clockRate, CreateDifficultyAttributes(progressiveBeatmap, playableMods, skills, clockRate))); + attribs.Add(new TimedDifficultyAttributes(obj.EndTime * clockRate, CreateDifficultyAttributes(progressiveBeatmap, playableMods, skills, clockRate))); } return attribs;