1
0
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:
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>.
//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,20 +30,26 @@ namespace osu.Game.Screens.Backgrounds
beatmap = value;
Background oldBackground = background;
addBackground(background = new Background());
background.Sprite.Texture = beatmap.Background;
if (oldBackground != null)
Schedule(() =>
{
oldBackground.Depth = 1;
oldBackground.Flush();
oldBackground.FadeOut(250);
oldBackground.Expire();
Background newBackground = new BeatmapBackground(beatmap);
background.BlurSigma = oldBackground.BlurSigma;
}
newBackground.Preload(Game, delegate
{
Background oldBackground = background;
Add(background = newBackground);
background.BlurSigma = blurTarget;
if (oldBackground != null)
{
oldBackground.Depth = 1;
oldBackground.Flush();
oldBackground.FadeOut(250);
oldBackground.Expire();
}
});
});
}
}
@ -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;
}
}
}
}