Skip to content

Game.Simulation.WaterPipeGraphDeleteSystem

Assembly: Game (assembly that contains the simulation systems; often Assembly-CSharp or the game's core assembly)
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
System responsible for cleaning up the water-pipe flow graph when pipe-related entities are deleted or when valve nodes are updated. It detects entities that carry WaterPipeNodeConnection, WaterPipeValveConnection or WaterPipeBuildingConnection components that are marked Deleted, and schedules parallel IJobChunk jobs to remove the corresponding flow graph nodes/edges using WaterPipeGraphUtils. It also handles valve node updates by removing the valve connection component and deleting the corresponding flow node. The system uses a ModificationBarrier (ModificationBarrier1) to produce an EntityCommandBuffer.ParallelWriter so removals and structural changes are performed safely from jobs. Both jobs are Burst-compiled and scheduled in parallel where possible.


Fields

  • private ModificationBarrier1 m_ModificationBarrier
    Holds a reference to the modification barrier system used to create an EntityCommandBuffer.ParallelWriter for safe structural changes from jobs.

  • private EntityQuery m_DeletedConnectionQuery
    EntityQuery that matches entities that are marked Deleted and that have at least one of: WaterPipeNodeConnection, WaterPipeValveConnection, or WaterPipeBuildingConnection (and are not Temp). When non-empty it triggers scheduling of DeleteConnectionsJob.

  • private EntityQuery m_DeletedValveNodeQuery
    EntityQuery that matches entities having WaterPipeValveConnection, Node and Updated, and that do NOT have Owner, Temp or Deleted. When non-empty it triggers scheduling of DeleteValveNodesJob to remove valve nodes and their connections.

  • private TypeHandle __TypeHandle
    Internal struct that stores the component type handles (ComponentTypeHandle, ComponentLookup, BufferLookup, EntityTypeHandle) used by the jobs. It is initialized via __AssignHandles(ref SystemState) to cache handles for scheduling.

Properties

  • None (the system exposes no public properties)

Constructors

  • public WaterPipeGraphDeleteSystem()
    Default constructor. The real initialization is performed in OnCreate / OnCreateForCompiler. The constructor is marked with [Preserve] in the source to avoid stripping.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains the ModificationBarrier1 system, constructs the two EntityQuery objects (m_DeletedConnectionQuery and m_DeletedValveNodeQuery) with the appropriate All/Any/None component constraints, and calls RequireAnyForUpdate to ensure the system only updates when at least one of these queries matches.

  • protected override void OnUpdate()
    If m_DeletedConnectionQuery is non-empty, schedules DeleteConnectionsJob as a parallel IJobChunk. If m_DeletedValveNodeQuery is non-empty, schedules DeleteValveNodesJob similarly. Both jobs receive component handles / lookups and a ParallelWriter EntityCommandBuffer from m_ModificationBarrier. The system registers job handles with the modification barrier and combines job dependencies into base.Dependency.

  • protected override void OnCreateForCompiler()
    Helper used by generated/compiled code to assign queries and cache type handles (__AssignQueries and __TypeHandle.__AssignHandles). Called to set up state used by the compiled system.

  • private void __AssignQueries(ref SystemState state)
    Internal placeholder used by compiler-generated code; in the source it currently only instantiates and disposes an EntityQueryBuilder (no-op in this listing), but is present to satisfy compiled system requirements.

Nested job types (important to know their behavior):

  • DeleteConnectionsJob (private struct, BurstCompile, IJobChunk)
  • Reads WaterPipeNodeConnection, WaterPipeValveConnection, WaterPipeBuildingConnection components from chunks, plus read-only lookups for WaterPipeEdge and buffers of ConnectedFlowEdge.
  • For each WaterPipeNodeConnection: if m_WaterPipeNode != Entity.Null then calls WaterPipeGraphUtils.DeleteFlowNode with the ParallelWriter and flow connection buffer lookup; otherwise logs a warning about a null WaterPipeNode.
  • For each WaterPipeValveConnection: calls WaterPipeGraphUtils.DeleteFlowNode for the valve node.
  • For each WaterPipeBuildingConnection: calls WaterPipeGraphUtils.DeleteBuildingNodes to remove building-related flow nodes and connected edges.
  • Uses m_CommandBuffer (EntityCommandBuffer.ParallelWriter) to schedule structural changes.

  • DeleteValveNodesJob (private struct, BurstCompile, IJobChunk)

  • Reads entity array and WaterPipeValveConnection components from chunk and a BufferLookup.
  • Removes the WaterPipeValveConnection component from matching entities via m_CommandBuffer.RemoveComponent.
  • For each WaterPipeValveConnection item, calls WaterPipeGraphUtils.DeleteFlowNode to remove the corresponding valve flow node via the command buffer.

  • TypeHandle.__AssignHandles(ref SystemState state)

  • Populates cached ComponentTypeHandle/ComponentLookup/BufferLookup/EntityTypeHandle instances from the provided SystemState for use when scheduling jobs.

Notes on job scheduling and safety: - Both jobs are scheduled via JobChunkExtensions.ScheduleParallel with the respective EntityQuery and the system's current dependency. - The system adds job handles to the ModificationBarrier to ensure the barrier waits for producers before playback of its command buffer. - Many of the component handles and lookups are obtained via InternalCompilerInterface.GetComponentTypeHandle / GetComponentLookup / GetBufferLookup according to the cached TypeHandle values.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Get the modification barrier to create an EntityCommandBuffer.ParallelWriter
    m_ModificationBarrier = base.World.GetOrCreateSystemManaged<ModificationBarrier1>();

    // Query for deleted pipe-related connections (nodes, valves, buildings)
    m_DeletedConnectionQuery = GetEntityQuery(new EntityQueryDesc
    {
        All = new ComponentType[1] { ComponentType.ReadOnly<Deleted>() },
        Any = new ComponentType[3]
        {
            ComponentType.ReadOnly<WaterPipeNodeConnection>(),
            ComponentType.ReadOnly<WaterPipeValveConnection>(),
            ComponentType.ReadOnly<WaterPipeBuildingConnection>()
        },
        None = new ComponentType[1] { ComponentType.ReadOnly<Temp>() }
    });

    // Query for valve nodes that were updated and need valve connection removal
    m_DeletedValveNodeQuery = GetEntityQuery(new EntityQueryDesc
    {
        All = new ComponentType[3]
        {
            ComponentType.ReadOnly<WaterPipeValveConnection>(),
            ComponentType.ReadOnly<Node>(),
            ComponentType.ReadOnly<Updated>()
        },
        None = new ComponentType[3]
        {
            ComponentType.ReadOnly<Owner>(),
            ComponentType.ReadOnly<Temp>(),
            ComponentType.ReadOnly<Deleted>()
        }
    });

    RequireAnyForUpdate(m_DeletedConnectionQuery, m_DeletedValveNodeQuery);
}

If you need the exact signatures or descriptions for WaterPipeNodeConnection, WaterPipeValveConnection, WaterPipeBuildingConnection, ConnectedFlowEdge, WaterPipeEdge or the helper methods in WaterPipeGraphUtils (DeleteFlowNode / DeleteBuildingNodes), tell me and I can add a focused reference section for those types and methods.