Syntriax f5a7077570 perf: improved garbage created by tweens slightly
They still do generate a lot of garbage but with boxed value pools I made the boxes reusable, it still does generate garbage through the delegate creation, gotta find a solution for them later
2025-08-14 20:31:46 +03:00

32 lines
980 B
C#

using Engine.Core;
namespace Engine.Systems.Tween;
public static class TweenLine2DExtensions
{
private static readonly BoxedPool<Line2D> boxedLine2DPool = new(2);
public static ITween TweenLine2D(this Line2D initialLine2D, ITweenManager tweenManager, float duration, Line2D targetLine2D, System.Action<Line2D> setMethod)
{
Boxed<Line2D> boxedInitial = boxedLine2DPool.Get(initialLine2D);
Boxed<Line2D> boxedTarget = boxedLine2DPool.Get(targetLine2D);
ITween tween = tweenManager.StartTween(duration,
t => setMethod?.Invoke(
new Line2D(
boxedInitial.Value.From.Lerp(boxedTarget.Value.From, t),
boxedInitial.Value.To.Lerp(boxedTarget.Value.To, t)
)
)
);
tween.OnComplete(() =>
{
boxedLine2DPool.Return(boxedInitial);
boxedLine2DPool.Return(boxedTarget);
});
return tween;
}
}