2020-01-02 14:23:41 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-01-02 14:23:41 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
2021-12-23 17:33:17 +08:00
|
|
|
using System.Threading;
|
2020-01-02 14:23:41 +08:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NUnit.Framework;
|
2021-12-26 21:23:52 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-01-02 14:23:41 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2022-08-02 18:50:57 +08:00
|
|
|
using osu.Framework.Graphics.Rendering;
|
2020-12-21 14:14:32 +08:00
|
|
|
using osu.Framework.Graphics.Textures;
|
2020-01-02 14:23:41 +08:00
|
|
|
using osu.Framework.IO.Stores;
|
2022-08-02 18:50:57 +08:00
|
|
|
using osu.Framework.Platform;
|
2020-01-06 14:33:59 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-01-02 14:23:41 +08:00
|
|
|
using osu.Game.Audio;
|
2021-12-26 21:23:52 +08:00
|
|
|
using osu.Game.Configuration;
|
2021-12-14 13:19:43 +08:00
|
|
|
using osu.Game.Database;
|
2020-12-21 14:14:32 +08:00
|
|
|
using osu.Game.IO;
|
2020-06-20 01:40:36 +08:00
|
|
|
using osu.Game.Rulesets;
|
2020-06-15 10:18:12 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-04-20 17:26:30 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
2020-06-15 10:18:12 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2020-01-02 14:23:41 +08:00
|
|
|
using osu.Game.Skinning;
|
2020-06-15 10:18:12 +08:00
|
|
|
using osu.Game.Storyboards;
|
|
|
|
using osu.Game.Storyboards.Drawables;
|
2020-01-02 14:23:41 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Gameplay
|
|
|
|
{
|
2020-01-06 14:33:59 +08:00
|
|
|
[HeadlessTest]
|
2020-12-21 14:14:32 +08:00
|
|
|
public partial class TestSceneStoryboardSamples : OsuTestScene, IStorageResourceProvider
|
2020-01-02 14:23:41 +08:00
|
|
|
{
|
2021-12-26 21:23:52 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
|
2022-08-02 18:50:57 +08:00
|
|
|
[Resolved]
|
|
|
|
private GameHost host { get; set; }
|
|
|
|
|
2020-01-02 14:23:41 +08:00
|
|
|
[Test]
|
|
|
|
public void TestRetrieveTopLevelSample()
|
|
|
|
{
|
|
|
|
ISkin skin = null;
|
2021-02-18 17:32:28 +08:00
|
|
|
ISample channel = null;
|
2020-01-02 14:23:41 +08:00
|
|
|
|
2020-12-21 14:14:32 +08:00
|
|
|
AddStep("create skin", () => skin = new TestSkin("test-sample", this));
|
2020-01-02 14:23:41 +08:00
|
|
|
AddStep("retrieve sample", () => channel = skin.GetSample(new SampleInfo("test-sample")));
|
|
|
|
|
|
|
|
AddAssert("sample is non-null", () => channel != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRetrieveSampleInSubFolder()
|
|
|
|
{
|
|
|
|
ISkin skin = null;
|
2021-02-18 17:32:28 +08:00
|
|
|
ISample channel = null;
|
2020-01-02 14:23:41 +08:00
|
|
|
|
2020-12-21 14:14:32 +08:00
|
|
|
AddStep("create skin", () => skin = new TestSkin("folder/test-sample", this));
|
2020-01-02 14:23:41 +08:00
|
|
|
AddStep("retrieve sample", () => channel = skin.GetSample(new SampleInfo("folder/test-sample")));
|
|
|
|
|
|
|
|
AddAssert("sample is non-null", () => channel != null);
|
|
|
|
}
|
|
|
|
|
2020-06-15 10:18:12 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSamplePlaybackAtZero()
|
|
|
|
{
|
|
|
|
GameplayClockContainer gameplayContainer = null;
|
|
|
|
DrawableStoryboardSample sample = null;
|
|
|
|
|
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
2020-08-06 17:31:08 +08:00
|
|
|
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
|
|
|
|
2021-04-20 17:26:30 +08:00
|
|
|
Add(gameplayContainer = new MasterGameplayClockContainer(working, 0)
|
2020-06-15 10:18:12 +08:00
|
|
|
{
|
2021-04-20 17:26:30 +08:00
|
|
|
Child = new FrameStabilityContainer
|
|
|
|
{
|
|
|
|
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
|
|
|
|
}
|
2020-06-15 10:18:12 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-08-24 10:50:19 +08:00
|
|
|
AddStep("reset clock", () => gameplayContainer.Reset(startClock: true));
|
2020-06-15 10:18:12 +08:00
|
|
|
|
2021-04-20 15:51:00 +08:00
|
|
|
AddUntilStep("sample played", () => sample.RequestedPlaying);
|
|
|
|
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
|
|
|
|
}
|
|
|
|
|
2022-08-18 17:28:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Sample at 0ms, start time at 1000ms (so the sample should not be played).
|
|
|
|
/// </summary>
|
2021-04-20 15:51:00 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSampleHasLifetimeEndWithInitialClockTime()
|
|
|
|
{
|
2022-04-13 13:09:49 +08:00
|
|
|
MasterGameplayClockContainer gameplayContainer = null;
|
2021-04-20 15:51:00 +08:00
|
|
|
DrawableStoryboardSample sample = null;
|
|
|
|
|
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
|
|
|
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
|
|
|
|
2022-04-13 13:09:49 +08:00
|
|
|
const double start_time = 1000;
|
|
|
|
|
|
|
|
Add(gameplayContainer = new MasterGameplayClockContainer(working, start_time)
|
2021-04-20 15:51:00 +08:00
|
|
|
{
|
2021-04-20 17:26:30 +08:00
|
|
|
Child = new FrameStabilityContainer
|
|
|
|
{
|
|
|
|
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
|
|
|
|
}
|
2021-04-20 15:51:00 +08:00
|
|
|
});
|
2022-08-22 13:11:06 +08:00
|
|
|
|
|
|
|
gameplayContainer.Reset(start_time);
|
2021-04-20 15:51:00 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("start time", () => gameplayContainer.Start());
|
|
|
|
|
|
|
|
AddUntilStep("sample not played", () => !sample.RequestedPlaying);
|
|
|
|
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
|
2020-06-15 10:18:12 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 21:23:52 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSamplePlaybackWithBeatmapHitsoundsOff()
|
|
|
|
{
|
|
|
|
GameplayClockContainer gameplayContainer = null;
|
|
|
|
TestDrawableStoryboardSample sample = null;
|
|
|
|
|
|
|
|
AddStep("disable beatmap hitsounds", () => config.SetValue(OsuSetting.BeatmapHitsounds, false));
|
|
|
|
|
|
|
|
AddStep("setup storyboard sample", () =>
|
|
|
|
{
|
|
|
|
Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, this);
|
|
|
|
|
|
|
|
var beatmapSkinSourceContainer = new BeatmapSkinProvidingContainer(Beatmap.Value.Skin);
|
|
|
|
|
|
|
|
Add(gameplayContainer = new MasterGameplayClockContainer(Beatmap.Value, 0)
|
|
|
|
{
|
|
|
|
Child = beatmapSkinSourceContainer
|
|
|
|
});
|
|
|
|
|
|
|
|
beatmapSkinSourceContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1))
|
|
|
|
{
|
2022-08-15 16:06:24 +08:00
|
|
|
Clock = gameplayContainer
|
2021-12-26 21:23:52 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-08-24 10:50:19 +08:00
|
|
|
AddStep("reset clock", () => gameplayContainer.Reset(startClock: true));
|
2021-12-26 21:23:52 +08:00
|
|
|
|
|
|
|
AddUntilStep("sample played", () => sample.IsPlayed);
|
|
|
|
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
|
|
|
|
|
|
|
|
AddStep("restore default", () => config.GetBindable<bool>(OsuSetting.BeatmapHitsounds).SetDefault());
|
|
|
|
}
|
|
|
|
|
2020-01-02 14:23:41 +08:00
|
|
|
private class TestSkin : LegacySkin
|
|
|
|
{
|
2020-12-21 14:14:32 +08:00
|
|
|
public TestSkin(string resourceName, IStorageResourceProvider resources)
|
2022-03-23 14:05:01 +08:00
|
|
|
: base(DefaultLegacySkin.CreateInfo(), resources, new TestResourceStore(resourceName))
|
2020-01-02 14:23:41 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestResourceStore : IResourceStore<byte[]>
|
|
|
|
{
|
|
|
|
private readonly string resourceName;
|
|
|
|
|
|
|
|
public TestResourceStore(string resourceName)
|
|
|
|
{
|
|
|
|
this.resourceName = resourceName;
|
|
|
|
}
|
|
|
|
|
2020-04-11 09:24:34 +08:00
|
|
|
public byte[] Get(string name) => name == resourceName ? TestResources.GetStore().Get("Resources/Samples/test-sample.mp3") : null;
|
2020-01-02 14:23:41 +08:00
|
|
|
|
2021-12-23 17:33:17 +08:00
|
|
|
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
|
|
|
=> name == resourceName ? TestResources.GetStore().GetAsync("Resources/Samples/test-sample.mp3", cancellationToken) : null;
|
2020-01-02 14:23:41 +08:00
|
|
|
|
2020-04-11 09:24:34 +08:00
|
|
|
public Stream GetStream(string name) => name == resourceName ? TestResources.GetStore().GetStream("Resources/Samples/test-sample.mp3") : null;
|
2020-01-02 14:23:41 +08:00
|
|
|
|
|
|
|
public IEnumerable<string> GetAvailableResources() => new[] { resourceName };
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2020-06-19 04:46:32 +08:00
|
|
|
|
|
|
|
private class TestCustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
|
|
|
|
{
|
2020-12-21 14:14:32 +08:00
|
|
|
private readonly IStorageResourceProvider resources;
|
2020-06-19 04:46:32 +08:00
|
|
|
|
2020-12-21 14:14:32 +08:00
|
|
|
public TestCustomSkinWorkingBeatmap(RulesetInfo ruleset, IStorageResourceProvider resources)
|
|
|
|
: base(ruleset, null, resources.AudioManager)
|
2020-06-19 04:46:32 +08:00
|
|
|
{
|
2020-12-21 14:14:32 +08:00
|
|
|
this.resources = resources;
|
2020-06-19 04:46:32 +08:00
|
|
|
}
|
|
|
|
|
2021-08-16 00:38:01 +08:00
|
|
|
protected internal override ISkin GetSkin() => new TestSkin("test-sample", resources);
|
2020-06-19 04:46:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private partial class TestDrawableStoryboardSample : DrawableStoryboardSample
|
|
|
|
{
|
|
|
|
public TestDrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
|
|
|
|
: base(sampleInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 14:14:32 +08:00
|
|
|
|
2020-12-22 11:01:09 +08:00
|
|
|
#region IResourceStorageProvider
|
|
|
|
|
2022-08-02 18:50:57 +08:00
|
|
|
public IRenderer Renderer => host.Renderer;
|
2020-12-21 14:14:32 +08:00
|
|
|
public AudioManager AudioManager => Audio;
|
|
|
|
public IResourceStore<byte[]> Files => null;
|
2021-05-31 17:37:32 +08:00
|
|
|
public new IResourceStore<byte[]> Resources => base.Resources;
|
2022-01-24 18:59:58 +08:00
|
|
|
public RealmAccess RealmAccess => null;
|
2020-12-21 14:14:32 +08:00
|
|
|
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
|
2020-12-22 11:01:09 +08:00
|
|
|
|
|
|
|
#endregion
|
2020-01-02 14:23:41 +08:00
|
|
|
}
|
|
|
|
}
|