Ensure all remaining objects are added in the last iteration

This commit is contained in:
Dan Balasescu 2024-04-12 00:11:54 +09:00
parent 19cc847be6
commit e9b319f4c6
No known key found for this signature in database
2 changed files with 32 additions and 4 deletions

View File

@ -99,6 +99,33 @@ namespace osu.Game.Tests.NonVisual
assertEquals(attribs[1], beatmap.HitObjects[0]);
}
[Test]
public void TestSkippedLastObjectAddedInLastIteration()
{
var beatmap = new Beatmap<TestHitObject>
{
HitObjects =
{
new TestHitObject { StartTime = 1 },
new TestHitObject
{
StartTime = 2,
Skip = true
},
new TestHitObject
{
StartTime = 3,
Skip = true
},
}
};
List<TimedDifficultyAttributes> 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));

View File

@ -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;