SpatialGrid class final

A uniform grid over the XZ plane, holding integer handles.

Why a grid

A corridor level spreads thousands of brushes thinly and evenly, which is the case a uniform grid handles best and a tree handles worst: no rebalancing, no traversal, and a query touches a fixed handful of cells whatever the level's size. It is also the case the engine's own BVH measured badly on, and that measurement is in ARCHITECTURE.md §2.

Two dimensions rather than three, because a dungeon is wide and short. Adding Y would multiply the cell count by the number of floors — usually one — while splitting almost nothing.

Why the stamps

A collider spanning several cells appears in each of them, so a naive walk reports it more than once. Callers that take a minimum do not care, but callers that accumulate — collecting overlaps, summing depenetration — very much do. A monotonically increasing query counter and one stamp per handle makes the deduplication O(1) per visit instead of a set allocated per query.

Constructors

SpatialGrid({double cellSize = 4.0})

Properties

cellCount int
no setter
cellSize double
Side of a cell, in metres. About two corridor widths, so a query for a player-sized box touches one or two cells.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Drops everything, cells included.
clearEntries() → void
Empties every cell but keeps the lists, for a grid rebuilt each step.
forEachAlongRay(Vector3 origin, Vector3 direction, double maxDistance, void visit(int)) → void
Visits each handle in a cell the ray passes through, once, near to far.
forEachInBox(Vector3 min, Vector3 max, void visit(int)) → void
Visits each handle whose cell meets the region, once.
insert(int handle, Aabb3 bounds) → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited