mirror of
https://github.com/ppy/osu.git
synced 2026-06-03 17:23:57 +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.
214 lines
7.7 KiB
C#
214 lines
7.7 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.Collections.Generic;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Audio;
|
|
using osu.Framework.Audio.Sample;
|
|
using osu.Framework.Graphics.Rendering;
|
|
using osu.Framework.Graphics.Textures;
|
|
using osu.Framework.IO.Stores;
|
|
using osu.Framework.Platform;
|
|
using osu.Framework.Testing;
|
|
using osu.Game.Audio;
|
|
using osu.Game.Configuration;
|
|
using osu.Game.Database;
|
|
using osu.Game.IO;
|
|
using osu.Game.Rulesets;
|
|
using osu.Game.Rulesets.Osu;
|
|
using osu.Game.Rulesets.UI;
|
|
using osu.Game.Screens.Play;
|
|
using osu.Game.Skinning;
|
|
using osu.Game.Storyboards;
|
|
using osu.Game.Storyboards.Drawables;
|
|
using osu.Game.Tests.Resources;
|
|
using osu.Game.Tests.Visual;
|
|
|
|
namespace osu.Game.Tests.Gameplay
|
|
{
|
|
[HeadlessTest]
|
|
public partial class TestSceneStoryboardSamples : OsuTestScene, IStorageResourceProvider
|
|
{
|
|
[Resolved]
|
|
private OsuConfigManager config { get; set; }
|
|
|
|
[Resolved]
|
|
private GameHost host { get; set; }
|
|
|
|
[Test]
|
|
public void TestRetrieveTopLevelSample()
|
|
{
|
|
ISkin skin = null;
|
|
ISample channel = null;
|
|
|
|
AddStep("create skin", () => skin = new TestSkin("test-sample", this));
|
|
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;
|
|
|
|
AddStep("create skin", () => skin = new TestSkin("folder/test-sample", this));
|
|
AddStep("retrieve sample", () => channel = skin.GetSample(new SampleInfo("folder/test-sample")));
|
|
|
|
AddAssert("sample is non-null", () => channel != null);
|
|
}
|
|
|
|
[Test]
|
|
public void TestSamplePlaybackAtZero()
|
|
{
|
|
GameplayClockContainer gameplayContainer = null;
|
|
DrawableStoryboardSample sample = null;
|
|
|
|
AddStep("create container", () =>
|
|
{
|
|
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
|
|
|
Add(gameplayContainer = new MasterGameplayClockContainer(working, 0)
|
|
{
|
|
Child = new FrameStabilityContainer
|
|
{
|
|
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(StoryboardElementSource.Beatmap, string.Empty, 0, 1))
|
|
}
|
|
});
|
|
});
|
|
|
|
AddStep("reset clock", () => gameplayContainer.Reset(startClock: true));
|
|
|
|
AddUntilStep("sample played", () => sample.RequestedPlaying);
|
|
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sample at 0ms, start time at 1000ms (so the sample should not be played).
|
|
/// </summary>
|
|
[Test]
|
|
public void TestSampleHasLifetimeEndWithInitialClockTime()
|
|
{
|
|
MasterGameplayClockContainer gameplayContainer = null;
|
|
DrawableStoryboardSample sample = null;
|
|
|
|
AddStep("create container", () =>
|
|
{
|
|
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
|
|
|
const double start_time = 1000;
|
|
|
|
Add(gameplayContainer = new MasterGameplayClockContainer(working, start_time)
|
|
{
|
|
Child = new FrameStabilityContainer
|
|
{
|
|
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(StoryboardElementSource.Beatmap, string.Empty, 0, 1))
|
|
}
|
|
});
|
|
|
|
gameplayContainer.Reset(start_time);
|
|
});
|
|
|
|
AddStep("start time", () => gameplayContainer.Start());
|
|
|
|
AddUntilStep("sample not played", () => !sample.RequestedPlaying);
|
|
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
|
|
}
|
|
|
|
[Test]
|
|
public void TestSamplePlaybackWithBeatmapHitsoundsOff()
|
|
{
|
|
GameplayClockContainer gameplayContainer = null;
|
|
DrawableStoryboardSample sample = null;
|
|
|
|
AddStep("disable beatmap hitsounds", () => config.SetValue(OsuSetting.BeatmapHitsounds, false));
|
|
|
|
AddStep("setup storyboard sample", () =>
|
|
{
|
|
Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, this);
|
|
|
|
var beatmapSkinSourceContainer = new BeatmapSkinProvidingContainer(Beatmap.Value.Skin);
|
|
|
|
Add(gameplayContainer = new MasterGameplayClockContainer(Beatmap.Value, 0)
|
|
{
|
|
Child = beatmapSkinSourceContainer
|
|
});
|
|
|
|
beatmapSkinSourceContainer.Add(sample = new DrawableStoryboardSample(new StoryboardSampleInfo(StoryboardElementSource.Beatmap, "test-sample", 1, 1))
|
|
{
|
|
Clock = gameplayContainer
|
|
});
|
|
});
|
|
|
|
AddStep("reset clock", () => gameplayContainer.Reset(startClock: true));
|
|
|
|
AddUntilStep("sample played", () => sample.IsPlayed);
|
|
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
|
|
|
|
AddStep("restore default", () => config.GetBindable<bool>(OsuSetting.BeatmapHitsounds).SetDefault());
|
|
}
|
|
|
|
private class TestSkin : LegacySkin
|
|
{
|
|
public TestSkin(string resourceName, IStorageResourceProvider resources)
|
|
: base(DefaultLegacySkin.CreateInfo(), resources, new TestResourceStore(resourceName))
|
|
{
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
|
=> name == resourceName ? TestResources.GetStore().GetAsync("Resources/Samples/test-sample.mp3", cancellationToken) : null;
|
|
|
|
public Stream GetStream(string name) => name == resourceName ? TestResources.GetStore().GetStream("Resources/Samples/test-sample.mp3") : null;
|
|
|
|
public IEnumerable<string> GetAvailableResources() => new[] { resourceName };
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
|
|
private class TestCustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
|
|
{
|
|
private readonly IStorageResourceProvider resources;
|
|
|
|
public TestCustomSkinWorkingBeatmap(RulesetInfo ruleset, IStorageResourceProvider resources)
|
|
: base(ruleset, null, resources.AudioManager)
|
|
{
|
|
this.resources = resources;
|
|
}
|
|
|
|
protected internal override ISkin GetSkin() => new TestSkin("test-sample", resources);
|
|
}
|
|
|
|
#region IResourceStorageProvider
|
|
|
|
public IRenderer Renderer => host.Renderer;
|
|
public AudioManager AudioManager => Audio;
|
|
public IResourceStore<byte[]> Files => null!;
|
|
public new IResourceStore<byte[]> Resources => base.Resources;
|
|
public RealmAccess RealmAccess => null!;
|
|
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
|
|
|
|
#endregion
|
|
}
|
|
}
|