Struct SpatialGridAccessor
Game-facing read/write accessor for the engine's Typhon.Engine.Internals.SpatialGrid (issue #232). Exposed on SpatialGrid so system callbacks can assign cell tiers, query cell coordinates, and use multi-observer helpers (SetCellTierMin(int, int, SimTier), ResetAllTiers(SimTier), SetTierInAABB(float, float, float, float, SimTier)).
public readonly struct SpatialGridAccessor
- Inherited Members
Remarks
8-byte readonly struct (one managed reference). The design doc specifies ref struct but TickContext is a
regular struct — ref structs cannot be fields of non-ref structs. Using readonly struct with a single reference field achieves the
same zero-allocation, thin-wrapper semantics without the composability constraint.
All methods delegate to the internal Typhon.Engine.Internals.SpatialGrid. No logic duplication.
Properties
CellCount
Total number of cells in the grid.
public int CellCount { get; }
Property Value
CellSize
Cell size in world units.
public float CellSize { get; }
Property Value
GridHeight
Grid height in cells.
public int GridHeight { get; }
Property Value
GridWidth
Grid width in cells.
public int GridWidth { get; }
Property Value
IsValid
True when the engine has a configured spatial grid. False when no grid was set up (non-spatial game) or during shutdown.
public bool IsValid { get; }
Property Value
Methods
ComputeCellKey(int, int)
Compute the flat cell key for the given cell coordinates. Accounts for Morton encoding when enabled.
public int ComputeCellKey(int cellX, int cellY)
Parameters
Returns
GetCellCoords(int)
Convert a cell key back to grid coordinates (x, y).
public (int x, int y) GetCellCoords(int cellKey)
Parameters
cellKeyint
Returns
ResetAllTiers(SimTier)
Bulk-set all cells to the specified tier. Typically called at the start of TierAssignment.
public void ResetAllTiers(SimTier tier)
Parameters
tierSimTier
SetCellTier(int, int, SimTier)
Set a cell's tier by grid coordinates. Requires a single-bit SimTier flag.
public void SetCellTier(int cellX, int cellY, SimTier tier)
Parameters
SetCellTierMin(int, int, SimTier)
Set a cell's tier using min (promote-only) semantics (Q7). If the cell already has a higher-priority tier (lower flag value),
the call is a no-op. Enables multi-observer union: ResetAllTiers(Tier3) then SetCellTierMin per observer.
public void SetCellTierMin(int cellX, int cellY, SimTier tier)
Parameters
SetTierInAABB(float, float, float, float, SimTier)
Set tiers for all cells overlapping a world-space AABB, using min (promote-only) semantics.
public void SetTierInAABB(float minX, float minY, float maxX, float maxY, SimTier tier)
Parameters
WorldToCell(float, float)
Convert a world-space 2D point to a grid cell key. Points outside bounds are clamped.
public int WorldToCell(float worldX, float worldY)