1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

refactor BeatmapBackgroundWithStoryboard to reduce overhead

This avoids loading the sprite if its not needed and instead of hiding it, it is removed when the storyboard replaces the background or there is a video.

This also only initializes DrawableStoryboard if there are any elements in any layer.
This commit is contained in:
Nathan Alo 2021-06-02 20:27:12 +08:00
parent 3c3ef13632
commit 277545bb06
2 changed files with 23 additions and 17 deletions

View File

@ -13,16 +13,21 @@ namespace osu.Game.Graphics.Backgrounds
private readonly string fallbackTextureName;
[Resolved]
private LargeTextureStore textures { get; set; }
public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1")
{
Beatmap = beatmap;
this.fallbackTextureName = fallbackTextureName;
}
[BackgroundDependencyLoader]
private void load(LargeTextureStore textures)
protected override void LoadComplete()
{
Sprite.Texture = Beatmap?.Background ?? textures.Get(fallbackTextureName);
base.LoadComplete();
Initialize();
}
protected virtual void Initialize() => Sprite.Texture = Beatmap?.Background ?? textures.Get(fallbackTextureName);
}
}

View File

@ -1,8 +1,7 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using System.Linq;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Storyboards.Drawables;
@ -16,19 +15,21 @@ namespace osu.Game.Graphics.Backgrounds
{
}
[BackgroundDependencyLoader]
private void load()
protected override void Initialize()
{
LoadComponentAsync(new DrawableStoryboard(Beatmap.Storyboard)
{
Clock = new InterpolatingFramedClock(Beatmap.Track),
},
loaded =>
{
AddInternal(loaded);
if (Beatmap.Storyboard.ReplacesBackground)
Sprite.FadeOut(300, Easing.OutQuint);
});
if (Beatmap.Storyboard.HasDrawable)
{
LoadComponentAsync(new DrawableStoryboard(Beatmap.Storyboard) { Clock = new InterpolatingFramedClock(Beatmap.Track) }, AddInternal);
}
if (Beatmap.Storyboard.ReplacesBackground || Beatmap.Storyboard.Layers.First(l => l.Name == "Video").Elements.Any())
{
Sprite.Expire();
}
else
{
base.Initialize();
}
}
}
}