mirror of
https://github.com/ppy/osu.git
synced 2026-05-27 16:10:16 +08:00
0e443b1c47
- Closes https://github.com/ppy/osu/issues/37757 Commit-by-commit reading is recommended. Commits will be split to PRs on request but I consider this to be the minimal viable functional increment. ## Done - This adds a first version of a full storyboard encoder (a66dc406f498e35d4e0c8f2a462e946a9a1aeccc). I expect there to be hiccups due to weird corners of the `.osb` format; this is only intended to be somewhat correct as a start to build upon. Storyboarders are asked to file issues as necessary. - Due to the fact that storyboard definitions can reside both in the `.osu` and the `.osb`, b60698a95c4de1bfeb36fbb159fd5a6028920832 adds the required storage to be able to tell which storyboard element lives where, so that it can be decoded properly later. - In c9d3e04a4135886b5b0943c85f3cc6f4fe99c84c, the storyboard decoder is weaved into the beatmap decoder to handle the `.osu` part of the storyboard, via the `LegacyStoryboardEncoder.Encode{General,Events}ToBeatmap()` methods. For `.osb`s, `LegacyStoryboardEncoder.EncodeStandaloneStoryboard()` is intended, but for now is not used outside tests. - Because of the above, dd1c4e43dc51154cd67860f096712f8b4f229661 removes `Beatmap.UnhandledEventLines` as no longer required. - 26ac417ed98a8937c42e5f52c4e15ef065a48902 adds tests. They are mostly handwritten to ensure basic encode-decode roundtripping. Using existing storyboards is difficult, see "Known issues" section as to why. - 5cc542366db7caac38eb0729260d884905a2c0d5 fixes a bug in the storyboard decoder where the trigger group number was not properly negated on decode (see inline comment reference to relevant stable code). ## Known issues - Any and all variables in the `[Variables]` section are inlined into their usages by `LegacyStoryboardDecoder`, and as such `LegacyStoryboardEncoder` will end up inlining them and discarding the `[Variables]` section. As far as I can tell stable will also do this. - `LegacyStoryboardDecoder` splits all `M` (move) commands into `MX`/`MY` commands. Therefore, `LegacyStoryboardEncoder` will write out things in the same split way. I did not put in effort to attempt to reconcile this, for reasons of part laziness, part not wanting to bloat this already-large diff. - Ordering of storyboard samples on decode may not match the order on decode. I'm crossing fingers this doesn't matter.
153 lines
5.9 KiB
C#
153 lines
5.9 KiB
C#
// 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.
|
|
|
|
#nullable disable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NUnit.Framework;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
|
using osu.Framework.Graphics.Audio;
|
|
using osu.Framework.Testing;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Configuration;
|
|
using osu.Game.Rulesets;
|
|
using osu.Game.Rulesets.Mods;
|
|
using osu.Game.Rulesets.Osu;
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
using osu.Game.Storyboards;
|
|
using osu.Game.Storyboards.Drawables;
|
|
using osuTK.Input;
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
{
|
|
public partial class TestSceneStoryboardSamplePlayback : PlayerTestScene
|
|
{
|
|
private Storyboard storyboard;
|
|
|
|
private IReadOnlyList<Mod> storyboardMods;
|
|
|
|
protected override bool HasCustomSteps => true;
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OsuConfigManager config)
|
|
{
|
|
config.SetValue(OsuSetting.ShowStoryboard, true);
|
|
|
|
storyboard = new Storyboard();
|
|
var backgroundLayer = storyboard.GetLayer("Background");
|
|
backgroundLayer.Add(new StoryboardSampleInfo(StoryboardElementSource.Beatmap, "Intro/welcome.mp3", time: -7000, volume: 20));
|
|
backgroundLayer.Add(new StoryboardSampleInfo(StoryboardElementSource.Beatmap, "Intro/welcome.mp3", time: -5000, volume: 20));
|
|
backgroundLayer.Add(new StoryboardSampleInfo(StoryboardElementSource.Beatmap, "Intro/welcome.mp3", time: 0, volume: 20));
|
|
backgroundLayer.Add(new StoryboardSampleInfo(StoryboardElementSource.Beatmap, "Intro/welcome.mp3", time: 2000, volume: 20));
|
|
}
|
|
|
|
[SetUp]
|
|
public void SetUp() => storyboardMods = Array.Empty<Mod>();
|
|
|
|
[Test]
|
|
public void TestStoryboardSamplesStopDuringPause()
|
|
{
|
|
createPlayerTest();
|
|
|
|
AddStep("player paused", () => Player.Pause());
|
|
AddAssert("player is currently paused", () => Player.GameplayClockContainer.IsPaused.Value);
|
|
allStoryboardSamplesStopped();
|
|
|
|
AddStep("player resume", () => Player.Resume());
|
|
waitUntilStoryboardSamplesPlay();
|
|
}
|
|
|
|
[Test]
|
|
public void TestStoryboardSamplesStopOnSkip()
|
|
{
|
|
createPlayerTest();
|
|
|
|
skipIntro();
|
|
allStoryboardSamplesStopped();
|
|
|
|
waitUntilStoryboardSamplesPlay();
|
|
}
|
|
|
|
[TestCase(typeof(OsuModDoubleTime), 1.5)]
|
|
[TestCase(typeof(OsuModDoubleTime), 2)]
|
|
[TestCase(typeof(OsuModHalfTime), 0.75)]
|
|
[TestCase(typeof(OsuModHalfTime), 0.5)]
|
|
public void TestStoryboardSamplesPlaybackWithRateAdjustMods(Type expectedMod, double expectedRate)
|
|
{
|
|
AddStep("setup mod", () =>
|
|
{
|
|
ModRateAdjust testedMod = (ModRateAdjust)Activator.CreateInstance(expectedMod).AsNonNull();
|
|
testedMod.SpeedChange.Value = expectedRate;
|
|
storyboardMods = new[] { testedMod };
|
|
});
|
|
|
|
createPlayerTest();
|
|
skipIntro();
|
|
|
|
AddAssert("sample playback rate matches mod rates", () => allStoryboardSamples.All(sound =>
|
|
sound.ChildrenOfType<DrawableSample>().First().AggregateFrequency.Value == expectedRate));
|
|
}
|
|
|
|
[TestCase(typeof(ModWindUp), 0.5, 2)]
|
|
[TestCase(typeof(ModWindUp), 1.51, 2)]
|
|
[TestCase(typeof(ModWindDown), 2, 0.5)]
|
|
[TestCase(typeof(ModWindDown), 0.99, 0.5)]
|
|
public void TestStoryboardSamplesPlaybackWithTimeRampMods(Type expectedMod, double initialRate, double finalRate)
|
|
{
|
|
AddStep("setup mod", () =>
|
|
{
|
|
ModTimeRamp testedMod = (ModTimeRamp)Activator.CreateInstance(expectedMod).AsNonNull();
|
|
testedMod.InitialRate.Value = initialRate;
|
|
testedMod.FinalRate.Value = finalRate;
|
|
storyboardMods = new[] { testedMod };
|
|
});
|
|
|
|
createPlayerTest();
|
|
skipIntro();
|
|
|
|
ModTimeRamp gameplayMod = null;
|
|
|
|
AddUntilStep("mod speed change updated", () =>
|
|
{
|
|
gameplayMod = Player.GameplayState.Mods.OfType<ModTimeRamp>().Single();
|
|
return gameplayMod.SpeedChange.Value != initialRate;
|
|
});
|
|
|
|
AddAssert("sample playback rate matches mod rates", () => allStoryboardSamples.All(sound =>
|
|
sound.ChildrenOfType<DrawableSample>().First().AggregateFrequency.Value == gameplayMod.SpeedChange.Value));
|
|
}
|
|
|
|
private void createPlayerTest()
|
|
{
|
|
CreateTest();
|
|
|
|
AddAssert("storyboard loaded", () => Player.Beatmap.Value.Storyboard != null);
|
|
waitUntilStoryboardSamplesPlay();
|
|
}
|
|
|
|
private void waitUntilStoryboardSamplesPlay() => AddUntilStep("any storyboard samples playing", () => allStoryboardSamples.Any(sound => sound.IsPlaying));
|
|
|
|
private void allStoryboardSamplesStopped() => AddAssert("all storyboard samples stopped immediately", () => allStoryboardSamples.All(sound => !sound.IsPlaying));
|
|
|
|
private void skipIntro() => AddStep("skip intro", () => InputManager.Key(Key.Space));
|
|
|
|
private IEnumerable<DrawableStoryboardSample> allStoryboardSamples => Player.ChildrenOfType<DrawableStoryboardSample>();
|
|
|
|
protected override bool AllowFail => false;
|
|
|
|
protected override TestPlayer CreatePlayer(Ruleset ruleset)
|
|
{
|
|
SelectedMods.Value = SelectedMods.Value.Concat(storyboardMods).ToArray();
|
|
return new TestPlayer(true, false);
|
|
}
|
|
|
|
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();
|
|
|
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) =>
|
|
new ClockBackedTestWorkingBeatmap(beatmap, storyboard ?? this.storyboard, Clock, Audio);
|
|
}
|
|
}
|