From e414e4442847e9742b38b6bc8d59e1d321f31a07 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Sat, 3 Jun 2017 18:18:45 +0900 Subject: [PATCH] Drastically improve mania gameplay loading time. --- .../Timing/Drawables/DrawableTimingChange.cs | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/osu.Game/Rulesets/Timing/Drawables/DrawableTimingChange.cs b/osu.Game/Rulesets/Timing/Drawables/DrawableTimingChange.cs index 04443c4b42..29ce98cceb 100644 --- a/osu.Game/Rulesets/Timing/Drawables/DrawableTimingChange.cs +++ b/osu.Game/Rulesets/Timing/Drawables/DrawableTimingChange.cs @@ -9,6 +9,7 @@ using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; using OpenTK; +using osu.Framework.Caching; namespace osu.Game.Rulesets.Timing.Drawables { @@ -94,6 +95,8 @@ namespace osu.Game.Rulesets.Timing.Drawables private readonly Axes autoSizingAxes; + private Cached layout = new Cached(); + /// /// The axes which this container should calculate its size from its children on. /// Note that this is not the same as , because that would not allow this container @@ -114,20 +117,33 @@ namespace osu.Game.Rulesets.Timing.Drawables return; } - if (!Children.Any()) - return; - - float height = Children.Select(child => child.Y + child.Height).Max(); - float width = Children.Select(child => child.X + child.Width).Max(); - - Size = new Vector2((autoSizingAxes & Axes.X) > 0 ? width : Size.X, - (autoSizingAxes & Axes.Y) > 0 ? height : Size.Y); - - RelativeCoordinateSpace = new Vector2((autoSizingAxes & Axes.X) > 0 ? width : 1, - (autoSizingAxes & Axes.Y) > 0 ? height : 1); + layout.Invalidate(); base.InvalidateFromChild(invalidation); } + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + if (!layout.EnsureValid()) + { + layout.Refresh(() => + { + if (!Children.Any()) + return; + + float height = Children.Select(child => child.Y + child.Height).Max(); + float width = Children.Select(child => child.X + child.Width).Max(); + + Size = new Vector2((autoSizingAxes & Axes.X) > 0 ? width : Size.X, + (autoSizingAxes & Axes.Y) > 0 ? height : Size.Y); + + RelativeCoordinateSpace = new Vector2((autoSizingAxes & Axes.X) > 0 ? width : 1, + (autoSizingAxes & Axes.Y) > 0 ? height : 1); + }); + } + } } } } \ No newline at end of file