Game.Simulation.WaterPipeOutsideConnectionGraphSystem
Assembly:
Game (assembly containing the Simulation systems; commonly part of the game's core assembly)
Namespace:
Game.Simulation
Type:
class
Base:
GameSystemBase
Summary:
WaterPipeOutsideConnectionGraphSystem is a small ECS system that reacts to newly created WaterPipeOutsideConnection entities and connects corresponding water pipe nodes into the global water pipe flow graph. It schedules a parallel IJobChunk (CreateOutsideConnectionsJob) that:
- Looks up the Owner component on created connection entities,
- Uses a ComponentLookup to find the associated WaterPipeNodeConnection data for that owner,
- Adds a TradeNode component to the pipe node entity,
- Creates flow edges from the global source node to the pipe node and from the pipe node to the global sink node via WaterPipeGraphUtils.CreateFlowEdge.
The system uses a ModificationBarrier3 (command buffer producer) and depends on a WaterPipeFlowSystem instance for shared graph archetypes and the source/sink nodes. It schedules work with ScheduleParallel and registers the job handle with the modification barrier.
Fields
-
private WaterPipeFlowSystem m_WaterPipeFlowSystem
Reference to the WaterPipeFlowSystem that provides the edge archetype, source node and sink node used to build outside connections. -
private ModificationBarrier3 m_ModificationBarrier
A barrier system used to obtain an EntityCommandBuffer.ParallelWriter for structural changes (adding components / creating edges) from the job. -
private EntityQuery m_CreatedConnectionQuery
Query matching newly created WaterPipeOutsideConnection entities with Owner and Created tags and excluding Temp. This query is required for the system to run. -
private TypeHandle __TypeHandle
Holds component type/lookup handles (see nested TypeHandle struct) used to populate job fields safely for Jobs. -
(nested)
CreateOutsideConnectionsJob
(private, Burst-compiled)
IJobChunk that iterates created connection entities and creates edges/nodes in the flow graph. See Methods section for details. -
(nested)
TypeHandle
(private)
Container for ComponentTypeHandleand ComponentLookup with an __AssignHandles method to capture state handles from SystemState.
Properties
- None exposed by this system.
Constructors
public WaterPipeOutsideConnectionGraphSystem()
Default constructor. Marked with [Preserve] attribute on some lifecycle methods to ensure the system isn't stripped by code stripping; the constructor itself is empty in the compiled file.
Methods
protected override void OnCreate()
Initializes references and the entity query:- Obtains or creates the WaterPipeFlowSystem and ModificationBarrier3 from the World.
- Constructs m_CreatedConnectionQuery to look for WaterPipeOutsideConnection + Owner + Created and exclude Temp.
-
Calls RequireForUpdate(m_CreatedConnectionQuery) so the system only runs when matching entities exist.
-
protected override void OnUpdate()
Prepares and schedules CreateOutsideConnectionsJob: - Builds the job data filling component handles, component lookups and a parallel command buffer writer from the modification barrier.
- Passes the WaterPipeFlowSystem's edgeArchetype, sourceNode and sinkNode to the job.
- Uses JobChunkExtensions.ScheduleParallel to schedule the job against m_CreatedConnectionQuery.
-
Registers the job handle with the modification barrier via AddJobHandleForProducer so structural changes are synchronized.
-
protected override void OnCreateForCompiler()
Helper called by generated/compiled code: assigns query and type handles for the system using the internal helpers. Ensures __TypeHandle.__AssignHandles is called with the system state. -
private void __AssignQueries(ref SystemState state)
Small helper used by OnCreateForCompiler. No queries are created here other than an empty EntityQueryBuilder disposal (kept by generated code). -
(nested)
CreateOutsideConnectionsJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Job chunk execution: - Reads the Owner component array from the chunk.
- For each owner, attempts to get the WaterPipeNodeConnection component (via m_WaterPipeNodeConnections.TryGetComponent(ownerEntity, out ...)).
- If a connection is found:
- Adds a TradeNode component to the node entity using the parallel command buffer.
- Calls CreateOutsideFlowEdge to create an edge from the global source node to the pipe node.
- Calls CreateOutsideFlowEdge to create an edge from the pipe node to the global sink node.
-
The job uses the stored m_EdgeArchetype and the command buffer to create edges via WaterPipeGraphUtils.CreateFlowEdge.
-
(nested)
CreateOutsideConnectionsJob.CreateOutsideFlowEdge(int jobIndex, Entity startNode, Entity endNode)
Helper used inside the job to create a flow edge between two nodes using WaterPipeGraphUtils.CreateFlowEdge with zeroed capacity/weight parameters in this context. -
(nested)
TypeHandle.__AssignHandles(ref SystemState state)
Captures the read-only ComponentTypeHandleand ComponentLookup from the provided SystemState. This method is marked AggressiveInlining in the compiled source.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization performed by the system:
m_WaterPipeFlowSystem = World.GetOrCreateSystemManaged<WaterPipeFlowSystem>();
m_ModificationBarrier = World.GetOrCreateSystemManaged<ModificationBarrier3>();
m_CreatedConnectionQuery = GetEntityQuery(
ComponentType.ReadOnly<WaterPipeOutsideConnection>(),
ComponentType.ReadOnly<Owner>(),
ComponentType.ReadOnly<Created>(),
ComponentType.Exclude<Temp>());
RequireForUpdate(m_CreatedConnectionQuery);
}
Notes and implementation details:
- The CreateOutsideConnectionsJob is Burst-compiled and runs in parallel over matching chunks.
- Structural changes (AddComponent / edge creation) are performed via an EntityCommandBuffer.ParallelWriter obtained from ModificationBarrier3 to avoid structural changes inside the job thread directly.
- The job uses ComponentLookup