Skip to content

Game.Simulation.WaterPipeGraphReferencesSystem

Assembly: Game
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
WaterPipeGraphReferencesSystem is a small ECS system that keeps the graph references for water pipe nodes consistent when pipe-edge entities are processed (including deleted edges). It schedules a Burst-compiled IJobChunk (UpdateGraphReferencesJob) that iterates over WaterPipeEdge entities and removes references to each edge from the ConnectedFlowEdge dynamic buffers on its start and end nodes. The implementation uses generated type-handles and BufferLookup to operate safely inside a job and relies on CollectionUtils.RemoveValue to remove entries from node buffers.


Fields

  • private EntityQuery m_EdgeGroup
    This query selects entities that have a WaterPipeEdge component (and considers entities with the Deleted component via the query's Any clause). The system requires this query for update, so it will only run when matching entities exist.

  • private TypeHandle __TypeHandle
    A compiler-generated struct that stores the EntityTypeHandle, a read-only ComponentTypeHandle, and a writable BufferLookup. It is populated by __AssignHandles(ref SystemState) and used to build the job's handles before scheduling.

  • private struct UpdateGraphReferencesJob (nested, private)
    The IJobChunk implementation that performs the actual work in parallel over chunks. Marked with [BurstCompile]. It holds:

  • m_EntityType (EntityTypeHandle, read-only)
  • m_WaterPipeEdgeType (ComponentTypeHandle, read-only)
  • m_ConnectedFlowEdges (BufferLookup, mutable) The job iterates chunk entities, reads the WaterPipeEdge (start/end node indices) and removes the edge reference from the two node buffers.

  • private struct TypeHandle (nested, private)
    Compiler-generated helper type that exposes:

  • __Unity_Entities_Entity_TypeHandle
  • __Game_Simulation_WaterPipeEdge_RO_ComponentTypeHandle
  • __Game_Simulation_ConnectedFlowEdge_RW_BufferLookup
    It provides __AssignHandles(ref SystemState) to initialize those handles from the runtime SystemState.

Properties

  • This system exposes no public properties.

Constructors

  • public WaterPipeGraphReferencesSystem()
    Default constructor. Marked with [Preserve] to avoid stripping by code stripping tools. No custom initialization beyond what the base GameSystemBase constructor does.

Methods

  • protected override void OnCreate()
    Sets up the EntityQuery (m_EdgeGroup) to select entities that contain WaterPipeEdge (and includes Deleted in the Any list). Calls RequireForUpdate(m_EdgeGroup) so the system only runs when relevant entities exist.

  • protected override void OnUpdate()
    Builds an instance of UpdateGraphReferencesJob by obtaining the EntityTypeHandle, ComponentTypeHandle (read-only) and BufferLookup (writable) via the generated TypeHandle and InternalCompilerInterface. Schedules the job over m_EdgeGroup using JobChunkExtensions.Schedule and chains it with the system's Dependency.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated: currently creates and disposes an EntityQueryBuilder(Allocator.Temp). Present to satisfy compiler/code-generation expectations when building queries at compile-time.

  • protected override void OnCreateForCompiler()
    Compiler-time helper: calls __AssignQueries and __TypeHandle.__AssignHandles to ensure the generated handles are assigned when compiling with source-generation support.

  • private void TypeHandle.__AssignHandles(ref SystemState state)
    Assigns the EntityTypeHandle, the read-only ComponentTypeHandle, and the BufferLookup from the provided SystemState. Marked AggressiveInlining.

  • private void UpdateGraphReferencesJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Core job execution:

  • Reads the chunk's NativeArray and NativeArray.
  • For each element in the chunk, retrieves the ConnectedFlowEdge buffers for the edge's start and end nodes (via BufferLookup).
  • Calls CollectionUtils.RemoveValue(buffer, new ConnectedFlowEdge(edge)) for both start and end buffers to remove the edge reference. This is invoked through IJobChunk.Execute.

Notes and implementation details: - The job is Burst-compiled (BurstCompile attribute) for performance. - Removal uses CollectionUtils.RemoveValue which may move elements inside the buffer; work is done on the node buffers referenced by indices stored in each WaterPipeEdge (m_Start and m_End). - The system uses InternalCompilerInterface.Get* helpers to obtain handles from the compiler-generated TypeHandle fields before scheduling the job; this is part of the generated-system pattern used by source-generated DOTS systems.

Usage Example

This system is part of the simulation update flow and runs automatically when a WaterPipeEdge entity exists (or is marked Deleted). Example showing the effect:

// When you destroy or delete a water pipe edge entity:
entityManager.DestroyEntity(waterPipeEdgeEntity);

// On the next frame the WaterPipeGraphReferencesSystem will run.
// The scheduled UpdateGraphReferencesJob will:
//  - read the WaterPipeEdge component (m_Start/m_End nodes)
//  - remove a ConnectedFlowEdge entry referencing that edge from the
//    ConnectedFlowEdge dynamic buffers of both m_Start and m_End nodes.
//
// No manual call is required; the system is registered and runs as part of the ECS system update.

Additional tips: - Ensure ConnectedFlowEdge buffers exist on node entities referenced by m_Start/m_End. - If adding custom logic that modifies these buffers concurrently, respect job dependencies or use the BufferLookup/EntityCommandBuffer patterns to avoid races. - The system is designed to be lightweight and run in parallel across chunks; keep per-item work minimal to retain performance benefits.