Skip to content

Game.WaterPipeEdgeGraphSystem

Assembly:
Game (runtime assembly for the game's ECS systems)

Namespace:
Game.Simulation

Type:
class

Base:
GameSystemBase

Summary:
A runtime ECS system that listens for newly created water-pipe network edges (entities with Game.Net.WaterPipeConnection + Edge + PrefabRef + Created tags) and constructs the corresponding "flow" graph used by the water simulation. When a net-edge is created this system: - ensures a flow-node exists for each connected net-node (creates one if needed), - creates a middle flow-node for the net-edge and connects flow edges from start -> middle -> end, - connects any other adjacent net-nodes to the middle node if their prefabs support water pipes, - ensures every net-node's flow-node is connected to all flow-edges that correspond to net-edges attached to that net-node, - uses a burst-compiled IJobChunk (CreateEdgeConnectionsJob) to do the work in parallel and records structural changes through a ModificationBarrier2B command buffer.

This system interacts closely with: - WaterPipeFlowSystem (provides node/edge archetypes), - ModificationBarrier2B (to record entity/archetype changes safely from a job), - WaterPipeGraphUtils (helper for creating flow edges), and reads components/buffers such as PrefabRef, WaterPipeConnectionData, ConnectedNode, ConnectedEdge, ConnectedFlowEdge, WaterPipeEdge and WaterPipeNodeConnection.


Fields

  • private WaterPipeFlowSystem m_WaterPipeFlowSystem
    Cached reference to the WaterPipeFlowSystem used to get node/edge archetypes (nodeArchetype, edgeArchetype) when creating flow entities.

  • private ModificationBarrier2B m_ModificationBarrier
    Command-buffer-providing barrier system used to perform structural changes (create entities, add components) from the job safely.

  • private EntityQuery m_CreatedEdgeQuery
    Query used to select newly created network edges that represent water-pipe connections. The query filters for ComponentType.ReadOnly(), Edge, PrefabRef, Created and excludes Temp.

  • private TypeHandle __TypeHandle
    Generated container of ECS type handles and buffer/component lookups used by the job (EntityTypeHandle, ComponentTypeHandle, BufferLookup, ComponentLookup, etc.). Assigned in OnCreateForCompiler.

Properties

  • (none declared public)

Constructors

  • public WaterPipeEdgeGraphSystem()
    Default constructor. The system initialization and required updates are set up in OnCreate.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes the system: caches the WaterPipeFlowSystem and the ModificationBarrier2B from the World, builds the EntityQuery (m_CreatedEdgeQuery) for newly created water-pipe net edges, and calls RequireForUpdate for that query so the system runs only when relevant edges exist.

  • [Preserve] protected override void OnUpdate()
    Creates a NativeParallelHashMap to track temporary mapping from net-node -> flow-node, constructs a CreateEdgeConnectionsJob with the proper type handles, lookups and command buffer from the ModificationBarrier2B, then schedules the job over m_CreatedEdgeQuery. The nodeMap is disposed after scheduling and the job handle is registered with the ModificationBarrier to ensure proper ordering.

  • protected override void OnCreateForCompiler()
    Compiler-time helper to assign queries and type handles (__AssignQueries and __TypeHandle.__AssignHandles). Present due to generated ECS code patterns.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Internal query assignment stub used by the generated code. No runtime behavior beyond codegen support.

Nested type: CreateEdgeConnectionsJob (Burst-compiled IJobChunk) - Purpose: The job iterates created net-edge chunks and for each Net Edge: - obtains/creates flow nodes corresponding to the net edge endpoints, - creates a middle flow-node for the edge and writes a WaterPipeNodeConnection component on the net-edge entity to point to that middle node, - creates flow edges between start -> middle and middle -> end using WaterPipeGraphUtils.CreateFlowEdge and WaterPipeConnectionData from the prefab, - connects any other connected net-nodes (via ConnectedNode buffer) to the middle node if their prefab has WaterPipeConnectionData, - ensures each net-node's flow-node is connected to the flow-edges for all net-edges attached to that net-node (avoids duplicate flow edges using ConnectedFlowEdge lookups and WaterPipeEdge components).

Key fields inside the job: - EntityTypeHandle m_EntityType - ComponentTypeHandle m_NetEdgeType - ComponentTypeHandle m_PrefabRefType - BufferLookup m_ConnectedNetNodes - BufferLookup m_ConnectedNetEdges - BufferLookup m_FlowConnections - ComponentLookup m_FlowEdges - ComponentLookup m_PrefabRefs - ComponentLookup m_WaterPipeConnectionDatas - ComponentLookup m_WaterPipeNodeConnections - EntityCommandBuffer m_CommandBuffer - NativeParallelHashMap m_NodeMap — temporary mapping from net-node -> created flow-node to avoid creating duplicates inside the job - EntityArchetype m_NodeArchetype — archetype to create flow node entities - EntityArchetype m_EdgeArchetype — archetype to create flow edge entities

Key job methods: - Execute(in ArchetypeChunk chunk, ...)
Processes each net-edge entity in the chunk: obtains endpoints, gets/creates flow-nodes, creates middle flow-node entity, writes WaterPipeNodeConnection (m_WaterPipeNode) on the net-edge, creates flow edges start->middle and middle->end, calls CreateEdgeMiddleNodeConnections and EnsureNodeEdgeConnections to connect surrounding nodes appropriately.

  • private void CreateEdgeMiddleNodeConnections(Entity netEdge, Entity flowMiddleNode)
    For every ConnectedNode attached to the netEdge, if the connected node's prefab has WaterPipeConnectionData, creates a flow edge from that node's flow node to the middle flow node. Uses PrefabRef and WaterPipeConnectionData lookups.

  • private void EnsureNodeEdgeConnections(Entity netNode, BufferedEntity flowNode, WaterPipeConnectionData connectionData)
    For each connected net-edge attached to netNode, if that net-edge already has a WaterPipeNodeConnection, ensures there is a flow-edge between flowNode and the existing water-pipe node. Uses WaterPipeGraphUtils.HasAnyFlowEdge to avoid duplicating edges.

  • private BufferedEntity GetOrCreateNetNodeConnection(Entity netNode)
    If netNode already has WaterPipeNodeConnection, returns it (stored). Otherwise checks m_NodeMap for a previously created node in this job, otherwise creates a new flow-node entity, writes WaterPipeNodeConnection on the net-node, and stores mapping in m_NodeMap. Returns a BufferedEntity wrapper indicating whether the node was already stored on the net-node or only stored in the map.

  • private void CreateFlowEdge(Entity startNode, Entity endNode, WaterPipeConnectionData connectionData)
    Convenience wrapper that calls WaterPipeGraphUtils.CreateFlowEdge with the command buffer and edge archetype passing capacity info from connectionData.

Concurrency & safety notes: - Structural changes are recorded through the EntityCommandBuffer from ModificationBarrier2B so the job can run in parallel without immediate structural mutations. - A NativeParallelHashMap is created in OnUpdate and passed into the job; it is disposed after job scheduling (Dispose(handle)), so the disposal is deferred until the scheduled job finishes. - The job is Burst compiled and uses ComponentLookup/BufferLookup/ComponentTypeHandle patterns for performance.

Related components/systems (for modders): - WaterPipeFlowSystem — provides node/edge archetypes and likely contains runtime data for the flow simulation. - WaterPipeGraphUtils — helper utilities to create flow edges and query existing flow edges. - WaterPipeConnectionData (prefab data) — defines capacities m_FreshCapacity and m_SewageCapacity used when creating flow edges. - WaterPipeNodeConnection — component that links a net-node entity to its flow-node entity. - WaterPipeEdge / ConnectedFlowEdge — used to query existing flow edges. - ConnectedNode / ConnectedEdge — net graph buffers describing adjacency.

Usage Example

// This system is an internal ECS system and normally shouldn't be subclassed by mods.
// Example: relevant parts of the system's OnCreate show required setup:
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_WaterPipeFlowSystem = base.World.GetOrCreateSystemManaged<WaterPipeFlowSystem>();
    m_ModificationBarrier = base.World.GetOrCreateSystemManaged<ModificationBarrier2B>();
    m_CreatedEdgeQuery = GetEntityQuery(
        ComponentType.ReadOnly<Game.Net.WaterPipeConnection>(),
        ComponentType.ReadOnly<Edge>(),
        ComponentType.ReadOnly<PrefabRef>(),
        ComponentType.ReadOnly<Created>(),
        ComponentType.Exclude<Temp>()
    );
    RequireForUpdate(m_CreatedEdgeQuery);
}

Notes for modders: - If your mod introduces new pipe-prefabs, ensure they include WaterPipeConnectionData and PrefabRef so this system can create flow edges correctly. - Avoid modifying the net-edge creation flow without considering this system, as disconnecting or adding edges may result in inconsistent flow graphs if not synchronized with the expected components (WaterPipeNodeConnection, ConnectedFlowEdge, WaterPipeEdge). - When inspecting runtime behavior, watch the ModificationBarrier2B command buffer ordering: structural changes are deferred, so queries immediately after scheduling may not see new flow nodes/edges until the barrier completes.