Reduce allocations of followpoints by reusing existing

This commit is contained in:
Dean Herbert 2020-03-19 00:34:24 +09:00
parent 90e1f6efbf
commit 1c0c269852

View File

@ -88,8 +88,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
private void refresh() private void refresh()
{ {
ClearInternal();
OsuHitObject osuStart = Start.HitObject; OsuHitObject osuStart = Start.HitObject;
double startTime = osuStart.GetEndTime(); double startTime = osuStart.GetEndTime();
@ -116,6 +114,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
double? firstTransformStartTime = null; double? firstTransformStartTime = null;
double finalTransformEndTime = startTime; double finalTransformEndTime = startTime;
int point = 0;
for (int d = (int)(spacing * 1.5); d < distance - spacing; d += spacing) for (int d = (int)(spacing * 1.5); d < distance - spacing; d += spacing)
{ {
float fraction = (float)d / distance; float fraction = (float)d / distance;
@ -126,13 +126,18 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
FollowPoint fp; FollowPoint fp;
AddInternal(fp = new FollowPoint if (InternalChildren.Count > point)
{ {
Position = pointStartPosition, fp = (FollowPoint)InternalChildren[point];
Rotation = rotation, fp.ClearTransforms();
Alpha = 0, }
Scale = new Vector2(1.5f * osuEnd.Scale), else
}); AddInternal(fp = new FollowPoint());
fp.Position = pointStartPosition;
fp.Rotation = rotation;
fp.Alpha = 0;
fp.Scale = new Vector2(1.5f * osuEnd.Scale);
if (firstTransformStartTime == null) if (firstTransformStartTime == null)
firstTransformStartTime = fadeInTime; firstTransformStartTime = fadeInTime;
@ -146,8 +151,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
finalTransformEndTime = fadeOutTime + osuEnd.TimeFadeIn; finalTransformEndTime = fadeOutTime + osuEnd.TimeFadeIn;
} }
point++;
} }
int excessPoints = InternalChildren.Count - point;
for (int i = 0; i < excessPoints; i++)
RemoveInternal(InternalChildren[^1]);
// todo: use Expire() on FollowPoints and take lifetime from them when https://github.com/ppy/osu-framework/issues/3300 is fixed. // todo: use Expire() on FollowPoints and take lifetime from them when https://github.com/ppy/osu-framework/issues/3300 is fixed.
LifetimeStart = firstTransformStartTime ?? startTime; LifetimeStart = firstTransformStartTime ?? startTime;
LifetimeEnd = finalTransformEndTime; LifetimeEnd = finalTransformEndTime;