diff --git a/Engine.Core/Helpers/ListPool.cs b/Engine.Core/Helpers/ListPool.cs index 19884e6..2377e79 100644 --- a/Engine.Core/Helpers/ListPool.cs +++ b/Engine.Core/Helpers/ListPool.cs @@ -31,10 +31,10 @@ public class ListPool : IPool> OnReturned?.Invoke(this, list); } - public ListPool(Func> generator, int initialCapacity = 1) + public ListPool(int initialListCount = 1, int initialListCapacity = 32) { - this.generator = generator; - for (int i = 0; i < initialCapacity; i++) + generator = () => new(initialListCapacity); + for (int i = 0; i < initialListCount; i++) queue.Enqueue(generator()); } } diff --git a/Engine.Physics2D/PhysicsEngine2D.cs b/Engine.Physics2D/PhysicsEngine2D.cs index 4e84b5b..10de29b 100644 --- a/Engine.Physics2D/PhysicsEngine2D.cs +++ b/Engine.Physics2D/PhysicsEngine2D.cs @@ -25,11 +25,11 @@ public class PhysicsEngine2D : Behaviour, IPreUpdate, IPhysicsEngine2D protected BehaviourCollector rigidBodyCollector = new(); protected BehaviourCollector colliderCollector = new(); - private readonly ListPool colliderPool = new(() => new(32)); - private readonly ListPool prePhysicsUpdatePool = new(() => new(32)); - private readonly ListPool physicsUpdatePool = new(() => new(32)); - private readonly ListPool physicsIterationPool = new(() => new(32)); - private readonly ListPool postPhysicsUpdatePool = new(() => new(32)); + private readonly ListPool colliderPool = new(); + private readonly ListPool prePhysicsUpdatePool = new(); + private readonly ListPool physicsUpdatePool = new(); + private readonly ListPool physicsIterationPool = new(); + private readonly ListPool postPhysicsUpdatePool = new(); public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; } public float IterationPeriod { get => _iterationPeriod; set => _iterationPeriod = value.Max(0.0001f); } diff --git a/Engine.Physics2D/PhysicsEngine2DStandalone.cs b/Engine.Physics2D/PhysicsEngine2DStandalone.cs index 5998f04..5de9885 100644 --- a/Engine.Physics2D/PhysicsEngine2DStandalone.cs +++ b/Engine.Physics2D/PhysicsEngine2DStandalone.cs @@ -21,11 +21,11 @@ public class PhysicsEngine2DStandalone : IPhysicsEngine2D private readonly ICollisionResolver2D collisionResolver = null!; private readonly IRaycastResolver2D raycastResolver = null!; - private readonly ListPool colliderPool = new(() => new(32)); - private readonly ListPool prePhysicsUpdatePool = new(() => new(32)); - private readonly ListPool physicsUpdatePool = new(() => new(32)); - private readonly ListPool physicsIterationPool = new(() => new(32)); - private readonly ListPool postPhysicsUpdatePool = new(() => new(32)); + private readonly ListPool colliderPool = new(); + private readonly ListPool prePhysicsUpdatePool = new(); + private readonly ListPool physicsUpdatePool = new(); + private readonly ListPool physicsIterationPool = new(); + private readonly ListPool postPhysicsUpdatePool = new(); public int IterationPerStep { get => _iterationCount; set => _iterationCount = value < 1 ? 1 : value; } diff --git a/Engine.Physics2D/RaycastResolver2D.cs b/Engine.Physics2D/RaycastResolver2D.cs index 881e4ad..726a2e5 100644 --- a/Engine.Physics2D/RaycastResolver2D.cs +++ b/Engine.Physics2D/RaycastResolver2D.cs @@ -6,7 +6,7 @@ namespace Syntriax.Engine.Physics2D; public class RaycastResolver2D : IRaycastResolver2D { - private readonly ListPool lineCacheQueue = new(() => new(4)); + private readonly ListPool lineCacheQueue = new(initialListCapacity: 4); RaycastResult? IRaycastResolver2D.RaycastAgainst(T shape, Ray2D ray, float length) {