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.
|
|
|
|
|
2020-06-15 10:18:12 +08:00
|
|
|
using System;
|
2020-01-02 14:23:41 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.IO.Stores;
|
2020-01-06 14:33:59 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-06-19 04:46:32 +08:00
|
|
|
using osu.Framework.Timing;
|
2020-01-02 14:23:41 +08:00
|
|
|
using osu.Game.Audio;
|
2020-06-19 04:46:32 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-06-15 10:18:12 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2020-06-19 04:46:32 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
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-01-02 14:23:41 +08:00
|
|
|
public class TestSceneStoryboardSamples : OsuTestScene
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestRetrieveTopLevelSample()
|
|
|
|
{
|
|
|
|
ISkin skin = null;
|
|
|
|
SampleChannel channel = null;
|
|
|
|
|
|
|
|
AddStep("create skin", () => skin = new TestSkin("test-sample", Audio));
|
|
|
|
AddStep("retrieve sample", () => channel = skin.GetSample(new SampleInfo("test-sample")));
|
|
|
|
|
|
|
|
AddAssert("sample is non-null", () => channel != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRetrieveSampleInSubFolder()
|
|
|
|
{
|
|
|
|
ISkin skin = null;
|
|
|
|
SampleChannel channel = null;
|
|
|
|
|
|
|
|
AddStep("create skin", () => skin = new TestSkin("folder/test-sample", Audio));
|
|
|
|
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", () =>
|
|
|
|
{
|
|
|
|
Add(gameplayContainer = new GameplayClockContainer(CreateWorkingBeatmap(new OsuRuleset().RulesetInfo), Array.Empty<Mod>(), 0));
|
|
|
|
|
|
|
|
gameplayContainer.Add(sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
|
|
|
|
{
|
|
|
|
Clock = gameplayContainer.GameplayClock
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("start time", () => gameplayContainer.Start());
|
|
|
|
|
|
|
|
AddUntilStep("sample playback succeeded", () => sample.LifetimeEnd < double.MaxValue);
|
|
|
|
}
|
|
|
|
|
2020-06-19 04:46:32 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSamplePlaybackWithRateMods()
|
|
|
|
{
|
|
|
|
GameplayClockContainer gameplayContainer = null;
|
|
|
|
TestDrawableStoryboardSample sample = null;
|
|
|
|
|
|
|
|
OsuModDoubleTime doubleTimeMod = null;
|
|
|
|
|
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
|
|
|
var beatmap = Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
|
|
|
|
|
|
|
Add(gameplayContainer = new GameplayClockContainer(beatmap, new[] { doubleTimeMod = new OsuModDoubleTime() }, 0));
|
|
|
|
|
|
|
|
SelectedMods.Value = new[] { doubleTimeMod };
|
|
|
|
Beatmap.Value = new TestCustomSkinWorkingBeatmap(beatmap.Beatmap, gameplayContainer.GameplayClock, Audio);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("create storyboard sample", () =>
|
|
|
|
{
|
|
|
|
gameplayContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1))
|
|
|
|
{
|
|
|
|
Clock = gameplayContainer.GameplayClock
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("start", () => gameplayContainer.Start());
|
|
|
|
|
|
|
|
AddAssert("sample playback rate matches mod rates", () => sample.TestChannel.AggregateFrequency.Value == doubleTimeMod.SpeedChange.Value);
|
|
|
|
}
|
|
|
|
|
2020-01-02 14:23:41 +08:00
|
|
|
private class TestSkin : LegacySkin
|
|
|
|
{
|
|
|
|
public TestSkin(string resourceName, AudioManager audioManager)
|
|
|
|
: base(DefaultLegacySkin.Info, new TestResourceStore(resourceName), audioManager, "skin.ini")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-04-11 09:24:34 +08:00
|
|
|
public Task<byte[]> GetAsync(string name) => name == resourceName ? TestResources.GetStore().GetAsync("Resources/Samples/test-sample.mp3") : 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
|
|
|
|
{
|
|
|
|
private readonly AudioManager audio;
|
|
|
|
|
|
|
|
public TestCustomSkinWorkingBeatmap(IBeatmap beatmap, IFrameBasedClock referenceClock, AudioManager audio)
|
|
|
|
: base(beatmap, null, referenceClock, audio)
|
|
|
|
{
|
|
|
|
this.audio = audio;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override ISkin GetSkin() => new TestSkin("test-sample", audio);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestDrawableStoryboardSample : DrawableStoryboardSample
|
|
|
|
{
|
|
|
|
public TestDrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
|
|
|
|
: base(sampleInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public SampleChannel TestChannel => Channel;
|
|
|
|
}
|
2020-01-02 14:23:41 +08:00
|
|
|
}
|
|
|
|
}
|