Syntriax.Engine/Engine.Systems/Tween/EngineExtensions/TweenLine2DEquationExtensions.cs
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
1.1 KiB
C#

using Engine.Core;
namespace Engine.Systems.Tween;
public static class TweenLine2DEquationExtensions
{
private static readonly BoxedPool<Line2DEquation> boxedLine2DEquationPool = new(2);
public static ITween TweenLine2DEquation(this Line2DEquation initialLine2DEquation, ITweenManager tweenManager, float duration, Line2DEquation targetLine2DEquation, System.Action<Line2DEquation> setMethod)
{
Boxed<Line2DEquation> boxedInitial = boxedLine2DEquationPool.Get(initialLine2DEquation);
Boxed<Line2DEquation> boxedTarget = boxedLine2DEquationPool.Get(targetLine2DEquation);
ITween tween = tweenManager.StartTween(duration,
t => setMethod?.Invoke(
new Line2DEquation(
boxedInitial.Value.Slope.Lerp(boxedTarget.Value.Slope, t),
boxedInitial.Value.OffsetY.Lerp(boxedTarget.Value.OffsetY, t)
)
)
);
tween.OnComplete(() =>
{
boxedLine2DEquationPool.Return(boxedInitial);
boxedLine2DEquationPool.Return(boxedTarget);
});
return tween;
}
}