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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user