refactor: list pool initial count and capacity parameters added
This commit is contained in:
parent
f56d6a7fc8
commit
30ccab1b93
@ -31,10 +31,10 @@ public class ListPool<T> : IPool<List<T>>
|
|||||||
OnReturned?.Invoke(this, list);
|
OnReturned?.Invoke(this, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListPool(Func<List<T>> generator, int initialCapacity = 1)
|
public ListPool(int initialListCount = 1, int initialListCapacity = 32)
|
||||||
{
|
{
|
||||||
this.generator = generator;
|
generator = () => new(initialListCapacity);
|
||||||
for (int i = 0; i < initialCapacity; i++)
|
for (int i = 0; i < initialListCount; i++)
|
||||||
queue.Enqueue(generator());
|
queue.Enqueue(generator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@ public class PhysicsEngine2D : Behaviour, IPreUpdate, IPhysicsEngine2D
|
|||||||
protected BehaviourCollector<IRigidBody2D> rigidBodyCollector = new();
|
protected BehaviourCollector<IRigidBody2D> rigidBodyCollector = new();
|
||||||
protected BehaviourCollector<ICollider2D> colliderCollector = new();
|
protected BehaviourCollector<ICollider2D> colliderCollector = new();
|
||||||
|
|
||||||
private readonly ListPool<ICollider2D> colliderPool = new(() => new(32));
|
private readonly ListPool<ICollider2D> colliderPool = new();
|
||||||
private readonly ListPool<IPrePhysicsUpdate> prePhysicsUpdatePool = new(() => new(32));
|
private readonly ListPool<IPrePhysicsUpdate> prePhysicsUpdatePool = new();
|
||||||
private readonly ListPool<IPhysicsUpdate> physicsUpdatePool = new(() => new(32));
|
private readonly ListPool<IPhysicsUpdate> physicsUpdatePool = new();
|
||||||
private readonly ListPool<IPhysicsIteration> physicsIterationPool = new(() => new(32));
|
private readonly ListPool<IPhysicsIteration> physicsIterationPool = new();
|
||||||
private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new(() => new(32));
|
private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new();
|
||||||
|
|
||||||
public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; }
|
public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; }
|
||||||
public float IterationPeriod { get => _iterationPeriod; set => _iterationPeriod = value.Max(0.0001f); }
|
public float IterationPeriod { get => _iterationPeriod; set => _iterationPeriod = value.Max(0.0001f); }
|
||||||
|
@ -21,11 +21,11 @@ public class PhysicsEngine2DStandalone : IPhysicsEngine2D
|
|||||||
private readonly ICollisionResolver2D collisionResolver = null!;
|
private readonly ICollisionResolver2D collisionResolver = null!;
|
||||||
private readonly IRaycastResolver2D raycastResolver = null!;
|
private readonly IRaycastResolver2D raycastResolver = null!;
|
||||||
|
|
||||||
private readonly ListPool<ICollider2D> colliderPool = new(() => new(32));
|
private readonly ListPool<ICollider2D> colliderPool = new();
|
||||||
private readonly ListPool<IPrePhysicsUpdate> prePhysicsUpdatePool = new(() => new(32));
|
private readonly ListPool<IPrePhysicsUpdate> prePhysicsUpdatePool = new();
|
||||||
private readonly ListPool<IPhysicsUpdate> physicsUpdatePool = new(() => new(32));
|
private readonly ListPool<IPhysicsUpdate> physicsUpdatePool = new();
|
||||||
private readonly ListPool<IPhysicsIteration> physicsIterationPool = new(() => new(32));
|
private readonly ListPool<IPhysicsIteration> physicsIterationPool = new();
|
||||||
private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new(() => new(32));
|
private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new();
|
||||||
|
|
||||||
public int IterationPerStep { get => _iterationCount; set => _iterationCount = value < 1 ? 1 : value; }
|
public int IterationPerStep { get => _iterationCount; set => _iterationCount = value < 1 ? 1 : value; }
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ namespace Syntriax.Engine.Physics2D;
|
|||||||
|
|
||||||
public class RaycastResolver2D : IRaycastResolver2D
|
public class RaycastResolver2D : IRaycastResolver2D
|
||||||
{
|
{
|
||||||
private readonly ListPool<Line2D> lineCacheQueue = new(() => new(4));
|
private readonly ListPool<Line2D> lineCacheQueue = new(initialListCapacity: 4);
|
||||||
|
|
||||||
RaycastResult? IRaycastResolver2D.RaycastAgainst<T>(T shape, Ray2D ray, float length)
|
RaycastResult? IRaycastResolver2D.RaycastAgainst<T>(T shape, Ray2D ray, float length)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user