Game.Tools.GenerateZonesSystem
Assembly: Game
Namespace: Game.Tools
Type: public class (CompilerGenerated)
Base: GameSystemBase
Summary:
GenerateZonesSystem is an ECS system responsible for turning zoning creation definitions (CreationDefinition + Zoning) into actual zone-block entities. It detects user zoning actions (flood-fill, paint, marquee), queries the zone search tree to find affected blocks/cells, accumulates zone changes into native collections, and then spawns ZoneBlock entities copying cell data and applying zone changes. The system uses two Burst-compiled jobs:
- FillBlocksListJob (IJobChunk) — finds and collects which cells on which blocks should be zoned (supports Marquee, Paint, FloodFill strategies and contains iterators used with the NativeQuadTree search tree).
- CreateBlocksJob (IJobParallelForDefer) — creates new zone-block entities (using ZoneBlockData archetype), copies buffers, marks selected/zoned cells, hides original blocks and attaches Temp references.
The system integrates with: - SearchSystem (reads native search tree), - ModificationBarrier1 (to create entities via a parallel command buffer), - Unity Jobs / Burst for performance, and uses NativeParallelMultiHashMap / NativeList for intermediate data.
Fields
-
private SearchSystem m_ZoneSearchSystem
Used to obtain the NativeQuadTreesearch tree readers for locating blocks and cells matching a position/shape when performing zoning operations. -
private ModificationBarrier1 m_ModificationBarrier
Barrier system used to obtain an EntityCommandBuffer.ParallelWriter to safely create zone-block entities and modify components from jobs. -
private EntityQuery m_DefinitionQuery
Query selecting entities with CreationDefinition, Zoning and Updated components; the system requires this query to run (RequireForUpdate). -
private TypeHandle __TypeHandle
Internal struct that stores ComponentTypeHandle / ComponentLookup / BufferLookup instances for the component types the jobs need (CreationDefinition, Zoning, Block, ZoneData, Cell, PrefabRef, ZoneBlockData). Assigned in OnCreateForCompiler.
Properties
- (none)
This system does not expose public properties.
Constructors
public GenerateZonesSystem()
Default (parameterless) constructor. The system is CompilerGenerated and relies on ECS lifecycle methods (OnCreate / OnUpdate) for initialization and operation.
Methods
-
protected override void OnCreate()
: System.Void
Initializes system references: gets or creates the SearchSystem and ModificationBarrier1 instances, constructs the EntityQuery that matches CreationDefinition + Zoning + Updated, and calls RequireForUpdate(m_DefinitionQuery) so the system only runs when there are relevant definitions to process. -
protected override void OnUpdate()
: System.Void
Main update method. Allocates temporary native collections (NativeParallelMultiHashMapzonedCells and NativeList zonedBlocks), configures and schedules: - FillBlocksListJob (IJobChunk, Burst) — populates zonedCells / zonedBlocks by iterating matching CreationDefinition+Zoning chunks and performing Marquee / Paint / FloodFill logic using a NativeQuadTree
search tree. This job uses several nested iterators: - MarqueeIterator — intersects a marquee quad with block quads and per-cell corners to mark cells to zone.
- BaseLineIterator — iterates along a line segment to collect base cells intersecting the line.
- FloodFillIterator — performs a flood-fill expansion across neighboring cells/blocks, adding eligible cells.
-
CreateBlocksJob (IJobParallelForDefer, Burst) — runs after FillBlocksListJob; for each affected block entity it:
- Creates a new entity using the ZoneBlockData archetype,
- Copies PrefabRef, Block component and the Cell buffer,
- Adds a Temp component referencing the original block entity,
- Adds Hidden and BatchesUpdated to the original block,
- Sets Selected flag and assigns Zone types for zoned cells. The method combines dependencies, disposes temporary collections with job dependencies, registers the search tree reader (m_ZoneSearchSystem.AddSearchTreeReader(jobHandle)), and tells the modification barrier about the CreateBlocksJob (m_ModificationBarrier.AddJobHandleForProducer(jobHandle2)). Finally, it sets base.Dependency to the CreateBlocksJob handle.
-
protected override void OnCreateForCompiler()
: System.Void
Compiler helper: calls __AssignQueries and assigns the handles in __TypeHandle via __AssignHandles(ref base.CheckedStateRef). Used to prepare component lookups/handles for job scheduling. -
private void __AssignQueries(ref SystemState state)
: System.Void
Internal method used by the compiler-generated setup. In this file it constructs an EntityQueryBuilder (no persistent query data here) and disposes it; used in OnCreateForCompiler. -
private struct TypeHandle
Nested helper struct that contains component type/lookups used by the jobs. Its __AssignHandles(ref SystemState) method fills ComponentTypeHandle / ComponentLookup / BufferLookup fields from the SystemState. -
Nested job types and iterators:
FillBlocksListJob
(BurstCompile, IJobChunk) — collects cells to zone based on CreationDefinition/Zoning; includes nested MarqueeIterator, BaseLineIterator, FloodFillIterator which are used with the NativeQuadTree search tree iteration.CreateBlocksJob
(BurstCompile, IJobParallelForDefer) — constructs zone-block entities in parallel from the collected lists; copies buffers and applies zone changes.-
The nested iterators use ComponentLookup
, BufferLookup , and the search tree to efficiently find and evaluate blocks/cells. | -
Other private helpers inside FillBlocksListJob:
- AddCells(Line2.Segment line, NativeList
baseCells) — collects base cells intersecting a line segment via BaseLineIterator. - PackToInt(int2 cellIndex) — encodes an int2 cell index into a single int used by NativeParallelHashSet for flood-fill bookkeeping.
- MarqueeBlocks / PaintBlocks / FloodFillBlocks — encapsulate logic for each zoning mode and populate m_ZonedCells / m_ZonedBlocks.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_ZoneSearchSystem = base.World.GetOrCreateSystemManaged<SearchSystem>();
m_ModificationBarrier = base.World.GetOrCreateSystemManaged<ModificationBarrier1>();
m_DefinitionQuery = GetEntityQuery(
ComponentType.ReadOnly<CreationDefinition>(),
ComponentType.ReadOnly<Zoning>(),
ComponentType.ReadOnly<Updated>());
RequireForUpdate(m_DefinitionQuery);
}
Notes and tips: - The system is designed to be high-performance: jobs are Burst-compiled, use native collections, and integrate with the SearchSystem to minimize work. - When extending or modifying this system, ensure correct lifetime management for temporary Native containers and that any added jobs are properly registered with the ModificationBarrier / search tree readers to maintain synchronization. - The jobs assume specific component layouts (Block, Cell, PrefabRef, ZoneBlockData). When creating new zone-related archetypes or components, keep compatibility in mind for CreateBlocksJob.