From a3234a52694f55faa130ecbf384f8009b9673509 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 22 Nov 2016 21:22:12 +0900 Subject: [PATCH] Avoid synchronous queries in BackgroundModeBeatmap. --- .../Backgrounds/BackgroundModeBeatmap.cs | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs index 649952ccfb..e599198009 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs @@ -1,9 +1,8 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //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; + } + + } } }