Skip to content

Game.ElectricityGraphDeleteSystem

Assembly:
Game

Namespace:
Game.Simulation

Type:
class

Base:
GameSystemBase

Summary:
ElectricityGraphDeleteSystem is a ECS system responsible for cleaning up electricity graph data when connection-related entities are deleted or valve nodes require removal. It watches for entities marked Deleted that also have any of ElectricityNodeConnection, ElectricityValveConnection or ElectricityBuildingConnection, and for valve entities that are Node + Updated but lack an Owner (and are not Temp or Deleted). When triggered it schedules two parallel IJobChunk jobs:

  • DeleteConnectionsJob — iterates chunks containing node/valve/building connection components and calls ElectricityGraphUtils to delete the corresponding flow nodes and building nodes, using ComponentLookup/BufferLookup to access flow edges and flow connections. All structural changes are emitted via an EntityCommandBuffer.ParallelWriter created from a ModificationBarrier1.
  • DeleteValveNodesJob — removes the ElectricityValveConnection component from the matching valve entities (via ECB) and deletes the valve flow node(s) via ElectricityGraphUtils.

The system uses a ModificationBarrier1 to produce the ECB and adds the jobs' handles to the barrier so structural changes are applied safely. It sets up two EntityQuery instances (m_DeletedConnectionQuery, m_DeletedValveNodeQuery) and calls RequireAnyForUpdate so it only runs when at least one query matches.


Fields

  • private ModificationBarrier1 m_ModificationBarrier
    Holds the barrier system used to create an EntityCommandBuffer. The barrier's ECB is used to remove components and delete flow nodes/edges in a thread-safe deferred manner.

  • private EntityQuery m_DeletedConnectionQuery
    Query matching entities that are Deleted and have any of ElectricityNodeConnection, ElectricityValveConnection or ElectricityBuildingConnection (excluding Temp). When non-empty, schedules DeleteConnectionsJob.

  • private EntityQuery m_DeletedValveNodeQuery
    Query matching valve entities that have ElectricityValveConnection, Node and Updated and that do not have Owner, Temp or Deleted. When non-empty, schedules DeleteValveNodesJob.

  • private TypeHandle __TypeHandle
    Container struct used to cache ComponentTypeHandle, ComponentLookup and BufferLookup handles (and EntityTypeHandle) used by the jobs. Populated via __AssignHandles(ref SystemState).

Properties

  • This system exposes no public properties.

Constructors

  • public ElectricityGraphDeleteSystem()
    Parameterless constructor (marked with [Preserve]) — standard generated constructor for the system. Initialization is done in OnCreate.

Methods

  • protected override void OnCreate() : System.Void
    Sets up the m_ModificationBarrier and initializes the two EntityQuery instances (m_DeletedConnectionQuery and m_DeletedValveNodeQuery). Calls RequireAnyForUpdate so the system only updates when there are relevant changes.

  • protected override void OnUpdate() : System.Void
    If m_DeletedConnectionQuery is non-empty schedules DeleteConnectionsJob (parallel) that deletes flow nodes/edges for deleted connections. If m_DeletedValveNodeQuery is non-empty schedules DeleteValveNodesJob (parallel) to remove valve connection components and delete valve nodes. Each scheduled job receives the proper ComponentTypeHandle / Lookup instances via InternalCompilerInterface using cached TypeHandle entries. JobHandles are added to the ModificationBarrier producer handles and combined into base.Dependency.

  • protected override void OnCreateForCompiler() : System.Void
    Internal/compile-time helper that assigns component handles and queries for the generated code path. Calls __AssignQueries and __TypeHandle.__AssignHandles.

  • private void __AssignQueries(ref SystemState state) : System.Void
    An internal helper used by the generated OnCreateForCompiler. (In this compiled code it constructs and disposes an EntityQueryBuilder — kept for compiler compatibility.)

  • Nested job: DeleteConnectionsJob : IJobChunk

  • Fields:
    • ReadOnly ComponentTypeHandle m_NodeConnectionType
    • ReadOnly ComponentTypeHandle m_ValveConnectionType
    • ReadOnly ComponentTypeHandle m_BuildingConnectionType
    • ReadOnly ComponentLookup m_FlowEdges
    • ReadOnly BufferLookup m_FlowConnections
    • EntityCommandBuffer.ParallelWriter m_CommandBuffer
  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void
    Iterates the relevant component arrays in the chunk and invokes ElectricityGraphUtils.DeleteFlowNode and ElectricityGraphUtils.DeleteBuildingNodes to remove flow graph data for the deleted connections, emitting commands via the parallel command buffer.

  • Nested job: DeleteValveNodesJob : IJobChunk

  • Fields:
    • ReadOnly EntityTypeHandle m_EntityType
    • ReadOnly ComponentTypeHandle m_ValveConnectionType
    • ReadOnly BufferLookup m_FlowConnections
    • EntityCommandBuffer.ParallelWriter m_CommandBuffer
  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void
    Gets entities and their ElectricityValveConnection components from the chunk, removes the ElectricityValveConnection component from those entities using the parallel ECB, then calls ElectricityGraphUtils.DeleteFlowNode for each valve node to delete connected flow graph data.

  • TypeHandle.__AssignHandles(ref SystemState state) : System.Void
    Called from OnCreateForCompiler to acquire and cache ComponentTypeHandle/ComponentLookup/BufferLookup and EntityTypeHandle instances (read-only) used by the jobs.

Usage Example

// Marking an entity as Deleted will make ElectricityGraphDeleteSystem remove its electricity flow nodes
// on the next simulation update (provided the entity has a connection component).
EntityManager.AddComponent<Deleted>(someConnectionEntity);

// Example: remove the ElectricityValveConnection component from a valve entity to trigger valve node removal
EntityManager.AddComponent<Updated>(valveEntity); // cause it to match the deleted-valve query if appropriate
EntityManager.RemoveComponent<ElectricityValveConnection>(valveEntity);

Notes: - The actual graph removal logic is performed by ElectricityGraphUtils (DeleteFlowNode, DeleteBuildingNodes), which this system calls from within the jobs. - Structural changes (component removal / entity deletions) are deferred via ModificationBarrier1's EntityCommandBuffer to avoid immediate structural modifications from worker threads.