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
This commit is contained in:
2025-08-14 20:31:46 +03:00
parent 746d29fb7a
commit f5a7077570
15 changed files with 278 additions and 57 deletions

View File

@@ -4,13 +4,28 @@ namespace Engine.Systems.Tween;
public static class TweenCircleExtensions
{
private static readonly BoxedPool<Circle> boxedCirclePool = new(2);
public static ITween TweenCircle(this Circle initialCircle, ITweenManager tweenManager, float duration, Circle targetCircle, System.Action<Circle> setMethod)
=> tweenManager.StartTween(duration,
{
Boxed<Circle> boxedInitial = boxedCirclePool.Get(initialCircle);
Boxed<Circle> boxedTarget = boxedCirclePool.Get(targetCircle);
ITween tween = tweenManager.StartTween(duration,
t => setMethod?.Invoke(
new Circle(
initialCircle.Center.Lerp(targetCircle.Center, t),
initialCircle.Diameter.Lerp(targetCircle.Diameter, t)
boxedInitial.Value.Center.Lerp(boxedTarget.Value.Center, t),
boxedInitial.Value.Diameter.Lerp(boxedTarget.Value.Diameter, t)
)
)
);
tween.OnComplete(() =>
{
boxedCirclePool.Return(boxedInitial);
boxedCirclePool.Return(boxedTarget);
});
return tween;
}
}