Table of Contents

Struct SpatialGridAccessor

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

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

int

CellSize

Cell size in world units.

public float CellSize { get; }

Property Value

float

GridHeight

Grid height in cells.

public int GridHeight { get; }

Property Value

int

GridWidth

Grid width in cells.

public int GridWidth { get; }

Property Value

int

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

bool

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

cellX int
cellY int

Returns

int

GetCellCoords(int)

Convert a cell key back to grid coordinates (x, y).

public (int x, int y) GetCellCoords(int cellKey)

Parameters

cellKey int

Returns

(int clusterChunkId, int slotIndex)

ResetAllTiers(SimTier)

Bulk-set all cells to the specified tier. Typically called at the start of TierAssignment.

public void ResetAllTiers(SimTier tier)

Parameters

tier SimTier

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

cellX int
cellY int
tier SimTier

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

cellX int
cellY int
tier SimTier

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

minX float
minY float
maxX float
maxY float
tier SimTier

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)

Parameters

worldX float
worldY float

Returns

int