mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09: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:
@ -13,16 +13,21 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
|
|
||||||
private readonly string fallbackTextureName;
|
private readonly string fallbackTextureName;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private LargeTextureStore textures { get; set; }
|
||||||
|
|
||||||
public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1")
|
public BeatmapBackground(WorkingBeatmap beatmap, string fallbackTextureName = @"Backgrounds/bg1")
|
||||||
{
|
{
|
||||||
Beatmap = beatmap;
|
Beatmap = beatmap;
|
||||||
this.fallbackTextureName = fallbackTextureName;
|
this.fallbackTextureName = fallbackTextureName;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
protected override void LoadComplete()
|
||||||
private void load(LargeTextureStore textures)
|
|
||||||
{
|
{
|
||||||
Sprite.Texture = Beatmap?.Background ?? textures.Get(fallbackTextureName);
|
base.LoadComplete();
|
||||||
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void Initialize() => Sprite.Texture = Beatmap?.Background ?? textures.Get(fallbackTextureName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Storyboards.Drawables;
|
using osu.Game.Storyboards.Drawables;
|
||||||
@ -16,19 +15,21 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
protected override void Initialize()
|
||||||
private void load()
|
|
||||||
{
|
{
|
||||||
LoadComponentAsync(new DrawableStoryboard(Beatmap.Storyboard)
|
if (Beatmap.Storyboard.HasDrawable)
|
||||||
{
|
{
|
||||||
Clock = new InterpolatingFramedClock(Beatmap.Track),
|
LoadComponentAsync(new DrawableStoryboard(Beatmap.Storyboard) { Clock = new InterpolatingFramedClock(Beatmap.Track) }, AddInternal);
|
||||||
},
|
}
|
||||||
loaded =>
|
|
||||||
|
if (Beatmap.Storyboard.ReplacesBackground || Beatmap.Storyboard.Layers.First(l => l.Name == "Video").Elements.Any())
|
||||||
{
|
{
|
||||||
AddInternal(loaded);
|
Sprite.Expire();
|
||||||
if (Beatmap.Storyboard.ReplacesBackground)
|
}
|
||||||
Sprite.FadeOut(300, Easing.OutQuint);
|
else
|
||||||
});
|
{
|
||||||
|
base.Initialize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user