Skip to content

PhysicsLayerRegistry Class

Maps string layer names to Box2D layer indices (0–63). Register names at startup via Register(string, int) before building any physics bodies, then use GetLayer(string) and GetMask(string) to build PhysicsQueryFilter instances and assign Brine2D.ECS.Components.PhysicsBodyComponent.Layer values by name.

public sealed class PhysicsLayerRegistry

Inheritance System.Object → PhysicsLayerRegistry

Remarks

This class is intentionally mutable during the registration phase and then frozen for runtime lookups. Call Freeze() once all layers are registered (typically at the end of your DI/startup configuration). After freezing, Register(string, int) throws.

Layer indices 0–63 map directly to Box2D category/mask bits: a body on layer N has categoryBits = 1UL << N and a query for layer N has CollisionMask = 1UL << N.

Properties
IsFrozen Whether Freeze() has been called. Once frozen, Register(string, int) throws.
Methods
ForLayer(string) Returns a PhysicsQueryFilter that hits shapes on the given named layer.
ForLayers(ReadOnlySpan<string>) Returns a PhysicsQueryFilter that hits shapes on any of the given named layers.
Freeze() Freezes the registry. After this call Register(string, int) throws and all lookups switch to a lock-free frozen dictionary for maximum read performance.
GetAllLayers() Returns all registered layer name → index pairs.
GetLayer(string) Returns the layer index for the given name.
GetMask(string) Returns the category/collision bit mask for the given layer name. Equivalent to 1UL << GetLayer(name).
GetMask(ReadOnlySpan<string>) Returns the combined mask for multiple named layers. Equivalent to OR-ing GetMask(string) for each name.
Register(string, int) Registers a named layer at the given index (0–63).
SolidLayer(string) Returns a PhysicsQueryFilter that hits solid (non-sensor) shapes on the given named layer.
SolidLayers(ReadOnlySpan<string>) Returns a PhysicsQueryFilter that hits solid shapes on any of the given named layers.
TryGetLayer(string, int) Tries to get the layer index for the given name. Returns false if not registered.