Gondwana Game Engine Development (master) - 2.7.0
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(
21 in Aabb area,
22 int layerMask,
23 int collidesWithMask,
24 List<ColliderInstance> results,
25 ICollider? ignore = null)
26 {
27 results.Clear();
28 var layer = SceneLayer;
29 var periodic = layer is not null && (layer.WrapHorizontally || layer.WrapVertically);
30 var period = periodic ? layer!.GetPeriod() : default;
31
32 var query = new System.Drawing.RectangleF(
33 area.MinX,
34 area.MinY,
35 area.Width,
36 area.Height);
37
38 foreach (var collider in _static.Concat(_dynamic))
39 {
40 if (ReferenceEquals(collider, ignore) || (collider.CollisionGroup & collidesWithMask) == 0 ||
41 (layerMask & collider.CollidesWith) == 0)
42 continue;
43
44 var bounds = collider.BoundsWorldPx;
45
46 if (!periodic)
47 {
48 if (area.Intersects(bounds))
49 results.Add(new(collider, bounds));
50
51 continue;
52 }
53
54 foreach (var offset in period.Offsets(
55 new(
56 bounds.MinX,
57 bounds.MinY,
58 bounds.Width,
59 bounds.Height),
60 query))
61 results.Add(
62 new(
63 collider,
64 new(
65 bounds.MinX + offset.X,
66 bounds.MinY + offset.Y,
67 bounds.MaxX + offset.X,
68 bounds.MaxY + offset.Y)));
69 }
70 }
71
72 private readonly HashSet<ICollider> _static = new();
73 private readonly HashSet<ICollider> _dynamic = new();
74
78 public IEnumerable<ICollider> StaticColliders => _static;
79
83 public IEnumerable<ICollider> DynamicColliders => _dynamic;
84
91 public void Register(ICollider collider)
92 {
93 if (collider is null)
94 throw new ArgumentNullException(nameof(collider));
95
96 if (collider.IsStatic)
97 _static.Add(collider);
98 else
99 _dynamic.Add(collider);
100 }
101
107 public void Unregister(ICollider collider)
108 {
109 if (collider is null)
110 return;
111
112 if (collider.IsStatic)
113 _static.Remove(collider);
114 else
115 _dynamic.Remove(collider);
116 }
117
129 public void QueryAabb(
130 in Aabb area,
131 int layerMask,
132 int collidesWithMask,
133 List<ICollider> results,
134 ICollider? ignore = null)
135 {
136 var instances = new List<ColliderInstance>();
137
139 area,
140 layerMask,
141 collidesWithMask,
142 instances,
143 ignore);
144
145 results.Clear();
146
147 foreach (var instance in instances)
148 if (!results.Contains(instance.Collider))
149 results.Add(instance.Collider);
150 }
151}
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