Merge pull request #20308 from peppy/fix-slider-rotation-slowness

Fix slider rotation causing thousands of new drawables to be created
This commit is contained in:
Dan Balasescu 2022-09-15 20:33:08 +09:00 committed by GitHub
commit fe46acb136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 19 deletions

View File

@ -66,11 +66,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
cachePoints(slider);
sliderVersion = slider.Path.Version.GetBoundCopy();
sliderVersion.BindValueChanged(_ =>
// schedule ensure that updates are only applied after all operations from a single frame are applied.
// this avoids inadvertently changing the slider path type for batch operations.
sliderVersion.BindValueChanged(_ => Scheduler.AddOnce(() =>
{
cachePoints(slider);
updatePathType();
});
}));
controlPoint.Changed += updateMarkerDisplay;

View File

@ -127,16 +127,13 @@ namespace osu.Game.Rulesets.Osu.Edit
{
didFlip = true;
var controlPoints = slider.Path.ControlPoints.Select(p =>
new PathControlPoint(new Vector2(
(direction == Direction.Horizontal ? -1 : 1) * p.Position.X,
(direction == Direction.Vertical ? -1 : 1) * p.Position.Y
), p.Type)).ToArray();
// Importantly, update as a single operation so automatic adjustment of control points to different
// curve types does not unexpectedly trigger and change the slider's shape.
slider.Path.ControlPoints.Clear();
slider.Path.ControlPoints.AddRange(controlPoints);
foreach (var cp in slider.Path.ControlPoints)
{
cp.Position = new Vector2(
(direction == Direction.Horizontal ? -1 : 1) * cp.Position.X,
(direction == Direction.Vertical ? -1 : 1) * cp.Position.Y
);
}
}
}
@ -186,13 +183,8 @@ namespace osu.Game.Rulesets.Osu.Edit
if (h is IHasPath path)
{
var controlPoints = path.Path.ControlPoints.Select(p =>
new PathControlPoint(RotatePointAroundOrigin(p.Position, Vector2.Zero, delta), p.Type)).ToArray();
// Importantly, update as a single operation so automatic adjustment of control points to different
// curve types does not unexpectedly trigger and change the slider's shape.
path.Path.ControlPoints.Clear();
path.Path.ControlPoints.AddRange(controlPoints);
foreach (PathControlPoint cp in path.Path.ControlPoints)
cp.Position = RotatePointAroundOrigin(cp.Position, Vector2.Zero, delta);
}
}