mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 09:42:54 +08:00
Avoid synchronous queries in BackgroundModeBeatmap.
This commit is contained in:
parent
3bc38268a0
commit
a3234a5269
@ -1,9 +1,8 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Background;
|
||||
@ -15,6 +14,7 @@ namespace osu.Game.Screens.Backgrounds
|
||||
private Background background;
|
||||
|
||||
private WorkingBeatmap beatmap;
|
||||
private Vector2 blurTarget;
|
||||
|
||||
public WorkingBeatmap Beatmap
|
||||
{
|
||||
@ -30,10 +30,16 @@ namespace osu.Game.Screens.Backgrounds
|
||||
|
||||
beatmap = value;
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
Background newBackground = new BeatmapBackground(beatmap);
|
||||
|
||||
newBackground.Preload(Game, delegate
|
||||
{
|
||||
Background oldBackground = background;
|
||||
|
||||
addBackground(background = new Background());
|
||||
background.Sprite.Texture = beatmap.Background;
|
||||
Add(background = newBackground);
|
||||
background.BlurSigma = blurTarget;
|
||||
|
||||
if (oldBackground != null)
|
||||
{
|
||||
@ -41,9 +47,9 @@ namespace osu.Game.Screens.Backgrounds
|
||||
oldBackground.Flush();
|
||||
oldBackground.FadeOut(250);
|
||||
oldBackground.Expire();
|
||||
|
||||
background.BlurSigma = oldBackground.BlurSigma;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,20 +58,33 @@ namespace osu.Game.Screens.Backgrounds
|
||||
Beatmap = beatmap;
|
||||
}
|
||||
|
||||
private void addBackground(Background background)
|
||||
{
|
||||
background.CacheDrawnFrameBuffer = true;
|
||||
Add(background);
|
||||
}
|
||||
|
||||
public void BlurTo(Vector2 sigma, double duration)
|
||||
{
|
||||
background?.BlurTo(sigma, duration, EasingTypes.OutExpo);
|
||||
blurTarget = sigma;
|
||||
}
|
||||
|
||||
public override bool Equals(BackgroundMode other)
|
||||
{
|
||||
return base.Equals(other) && beatmap == ((BackgroundModeBeatmap)other).Beatmap;
|
||||
}
|
||||
|
||||
class BeatmapBackground : Background
|
||||
{
|
||||
private WorkingBeatmap beatmap;
|
||||
|
||||
public BeatmapBackground(WorkingBeatmap beatmap)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
CacheDrawnFrameBuffer = true;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Sprite.Texture = beatmap.Background;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user