Add test scene

This commit is contained in:
Ronnie Moir 2020-06-18 21:46:32 +01:00
parent bed5e857df
commit f04f2d2175
2 changed files with 66 additions and 8 deletions

View File

@ -10,9 +10,12 @@
using osu.Framework.Audio.Sample;
using osu.Framework.IO.Stores;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osu.Game.Storyboards;
@ -70,6 +73,37 @@ public void TestSamplePlaybackAtZero()
AddUntilStep("sample playback succeeded", () => sample.LifetimeEnd < double.MaxValue);
}
[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);
}
private class TestSkin : LegacySkin
{
public TestSkin(string resourceName, AudioManager audioManager)
@ -99,5 +133,28 @@ public void Dispose()
{
}
}
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;
}
}
}

View File

@ -20,7 +20,8 @@ public class DrawableStoryboardSample : Component
private const double allowable_late_start = 100;
private readonly StoryboardSampleInfo sampleInfo;
private SampleChannel channel;
protected SampleChannel Channel;
public override bool RemoveWhenNotAlive => false;
@ -33,14 +34,14 @@ public DrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, IBindable<IReadOnlyList<Mod>> mods)
{
channel = beatmap.Value.Skin.GetSample(sampleInfo);
Channel = beatmap.Value.Skin.GetSample(sampleInfo);
if (channel != null)
if (Channel != null)
{
channel.Volume.Value = sampleInfo.Volume / 100.0;
Channel.Volume.Value = sampleInfo.Volume / 100.0;
foreach (var mod in mods.Value.OfType<IApplicableToSample>())
mod.ApplyToSample(channel);
mod.ApplyToSample(Channel);
}
}
@ -52,7 +53,7 @@ protected override void Update()
if (Time.Current < sampleInfo.StartTime)
{
// We've rewound before the start time of the sample
channel?.Stop();
Channel?.Stop();
// In the case that the user fast-forwards to a point far beyond the start time of the sample,
// we want to be able to fall into the if-conditional below (therefore we must not have a life time end)
@ -64,7 +65,7 @@ protected override void Update()
// We've passed the start time of the sample. We only play the sample if we're within an allowable range
// from the sample's start, to reduce layering if we've been fast-forwarded far into the future
if (Time.Current - sampleInfo.StartTime < allowable_late_start)
channel?.Play();
Channel?.Play();
// In the case that the user rewinds to a point far behind the start time of the sample,
// we want to be able to fall into the if-conditional above (therefore we must not have a life time start)
@ -75,7 +76,7 @@ protected override void Update()
protected override void Dispose(bool isDisposing)
{
channel?.Stop();
Channel?.Stop();
base.Dispose(isDisposing);
}
}