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;
|
2020-09-29 13:09:51 +08:00
|
|
|
using System.Linq;
|
2020-01-02 14:23:41 +08:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2020-09-29 13:09:51 +08:00
|
|
|
using osu.Framework.Graphics.Audio;
|
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;
|
2020-01-06 14:33:59 +08:00
|
|
|
using osu.Framework.Testing;
|
2021-02-24 05:25:59 +08:00
|
|
|
using osu.Framework.Utils;
|
2020-01-02 14:23:41 +08:00
|
|
|
using osu.Game.Audio;
|
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.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-12-21 14:14:32 +08:00
|
|
|
public class TestSceneStoryboardSamples : OsuTestScene, IStorageResourceProvider
|
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);
|
2020-08-17 14:38:16 +08:00
|
|
|
working.LoadTrack();
|
2020-08-06 17:31:08 +08:00
|
|
|
|
2020-08-17 21:36:03 +08:00
|
|
|
Add(gameplayContainer = new GameplayClockContainer(working, 0));
|
2020-06-15 10:18:12 +08:00
|
|
|
|
|
|
|
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-20 01:40:36 +08:00
|
|
|
[TestCase(typeof(OsuModDoubleTime), 1.5)]
|
|
|
|
[TestCase(typeof(OsuModHalfTime), 0.75)]
|
|
|
|
[TestCase(typeof(ModWindUp), 1.5)]
|
|
|
|
[TestCase(typeof(ModWindDown), 0.75)]
|
|
|
|
[TestCase(typeof(OsuModDoubleTime), 2)]
|
|
|
|
[TestCase(typeof(OsuModHalfTime), 0.5)]
|
|
|
|
[TestCase(typeof(ModWindUp), 2)]
|
|
|
|
[TestCase(typeof(ModWindDown), 0.5)]
|
|
|
|
public void TestSamplePlaybackWithRateMods(Type expectedMod, double expectedRate)
|
2020-06-19 04:46:32 +08:00
|
|
|
{
|
|
|
|
GameplayClockContainer gameplayContainer = null;
|
2021-02-24 05:25:59 +08:00
|
|
|
StoryboardSampleInfo sampleInfo = null;
|
2020-06-19 04:46:32 +08:00
|
|
|
TestDrawableStoryboardSample sample = null;
|
|
|
|
|
2020-06-20 01:40:36 +08:00
|
|
|
Mod testedMod = Activator.CreateInstance(expectedMod) as Mod;
|
2020-06-19 04:46:32 +08:00
|
|
|
|
2020-06-20 01:40:36 +08:00
|
|
|
switch (testedMod)
|
2020-06-19 04:46:32 +08:00
|
|
|
{
|
2020-06-20 01:40:36 +08:00
|
|
|
case ModRateAdjust m:
|
|
|
|
m.SpeedChange.Value = expectedRate;
|
|
|
|
break;
|
2020-06-19 04:46:32 +08:00
|
|
|
|
2020-06-20 01:40:36 +08:00
|
|
|
case ModTimeRamp m:
|
2021-02-24 03:43:04 +08:00
|
|
|
m.FinalRate.Value = m.InitialRate.Value = expectedRate;
|
2020-06-20 01:40:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-06-19 04:46:32 +08:00
|
|
|
|
2020-06-20 01:40:36 +08:00
|
|
|
AddStep("setup storyboard sample", () =>
|
2020-06-19 04:46:32 +08:00
|
|
|
{
|
2020-12-21 14:14:32 +08:00
|
|
|
Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, this);
|
2020-06-20 01:40:36 +08:00
|
|
|
SelectedMods.Value = new[] { testedMod };
|
|
|
|
|
2020-09-29 13:09:51 +08:00
|
|
|
var beatmapSkinSourceContainer = new BeatmapSkinProvidingContainer(Beatmap.Value.Skin);
|
2020-06-20 01:40:36 +08:00
|
|
|
|
2020-09-29 13:09:51 +08:00
|
|
|
Add(gameplayContainer = new GameplayClockContainer(Beatmap.Value, 0)
|
|
|
|
{
|
|
|
|
Child = beatmapSkinSourceContainer
|
|
|
|
});
|
|
|
|
|
2021-02-24 05:25:59 +08:00
|
|
|
beatmapSkinSourceContainer.Add(sample = new TestDrawableStoryboardSample(sampleInfo = new StoryboardSampleInfo("test-sample", 1, 1))
|
2020-06-19 04:46:32 +08:00
|
|
|
{
|
|
|
|
Clock = gameplayContainer.GameplayClock
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("start", () => gameplayContainer.Start());
|
|
|
|
|
2021-02-24 05:25:59 +08:00
|
|
|
AddAssert("sample playback rate matches mod rates", () =>
|
|
|
|
testedMod != null && Precision.AlmostEquals(
|
|
|
|
sample.ChildrenOfType<DrawableSample>().First().AggregateFrequency.Value,
|
|
|
|
((IApplicableToRate)testedMod).ApplyToRate(sampleInfo.StartTime)));
|
2020-06-19 04:46:32 +08:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
: base(DefaultLegacySkin.Info, new TestResourceStore(resourceName), resources, "skin.ini")
|
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
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2020-12-21 14:14:32 +08:00
|
|
|
protected override ISkin GetSkin() => new TestSkin("test-sample", resources);
|
2020-06-19 04:46:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private 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
|
|
|
|
|
2020-12-21 14:14:32 +08:00
|
|
|
public AudioManager AudioManager => Audio;
|
|
|
|
public IResourceStore<byte[]> Files => null;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|