Skip to content

Game.Zones.CellBlockJobs.BlockCellsJob

Assembly:
Namespace: Game.Zones

Type: struct

Base: Unity.Jobs.IJobParallelForDefer

Summary:
BlockCellsJob is a Burst-compiled parallel job used by the zoning system to update per-block cell data (Cell buffer) for placement/zoning in Cities: Skylines 2. For each block it: - Clears cell state into an "updating" default, - Iterates nearby net (road) geometry and area geometry via native quadtrees (NetIterator and AreaIterator) and marks cells as blocked / road-adjacent / sets height for elevated segments, - Computes a valid area (ValidArea) of the block after considering obstacles, - Writes back the updated Cell buffer and ValidArea component for the block entity.

This job relies on many ComponentLookup / BufferLookup and NativeQuadTree data structures and uses low-level math/geometry intersection checks to determine overlap between block grid cells and world geometry.


Fields

  • public NativeArray<CellCheckHelpers.SortedEntity> m_Blocks
    Contains the set of block entities to process (deferred length array used for scheduling). Each entry references a Block entity whose cell buffer will be updated.

  • public ComponentLookup<Block> m_BlockData
    Read-only ComponentLookup to access Block component data (size, origin, etc.) for each block entity.

  • public NativeQuadTree<Entity, QuadTreeBoundsXZ> m_NetSearchTree
    Read-only quadtree indexing network (edge/node) entities used to find nearby road geometry that can block cells.

  • public NativeQuadTree<AreaSearchItem, QuadTreeBoundsXZ> m_AreaSearchTree
    Read-only quadtree indexing area search items (areas / triangles) used to find nearby area geometry.

  • public ComponentLookup<Owner> m_OwnerData
    ComponentLookup to check and read Owner components (used when determining object geometry to ignore/block).

  • public ComponentLookup<Game.Objects.Transform> m_TransformData
    Lookup for object transform components; used to compute ignore quads / circles for small placed objects.

  • public ComponentLookup<EdgeGeometry> m_EdgeGeometryData
    Edge geometry data for net edges (segments) used when checking road overlap.

  • public ComponentLookup<StartNodeGeometry> m_StartNodeGeometryData
    Geometry data for start nodes used when checking road overlap.

  • public ComponentLookup<EndNodeGeometry> m_EndNodeGeometryData
    Geometry data for end nodes used when checking road overlap.

  • public ComponentLookup<Composition> m_CompositionData
    Composition lookup for network pieces (road/prefab composition indices).

  • public ComponentLookup<PrefabRef> m_PrefabRefData
    PrefabRef lookup used to find the prefab for owner objects and areas.

  • public ComponentLookup<NetCompositionData> m_PrefabCompositionData
    Lookup for prefab composition (per-net prefab) containing flags, height ranges, etc.

  • public ComponentLookup<RoadComposition> m_PrefabRoadCompositionData
    Optional lookup for road-specific composition (road flags like zoning enabled).

  • public ComponentLookup<AreaGeometryData> m_PrefabAreaGeometryData
    Lookup for area prefab geometry and flags (physical geometry, protected areas).

  • public ComponentLookup<ObjectGeometryData> m_PrefabObjectGeometryData
    Lookup for placed object geometry to generate ignore shapes (circle or quad) when marking block cells.

  • public ComponentLookup<Native> m_NativeData
    Lookup indicating native-owned areas; used to respect protected/physical area flags.

  • public BufferLookup<Game.Areas.Node> m_AreaNodes
    BufferLookup to read area nodes for area triangle reconstruction.

  • public BufferLookup<Triangle> m_AreaTriangles
    BufferLookup to read area triangles (indices into area nodes).

  • public BufferLookup<Cell> m_Cells
    BufferLookup to access the DynamicBuffer for each block entity. Marked with NativeDisableParallelForRestriction because job writes into buffers in parallel.

  • public ComponentLookup<ValidArea> m_ValidAreaData
    Lookup for writing the computed ValidArea component back to the block entity. Marked with NativeDisableParallelForRestriction.

Properties

  • None.
    This job is a plain struct with public fields used to pass data in; it does not expose properties.

Constructors

  • public BlockCellsJob()
    Default value-type constructor (job struct). All input fields must be assigned by the caller prior to scheduling.

Methods

  • public void Execute(int index)
    Main entry called per-block (parallel). For the block at m_Blocks[index].m_Entity it:
  • Reads the Block component and the Cell buffer,
  • Initializes a ValidArea with default extents,
  • Calculates block Bounds2 and Quad2 (world bounds/corners),
  • Clears block cell states via ClearBlockStatus,
  • Constructs and runs a NetIterator to scan net geometry from m_NetSearchTree and update cells (blocked / road direction / height for elevated),
  • Constructs and runs an AreaIterator to scan area geometry from m_AreaSearchTree and update cells (blocked),
  • Runs CleanBlockedCells to finalize blocked cells and compute a tighter ValidArea,
  • Writes ValidArea back to the block entity via m_ValidAreaData.

  • private static void ClearBlockStatus(Block blockData, DynamicBuffer<Cell> cells)
    Resets cell state for a block before processing. Leaves certain flags in an "Updating" base state and sets heights to short.MaxValue. Ensures first row is flagged roadside/updating and others are updating by default.

  • private static void CleanBlockedCells(Block blockData, ref ValidArea validAreaData, DynamicBuffer<Cell> cells)
    After net/area processing this finalizes blocked propagation, computes the final valid area region (min/max x/z that contains non-blocked cells) and marks adjacent road-left / road-right flags where relevant.

  • Nested: NetIterator (private struct)

  • Implements INativeQuadTreeIterator and IUnsafeQuadTreeIterator. Used by m_NetSearchTree.Iterate to visit nearby net entities (edges/nodes) and check segments against block cell quads.
  • Key methods: Intersect(QuadTreeBoundsXZ), Iterate(QuadTreeBoundsXZ, Entity), CheckSegment(Bezier4x3, Bezier4x3, NetCompositionData, RoadComposition, bool2), CheckOverlapX, CheckOverlapZ, SetHeightRange.
  • Responsibilities: compute ignore shapes for placed objects, check intersections with edge/node bezier segments, mark cells as blocked or set elevation heights, compute road direction flags (via ZoneUtils.GetRoadDirection) and respect road/roadside/prefab flags (e.g., tunnels/elevated/exclusive ground).

  • Nested: AreaIterator (private struct)

  • Implements INativeQuadTreeIterator and IUnsafeQuadTreeIterator. Used by m_AreaSearchTree.Iterate to visit area items and triangles.
  • Key methods: Intersect, Iterate, CheckOverlapX, CheckOverlapZ.
  • Responsibilities: reconstruct Triangle3 from area buffers and mark overlapping cells as blocked for areas flagged as physical/protected (and where allowed by native ownership).

Usage Example

// Example: prepare and schedule the job (simplified)
var job = new CellBlockJobs.BlockCellsJob
{
    m_Blocks = blocksNativeArray,                       // NativeArray<CellCheckHelpers.SortedEntity> (deferred/filled by caller)
    m_BlockData = blockLookup,                          // ComponentLookup<Block>
    m_NetSearchTree = netQuadTree,
    m_AreaSearchTree = areaQuadTree,
    m_OwnerData = ownerLookup,
    m_TransformData = transformLookup,
    m_EdgeGeometryData = edgeGeometryLookup,
    m_StartNodeGeometryData = startNodeGeometryLookup,
    m_EndNodeGeometryData = endNodeGeometryLookup,
    m_CompositionData = compositionLookup,
    m_PrefabRefData = prefabRefLookup,
    m_PrefabCompositionData = prefabCompositionLookup,
    m_PrefabRoadCompositionData = prefabRoadCompositionLookup,
    m_PrefabAreaGeometryData = prefabAreaGeometryLookup,
    m_PrefabObjectGeometryData = prefabObjectGeometryLookup,
    m_NativeData = nativeLookup,
    m_AreaNodes = areaNodesBufferLookup,
    m_AreaTriangles = areaTrianglesBufferLookup,
    m_Cells = cellsBufferLookup,                        // BufferLookup<Cell> (NativeDisableParallelForRestriction)
    m_ValidAreaData = validAreaLookup                   // ComponentLookup<ValidArea> (NativeDisableParallelForRestriction)
};

// Schedule: IJobParallelForDefer uses a deferred length array; use an appropriate batchSize and dependency.
// (Note: actual scheduling may require a special deferred length handle — this is a simplified illustrative call.)
JobHandle handle = job.Schedule(blocksNativeArray.Length, 64, dependency);

Notes and tips: - This job is low-level and interacts with native ECS ComponentLookup / BufferLookup and NativeQuadTree types — ensure lookups are correctly acquired (with read/write flags) and that buffers exist on the block entities. - The job is Burst-compiled and expects all fields to be blittable and safe for Burst. - Be careful with NativeDisableParallelForRestriction fields (m_Cells, m_ValidAreaData): these indicate manual guarantees about thread-safety; follow the original system's patterns when modifying. - The nested iterators contain the detailed geometry intersection logic — if you need to customize blocking behavior (e.g., ignore certain prefabs), inspect NetIterator and AreaIterator implementations.