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
25 lines
830 B
C#
25 lines
830 B
C#
using Engine.Core;
|
|
|
|
namespace Engine.Systems.Tween;
|
|
|
|
public static class TweenVector2DExtensions
|
|
{
|
|
private static readonly BoxedPool<Vector2D> boxedVector2DPool = new(2);
|
|
|
|
public static ITween TweenVector2D(this Vector2D initialVector2D, ITweenManager tweenManager, float duration, Vector2D targetVector2D, System.Action<Vector2D> setMethod)
|
|
{
|
|
Boxed<Vector2D> boxedInitial = boxedVector2DPool.Get(initialVector2D);
|
|
Boxed<Vector2D> boxedTarget = boxedVector2DPool.Get(targetVector2D);
|
|
|
|
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t)));
|
|
|
|
tween.OnComplete(() =>
|
|
{
|
|
boxedVector2DPool.Return(boxedInitial);
|
|
boxedVector2DPool.Return(boxedTarget);
|
|
});
|
|
|
|
return tween;
|
|
}
|
|
}
|