Struct SpatialGridConfig
Immutable configuration for the engine-wide spatial grid. Set once via ConfigureSpatialGrid(SpatialGridConfig) before archetypes are initialized.
public readonly struct SpatialGridConfig
- Inherited Members
Remarks
All spatial archetypes share a single coarse grid with one cell size (Decision Q1 in claude/design/Spatial/SpatialTiers/01-spatial-clusters.md).
Per-archetype differences are expressed at the system level via tier filters, not at the grid level.
Grid dimensions are derived from (WorldMax - WorldMin) / CellSize and rounded up to the nearest power of two when Morton cell keys are enabled — this keeps the Morton decode well-defined without needing a per-axis width.
Constructors
SpatialGridConfig(Vector2, Vector2, float, float)
Build a grid configuration and precompute the derived cell dimensions. World bounds are half-open: worldMin is inclusive,
worldMax is exclusive.
public SpatialGridConfig(Vector2 worldMin, Vector2 worldMax, float cellSize, float migrationHysteresisRatio = 0.05)
Parameters
worldMinVector2World-space minimum corner (inclusive).
worldMaxVector2World-space maximum corner (exclusive); must be strictly greater than
worldMinon both axes.cellSizefloatCell size in world units; must be > 0.
migrationHysteresisRatiofloatPer-axis dead zone as a fraction of cell size (default 0.05). Reserved for the Phase 3 migration path.
Exceptions
- ArgumentOutOfRangeException
cellSizeis not positive, or the derived per-axis key-space dimension exceeds the 32 768 limit of the 32-bit Morton encoding.- ArgumentException
worldMaxis not strictly greater thanworldMinon both axes.
Fields
CellCount
Total number of descriptor slots. Equals KeySpaceDim² for Morton keys.
public readonly int CellCount
Field Value
CellSize
Size of a single grid cell, in world units. Must be > 0.
public readonly float CellSize
Field Value
GridHeight
Number of real cells along the Y axis.
public readonly int GridHeight
Field Value
GridWidth
Number of real cells along the X axis — derived from (WorldMax.X - WorldMin.X) / CellSize, rounded up. This is the count of cells entities can actually occupy.
public readonly int GridWidth
Field Value
InverseCellSize
Precomputed 1 / CellSize.
public readonly float InverseCellSize
Field Value
KeySpaceDim
Cell key space size per axis. Equal to GridWidth/GridHeight for row-major, or padded to the next power of two (matching the larger of the two) for Morton. Used only for descriptor array sizing — not for world-to-cell clamping.
public readonly int KeySpaceDim
Field Value
MigrationHysteresisRatio
Fractional dead zone applied per axis during entity migration, as a fraction of cell size. Default 0.05 (5 % of cell size). Unused in Phase 1+2 — reserved for the Phase 3 migration path.
public readonly float MigrationHysteresisRatio
Field Value
WorldMax
World-space maximum corner (exclusive — the grid excludes the max edge).
public readonly Vector2 WorldMax
Field Value
WorldMin
World-space minimum corner (inclusive).
public readonly Vector2 WorldMin