Force snaking slider paths to retain a fixed size

This commit is contained in:
smoogipoo 2019-07-25 18:22:56 +09:00
parent ae66a7e9e4
commit d4f85af19c
2 changed files with 27 additions and 9 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Lines; using osu.Framework.Graphics.Lines;
@ -75,22 +76,22 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
protected SliderBody() protected SliderBody()
{ {
InternalChild = path = new SliderPath(); RecyclePath();
} }
/// <summary> /// <summary>
/// Initialises a new <see cref="SliderPath"/>, releasing all resources retained by the old one. /// Initialises a new <see cref="SliderPath"/>, releasing all resources retained by the old one.
/// </summary> /// </summary>
public void RecyclePath() public virtual void RecyclePath()
{ {
InternalChild = path = new SliderPath InternalChild = path = new SliderPath
{ {
Position = path.Position, Position = path?.Position ?? Vector2.Zero,
PathRadius = path.PathRadius, PathRadius = path?.PathRadius ?? 10,
AccentColour = path.AccentColour, AccentColour = path?.AccentColour ?? Color4.White,
BorderColour = path.BorderColour, BorderColour = path?.BorderColour ?? Color4.White,
BorderSize = path.BorderSize, BorderSize = path?.BorderSize ?? DEFAULT_BORDER_SIZE,
Vertices = path.Vertices Vertices = path?.Vertices ?? Array.Empty<Vector2>()
}; };
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using osuTK; using osuTK;
@ -78,9 +79,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
slider.Path.GetPathToProgress(CurrentCurve, 0, 1); slider.Path.GetPathToProgress(CurrentCurve, 0, 1);
SetVertices(CurrentCurve); SetVertices(CurrentCurve);
// The body is sized to the full path size to avoid excessive autosize computations // Force the body to be the final path size to avoid excessive autosize computations
Path.AutoSizeAxes = Axes.Both;
Size = Path.Size; Size = Path.Size;
updatePathSize();
snakedPosition = Path.PositionInBoundingBox(Vector2.Zero); snakedPosition = Path.PositionInBoundingBox(Vector2.Zero);
snakedPathOffset = Path.PositionInBoundingBox(Path.Vertices[0]); snakedPathOffset = Path.PositionInBoundingBox(Path.Vertices[0]);
@ -93,6 +97,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
setRange(lastSnakedStart, lastSnakedEnd); setRange(lastSnakedStart, lastSnakedEnd);
} }
public override void RecyclePath()
{
base.RecyclePath();
updatePathSize();
}
private void updatePathSize()
{
// Force the path to its final size to avoid excessive framebuffer resizes
Path.AutoSizeAxes = Axes.None;
Path.Size = Size;
}
private void setRange(double p0, double p1) private void setRange(double p0, double p1)
{ {
if (p0 > p1) if (p0 > p1)