feat: added list pools

This commit is contained in:
2025-06-09 18:28:54 +03:00
parent 3f914fe46f
commit 152b0e93db
3 changed files with 58 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ namespace Syntriax.Engine.Physics2D;
public class RaycastResolver2D : IRaycastResolver2D
{
private readonly Pool<List<Line2D>> lineCacheQueue = new(() => new List<Line2D>(4));
private readonly ListPool<Line2D> lineCacheQueue = new(() => new(4));
RaycastResult? IRaycastResolver2D.RaycastAgainst<T>(T shape, Ray2D ray, float length)
{
@@ -21,7 +21,6 @@ public class RaycastResolver2D : IRaycastResolver2D
public RaycastResult? RaycastAgainstShape(IShapeCollider2D shapeCollider, Ray2D ray, float length)
{
List<Line2D> line2Ds = lineCacheQueue.Get();
line2Ds.Clear();
RaycastResult? raycastResult = null;
float closestRaycastResultSquared = float.MaxValue;
@@ -60,7 +59,6 @@ public class RaycastResolver2D : IRaycastResolver2D
}
}
line2Ds.Clear();
lineCacheQueue.Return(line2Ds);
return raycastResult;