21 List<ColliderInstance> results,
ICollider? ignore =
null)
24 var layer = SceneLayer;
25 var periodic = layer is not
null && (layer.WrapHorizontally || layer.WrapVertically);
26 var period = periodic ? layer!.GetPeriod() :
default;
27 var query =
new System.Drawing.RectangleF(area.MinX, area.MinY, area.Width, area.Height);
28 foreach (var collider
in _static.Concat(_dynamic))
30 if (ReferenceEquals(collider, ignore) || (collider.CollisionGroup & collidesWithMask) == 0 || (layerMask & collider.CollidesWith) == 0)
32 var bounds = collider.BoundsWorldPx;
35 if (area.Intersects(bounds)) results.Add(
new(collider, bounds));
38 foreach (var offset
in period.Offsets(
new(bounds.MinX, bounds.MinY, bounds.Width, bounds.Height), query))
39 results.Add(
new(collider,
new(bounds.MinX + offset.X, bounds.MinY + offset.Y, bounds.MaxX + offset.X, bounds.MaxY + offset.Y)));
43 private readonly HashSet<ICollider> _static =
new();
44 private readonly HashSet<ICollider> _dynamic =
new();
65 throw new ArgumentNullException(nameof(collider));
68 _static.Add(collider);
70 _dynamic.Add(collider);
84 _static.Remove(collider);
86 _dynamic.Remove(collider);
103 int collidesWithMask,
104 List<ICollider> results,
107 var instances =
new List<ColliderInstance>();
108 QueryInstances(area, layerMask, collidesWithMask, instances, ignore);
110 foreach (var instance
in instances)
111 if (!results.Contains(instance.Collider)) results.Add(instance.Collider);
Manages registration and querying of colliders, separating them into static and dynamic collections f...
void QueryInstances(in Aabb area, int layerMask, int collidesWithMask, List< ColliderInstance > results, ICollider? ignore=null)
Queries canonical colliders with translated bounds for every overlapping wrapped instance....
void Unregister(ICollider collider)
Unregisters a collider from the registry, removing it from either the static or dynamic collection ba...
IEnumerable< ICollider > DynamicColliders
Gets the collection of dynamic colliders registered in this registry.
void QueryAabb(in Aabb area, int layerMask, int collidesWithMask, List< ICollider > results, ICollider? ignore=null)
Broad-phase query: returns colliders overlapping the given AABB that also match the provided layer ma...
void Register(ICollider collider)
Registers a collider with the registry. The collider is added to either the static or dynamic collect...
IEnumerable< ICollider > StaticColliders
Gets the collection of static colliders registered in this registry.
Represents a single layer within a Scene, containing a grid of tiles and supporting various coordinat...
World-space axis-aligned collider used by the collision system.
bool IsStatic
True for static, non-moving colliders (walls, tiles, etc.). False for dynamic objects (player,...
Represents an axis-aligned bounding box (AABB) defined by its minimum and maximum coordinates along t...