1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 16:12:55 +08:00
osu-lazer/osu.Game.Tests/Gameplay/TestSceneStoryboardSamples.cs

228 lines
8.2 KiB
C#
Raw Normal View History

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.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;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Textures;
2020-01-02 14:23:41 +08:00
using osu.Framework.IO.Stores;
using osu.Framework.Testing;
using osu.Framework.Utils;
2020-01-02 14:23:41 +08:00
using osu.Game.Audio;
using osu.Game.IO;
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;
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
{
[HeadlessTest]
public class TestSceneStoryboardSamples : OsuTestScene, IStorageResourceProvider
2020-01-02 14:23:41 +08:00
{
[Test]
public void TestRetrieveTopLevelSample()
{
ISkin skin = null;
ISample channel = null;
2020-01-02 14:23:41 +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;
ISample channel = null;
2020-01-02 14:23:41 +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
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
IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
2020-06-15 10:18:12 +08:00
});
});
2021-04-20 17:26:30 +08:00
AddStep("reset clock", () => gameplayContainer.Start());
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);
}
[Test]
public void TestSampleHasLifetimeEndWithInitialClockTime()
{
GameplayClockContainer gameplayContainer = null;
DrawableStoryboardSample sample = null;
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack();
2021-04-20 17:26:30 +08:00
Add(gameplayContainer = new MasterGameplayClockContainer(working, 1000, true)
2021-04-20 15:51:00 +08:00
{
2021-04-20 17:26:30 +08:00
IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
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
}
[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;
StoryboardSampleInfo sampleInfo = null;
2020-06-19 04:46:32 +08:00
TestDrawableStoryboardSample sample = null;
Mod testedMod = Activator.CreateInstance(expectedMod) as Mod;
2020-06-19 04:46:32 +08:00
switch (testedMod)
2020-06-19 04:46:32 +08:00
{
case ModRateAdjust m:
m.SpeedChange.Value = expectedRate;
break;
2020-06-19 04:46:32 +08:00
case ModTimeRamp m:
2021-02-24 03:43:04 +08:00
m.FinalRate.Value = m.InitialRate.Value = expectedRate;
break;
}
2020-06-19 04:46:32 +08:00
AddStep("setup storyboard sample", () =>
2020-06-19 04:46:32 +08:00
{
Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, this);
SelectedMods.Value = new[] { testedMod };
var beatmapSkinSourceContainer = new BeatmapSkinProvidingContainer(Beatmap.Value.Skin);
2021-04-14 16:47:11 +08:00
Add(gameplayContainer = new MasterGameplayClockContainer(Beatmap.Value, 0)
{
Child = beatmapSkinSourceContainer
});
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());
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
{
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;
}
public byte[] Get(string name) => name == resourceName ? TestResources.GetStore().Get("Resources/Samples/test-sample.mp3") : null;
2020-01-02 14:23:41 +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
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 IStorageResourceProvider resources;
2020-06-19 04:46:32 +08:00
public TestCustomSkinWorkingBeatmap(RulesetInfo ruleset, IStorageResourceProvider resources)
: base(ruleset, null, resources.AudioManager)
2020-06-19 04:46:32 +08:00
{
this.resources = resources;
2020-06-19 04:46: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)
{
}
}
#region IResourceStorageProvider
public AudioManager AudioManager => Audio;
public IResourceStore<byte[]> Files => null;
public new IResourceStore<byte[]> Resources => base.Resources;
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
#endregion
2020-01-02 14:23:41 +08:00
}
}