Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
ColliderRegistry.cs
2
7public sealed class ColliderRegistry
8{
9 internal Gondwana.Scenes.SceneLayer? SceneLayer { get; set; }
10
20 public void QueryInstances(in Aabb area, int layerMask, int collidesWithMask,
21 List<ColliderInstance> results, ICollider? ignore = null)
22 {
23 results.Clear();
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))
29 {
30 if (ReferenceEquals(collider, ignore) || (collider.CollisionGroup & collidesWithMask) == 0 || (layerMask & collider.CollidesWith) == 0)
31 continue;
32 var bounds = collider.BoundsWorldPx;
33 if (!periodic)
34 {
35 if (area.Intersects(bounds)) results.Add(new(collider, bounds));
36 continue;
37 }
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)));
40 }
41 }
42
43 private readonly HashSet<ICollider> _static = new();
44 private readonly HashSet<ICollider> _dynamic = new();
45
49 public IEnumerable<ICollider> StaticColliders => _static;
50
54 public IEnumerable<ICollider> DynamicColliders => _dynamic;
55
62 public void Register(ICollider collider)
63 {
64 if (collider is null)
65 throw new ArgumentNullException(nameof(collider));
66
67 if (collider.IsStatic)
68 _static.Add(collider);
69 else
70 _dynamic.Add(collider);
71 }
72
78 public void Unregister(ICollider collider)
79 {
80 if (collider is null)
81 return;
82
83 if (collider.IsStatic)
84 _static.Remove(collider);
85 else
86 _dynamic.Remove(collider);
87 }
88
100 public void QueryAabb(
101 in Aabb area,
102 int layerMask,
103 int collidesWithMask,
104 List<ICollider> results,
105 ICollider? ignore = null)
106 {
107 var instances = new List<ColliderInstance>();
108 QueryInstances(area, layerMask, collidesWithMask, instances, ignore);
109 results.Clear();
110 foreach (var instance in instances)
111 if (!results.Contains(instance.Collider)) results.Add(instance.Collider);
112 }
113}
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...
Definition SceneLayer.cs:40
World-space axis-aligned collider used by the collision system.
Definition ICollider.cs:7
bool IsStatic
True for static, non-moving colliders (walls, tiles, etc.). False for dynamic objects (player,...
Definition ICollider.cs:18
Represents an axis-aligned bounding box (AABB) defined by its minimum and maximum coordinates along t...
Definition Aabb.cs:10