1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 18:13:09 +08:00

Add test coverage of GameplaySampleTriggerSource not considering nested objects

This commit is contained in:
Dean Herbert 2023-02-16 18:13:11 +09:00
parent 979c079f8b
commit b59ec551f6

View File

@ -10,13 +10,16 @@ using osu.Framework.Timing;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Storyboards; using osu.Game.Storyboards;
using osuTK;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
@ -36,13 +39,16 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) protected override IBeatmap CreateBeatmap(RulesetInfo ruleset)
{ {
ControlPointInfo controlPointInfo = new LegacyControlPointInfo();
beatmap = new Beatmap beatmap = new Beatmap
{ {
BeatmapInfo = new BeatmapInfo BeatmapInfo = new BeatmapInfo
{ {
Difficulty = new BeatmapDifficulty { CircleSize = 6, SliderMultiplier = 3 }, Difficulty = new BeatmapDifficulty { CircleSize = 6, SliderMultiplier = 3 },
Ruleset = ruleset Ruleset = ruleset
} },
ControlPointInfo = controlPointInfo
}; };
const double start_offset = 8000; const double start_offset = 8000;
@ -51,7 +57,7 @@ namespace osu.Game.Tests.Visual.Gameplay
// intentionally start objects a bit late so we can test the case of no alive objects. // intentionally start objects a bit late so we can test the case of no alive objects.
double t = start_offset; double t = start_offset;
beatmap.HitObjects.AddRange(new[] beatmap.HitObjects.AddRange(new HitObject[]
{ {
new HitCircle new HitCircle
{ {
@ -71,12 +77,24 @@ namespace osu.Game.Tests.Visual.Gameplay
}, },
new HitCircle new HitCircle
{ {
StartTime = t + spacing, StartTime = t += spacing,
},
new Slider
{
StartTime = t += spacing,
Path = new SliderPath(PathType.Linear, new[] { Vector2.Zero, Vector2.UnitY * 200 }),
Samples = new[] { new HitSampleInfo(HitSampleInfo.HIT_WHISTLE) }, Samples = new[] { new HitSampleInfo(HitSampleInfo.HIT_WHISTLE) },
SampleControlPoint = new SampleControlPoint { SampleBank = "soft" }, SampleControlPoint = new SampleControlPoint { SampleBank = "soft" },
}, },
}); });
// Add a change in volume halfway through final slider.
controlPointInfo.Add(t, new SampleControlPoint
{
SampleBank = "normal",
SampleVolume = 20,
});
return beatmap; return beatmap;
} }
@ -128,10 +146,23 @@ namespace osu.Game.Tests.Visual.Gameplay
waitForAliveObjectIndex(3); waitForAliveObjectIndex(3);
checkValidObjectIndex(3); checkValidObjectIndex(3);
AddStep("Seek into future", () => Beatmap.Value.Track.Seek(beatmap.HitObjects.Last().GetEndTime() + 10000)); seekBeforeIndex(4);
waitForAliveObjectIndex(4);
// Even before the object, we should prefer the first nested object's sample.
// This is because the (parent) object will only play its sample at the final EndTime.
AddAssert("check valid object is slider's first nested", () => sampleTriggerSource.GetMostValidObject(), () => Is.EqualTo(beatmap.HitObjects[4].NestedHitObjects.First()));
AddStep("seek to just after slider", () => Beatmap.Value.Track.Seek(beatmap.HitObjects[4].GetEndTime() + 100));
AddUntilStep("wait until valid object is slider's last nested", () => sampleTriggerSource.GetMostValidObject(), () => Is.EqualTo(beatmap.HitObjects[4].NestedHitObjects.Last()));
// After we get far enough away, the samples of the object itself should be used, not any nested object.
AddStep("seek to further after slider", () => Beatmap.Value.Track.Seek(beatmap.HitObjects[4].GetEndTime() + 1000));
AddUntilStep("wait until valid object is slider itself", () => sampleTriggerSource.GetMostValidObject(), () => Is.EqualTo(beatmap.HitObjects[4]));
AddStep("Seek into future", () => Beatmap.Value.Track.Seek(beatmap.HitObjects.Last().GetEndTime() + 10000));
waitForAliveObjectIndex(null); waitForAliveObjectIndex(null);
checkValidObjectIndex(3); checkValidObjectIndex(4);
} }
private void seekBeforeIndex(int index) => private void seekBeforeIndex(int index) =>