2020-10-05 12:16:45 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2020-10-06 03:22:07 +08:00
|
|
|
using System.Collections.Generic;
|
2020-10-05 12:16:45 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Testing;
|
2022-05-07 22:17:23 +08:00
|
|
|
using osu.Game.Audio;
|
2020-10-05 12:16:45 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneGameplaySamplePlayback : PlayerTestScene
|
2020-10-05 12:16:45 +08:00
|
|
|
{
|
2024-02-29 20:34:38 +08:00
|
|
|
protected override bool AllowBackwardsSeeks => true;
|
|
|
|
|
2024-03-12 17:35:00 +08:00
|
|
|
private bool seek;
|
|
|
|
|
2020-10-05 12:16:45 +08:00
|
|
|
[Test]
|
|
|
|
public void TestAllSamplesStopDuringSeek()
|
|
|
|
{
|
2022-08-15 19:16:14 +08:00
|
|
|
DrawableSlider? slider = null;
|
|
|
|
PoolableSkinnableSample[] samples = null!;
|
|
|
|
ISamplePlaybackDisabler sampleDisabler = null!;
|
2020-10-05 12:16:45 +08:00
|
|
|
|
2020-11-13 17:35:33 +08:00
|
|
|
AddUntilStep("get variables", () =>
|
2020-10-05 12:16:45 +08:00
|
|
|
{
|
2020-10-27 13:35:12 +08:00
|
|
|
sampleDisabler = Player;
|
2022-04-14 12:11:11 +08:00
|
|
|
slider = Player.ChildrenOfType<DrawableSlider>().MinBy(s => s.HitObject.StartTime);
|
2022-08-15 19:16:14 +08:00
|
|
|
samples = slider.ChildrenOfType<PoolableSkinnableSample>().ToArray();
|
2020-11-13 17:35:33 +08:00
|
|
|
|
|
|
|
return slider != null;
|
2020-10-05 12:16:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for slider sliding then seek", () =>
|
|
|
|
{
|
2022-08-15 19:16:14 +08:00
|
|
|
if (slider?.Tracking.Value != true)
|
2020-10-05 12:16:45 +08:00
|
|
|
return false;
|
|
|
|
|
2021-01-20 13:05:35 +08:00
|
|
|
if (!samples.Any(s => s.Playing))
|
2020-10-05 12:16:45 +08:00
|
|
|
return false;
|
|
|
|
|
2024-03-12 17:35:00 +08:00
|
|
|
seek = true;
|
2020-10-05 12:16:45 +08:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2024-07-18 15:22:39 +08:00
|
|
|
AddUntilStep("sample playback disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
|
2020-10-05 12:16:45 +08:00
|
|
|
|
|
|
|
// because we are in frame stable context, it's quite likely that not all samples are "played" at this point.
|
|
|
|
// the important thing is that at least one started, and that sample has since stopped.
|
2020-10-06 03:22:07 +08:00
|
|
|
AddAssert("all looping samples stopped immediately", () => allStopped(allLoopingSounds));
|
|
|
|
AddUntilStep("all samples stopped eventually", () => allStopped(allSounds));
|
2020-10-05 12:16:45 +08:00
|
|
|
|
2020-10-27 13:35:12 +08:00
|
|
|
AddAssert("sample playback still disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
|
2020-10-05 12:16:45 +08:00
|
|
|
|
2024-03-12 17:35:00 +08:00
|
|
|
AddStep("stop seeking", () => seek = false);
|
|
|
|
|
2020-10-27 13:35:12 +08:00
|
|
|
AddUntilStep("seek finished, sample playback enabled", () => !sampleDisabler.SamplePlaybackDisabled.Value);
|
2020-10-05 12:16:45 +08:00
|
|
|
AddUntilStep("any sample is playing", () => Player.ChildrenOfType<PausableSkinnableSound>().Any(s => s.IsPlaying));
|
|
|
|
}
|
|
|
|
|
2024-03-12 17:35:00 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (seek)
|
|
|
|
{
|
|
|
|
// Frame stable playback is too fast to catch up these days.
|
|
|
|
//
|
|
|
|
// We want to keep seeking while asserting various test conditions, so
|
|
|
|
// continue to seek until we unset the flag.
|
|
|
|
var gameplayClockContainer = Player.ChildrenOfType<GameplayClockContainer>().First();
|
|
|
|
gameplayClockContainer.Seek(gameplayClockContainer.CurrentTime > 30000 ? 0 : 60000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 03:22:07 +08:00
|
|
|
private IEnumerable<PausableSkinnableSound> allSounds => Player.ChildrenOfType<PausableSkinnableSound>();
|
|
|
|
private IEnumerable<PausableSkinnableSound> allLoopingSounds => allSounds.Where(sound => sound.Looping);
|
|
|
|
|
|
|
|
private bool allStopped(IEnumerable<PausableSkinnableSound> sounds) => sounds.All(sound => !sound.IsPlaying);
|
|
|
|
|
2020-10-05 12:16:45 +08:00
|
|
|
protected override bool Autoplay => true;
|
|
|
|
|
|
|
|
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();
|
|
|
|
}
|
|
|
|
}
|