Syntriax.Engine/Engine.Systems/Tween/EngineExtensions/TweenProjection1DExtensions.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 TweenProjection1DExtensions
{
private static readonly BoxedPool<Projection1D> boxedProjection1DPool = new(2);
public static ITween TweenProjection1D(this Projection1D initialProjection1D, ITweenManager tweenManager, float duration, Projection1D targetProjection1D, System.Action<Projection1D> setMethod)
{
Boxed<Projection1D> boxedInitial = boxedProjection1DPool.Get(initialProjection1D);
Boxed<Projection1D> boxedTarget = boxedProjection1DPool.Get(targetProjection1D);
ITween tween = tweenManager.StartTween(duration,
t => setMethod?.Invoke(
new Projection1D(
boxedInitial.Value.Min.Lerp(boxedTarget.Value.Min, t),
boxedInitial.Value.Max.Lerp(boxedTarget.Value.Max, t)
)
)
);
tween.OnComplete(() =>
{
boxedProjection1DPool.Return(boxedInitial);
boxedProjection1DPool.Return(boxedTarget);
});
return tween;
}
}