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

Avoid synchronous queries in BackgroundModeBeatmap.

This commit is contained in:
Dean Herbert 2016-11-22 21:22:12 +09:00
parent 3bc38268a0
commit a3234a5269

View File

@ -1,9 +1,8 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>. //Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using OpenTK; using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations; using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Background; using osu.Game.Graphics.Background;
@ -15,6 +14,7 @@ namespace osu.Game.Screens.Backgrounds
private Background background; private Background background;
private WorkingBeatmap beatmap; private WorkingBeatmap beatmap;
private Vector2 blurTarget;
public WorkingBeatmap Beatmap public WorkingBeatmap Beatmap
{ {
@ -30,10 +30,16 @@ namespace osu.Game.Screens.Backgrounds
beatmap = value; beatmap = value;
Schedule(() =>
{
Background newBackground = new BeatmapBackground(beatmap);
newBackground.Preload(Game, delegate
{
Background oldBackground = background; Background oldBackground = background;
addBackground(background = new Background()); Add(background = newBackground);
background.Sprite.Texture = beatmap.Background; background.BlurSigma = blurTarget;
if (oldBackground != null) if (oldBackground != null)
{ {
@ -41,9 +47,9 @@ namespace osu.Game.Screens.Backgrounds
oldBackground.Flush(); oldBackground.Flush();
oldBackground.FadeOut(250); oldBackground.FadeOut(250);
oldBackground.Expire(); oldBackground.Expire();
background.BlurSigma = oldBackground.BlurSigma;
} }
});
});
} }
} }
@ -52,20 +58,33 @@ namespace osu.Game.Screens.Backgrounds
Beatmap = beatmap; Beatmap = beatmap;
} }
private void addBackground(Background background)
{
background.CacheDrawnFrameBuffer = true;
Add(background);
}
public void BlurTo(Vector2 sigma, double duration) public void BlurTo(Vector2 sigma, double duration)
{ {
background?.BlurTo(sigma, duration, EasingTypes.OutExpo); background?.BlurTo(sigma, duration, EasingTypes.OutExpo);
blurTarget = sigma;
} }
public override bool Equals(BackgroundMode other) public override bool Equals(BackgroundMode other)
{ {
return base.Equals(other) && beatmap == ((BackgroundModeBeatmap)other).Beatmap; 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;
}
}
} }
} }