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:
12
Engine.Systems/Tween/Helpers/Boxed.cs
Normal file
12
Engine.Systems/Tween/Helpers/Boxed.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Tween;
|
||||
|
||||
public class Boxed<T> where T : struct
|
||||
{
|
||||
public Event<Boxed<T>, BoxedValueChangedArguments> OnValueChanged { get; } = new();
|
||||
|
||||
public T Value { get; set; } = default;
|
||||
|
||||
public readonly record struct BoxedValueChangedArguments(T PreviousValue, T CurrentValue);
|
||||
}
|
14
Engine.Systems/Tween/Helpers/BoxedPool.cs
Normal file
14
Engine.Systems/Tween/Helpers/BoxedPool.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Tween;
|
||||
|
||||
public class BoxedPool<T>(int initialCapacity = 1) : Pool<Boxed<T>>(() => new(), initialCapacity) where T : struct;
|
||||
public static class BoxedPoolExtensions
|
||||
{
|
||||
public static Boxed<T> Get<T>(this BoxedPool<T> boxedPool, T value) where T : struct
|
||||
{
|
||||
Boxed<T> boxed = boxedPool.Get();
|
||||
boxed.Value = value;
|
||||
return boxed;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user