Skip to content

Game.Simulation.WaterPipeGraphUtils

Assembly: Game
Namespace: Game.Simulation

Type: static class

Base: System.Object

Summary:
Utility helpers for managing the water-pipe flow graph in the Entities (DOTS) simulation. Provides helper routines to query, create, update and delete flow edges and nodes for the water/ sewage graph. The helpers operate on Unity.Entities primitives (Entity, EntityManager, EntityCommandBuffer, BufferLookup/ComponentLookup, buffers of ConnectedFlowEdge and components WaterPipeEdge) and include job-friendly overloads (EntityCommandBuffer.ParallelWriter, jobIndex). Methods use Unity.Assertions to validate inputs in development builds.


Fields

  • (none)
    No instance or static fields — this is a pure static helper class.

Properties

  • (none)

Constructors

  • (none)
    Static classes have no constructors defined in this file.

Methods

  • public static bool HasAnyFlowEdge(Entity node1, Entity node2, ref BufferLookup<ConnectedFlowEdge> flowConnections, ref ComponentLookup<WaterPipeEdge> flowEdges)
    Checks whether any flow edge connects the two nodes (in either direction). Iterates the ConnectedFlowEdge buffer for node1 and compares the referenced WaterPipeEdge's m_Start/m_End against node1/node2. Uses Assert.IsTrue to validate node indices (>0). Returns true if a matching edge is found (either start->end or end->start); otherwise false.

  • public static bool TryGetFlowEdge(Entity startNode, Entity endNode, ref BufferLookup<ConnectedFlowEdge> flowConnections, ref ComponentLookup<WaterPipeEdge> flowEdges, out Entity entity)
    Overload that attempts to find a flow edge from startNode to endNode and outputs the edge Entity if found. Calls the full overload under the hood.

  • public static bool TryGetFlowEdge(Entity startNode, Entity endNode, ref BufferLookup<ConnectedFlowEdge> flowConnections, ref ComponentLookup<WaterPipeEdge> flowEdges, out WaterPipeEdge edge)
    Overload that attempts to find a flow edge from startNode to endNode and outputs the WaterPipeEdge component if found. Calls the full overload under the hood.

  • public static bool TryGetFlowEdge(Entity startNode, Entity endNode, ref BufferLookup<ConnectedFlowEdge> flowConnections, ref ComponentLookup<WaterPipeEdge> flowEdges, out Entity entity, out WaterPipeEdge edge)
    Searches the ConnectedFlowEdge buffer for startNode and checks each referenced WaterPipeEdge. If an edge with m_Start == startNode and m_End == endNode is found, outputs the edge Entity and WaterPipeEdge and returns true. If not found, outputs default(Entity) and default(WaterPipeEdge) and returns false. Uses Assert.IsTrue to validate node indices.

  • public static bool TrySetFlowEdge(Entity startNode, Entity endNode, int freshCapacity, int sewageCapacity, ref BufferLookup<ConnectedFlowEdge> flowConnections, ref ComponentLookup<WaterPipeEdge> flowEdges)
    Finds the directed flow edge startNode->endNode and, if found, updates its m_FreshCapacity and m_SewageCapacity and writes the modified WaterPipeEdge back into flowEdges[entity]. Returns true when the edge existed and was updated, otherwise false.

  • public static Entity CreateFlowEdge(EntityCommandBuffer commandBuffer, EntityArchetype edgeArchetype, Entity startNode, Entity endNode, int freshCapacity, int sewageCapacity)
    Creates a new flow edge entity via an EntityCommandBuffer, sets its WaterPipeEdge component (m_Start, m_End, capacities) and appends a ConnectedFlowEdge entry to the buffers on both startNode and endNode. Asserts that startNode and endNode are not Entity.Null. Returns the created edge Entity.

  • public static Entity CreateFlowEdge(EntityCommandBuffer.ParallelWriter commandBuffer, int jobIndex, EntityArchetype edgeArchetype, Entity startNode, Entity endNode, int freshCapacity, int sewageCapacity)
    Job-friendly variant that uses an EntityCommandBuffer.ParallelWriter and jobIndex to create the flow edge and append ConnectedFlowEdge entries. Same assertions and behavior as the non-parallel CreateFlowEdge.

  • public static Entity CreateFlowEdge(EntityManager entityManager, EntityArchetype edgeArchetype, Entity startNode, Entity endNode, int freshCapacity, int sewageCapacity)
    Direct EntityManager variant: creates the edge entity immediately, sets the WaterPipeEdge component via SetComponentData, and directly adds ConnectedFlowEdge entries to the start and end node buffers. Asserts that startNode and endNode are not Entity.Null. Returns the created edge Entity.

  • public static void DeleteFlowNode(EntityCommandBuffer.ParallelWriter commandBuffer, int jobIndex, Entity node, ref BufferLookup<ConnectedFlowEdge> flowConnections)
    Marks the provided node entity with the Deleted component (via the command buffer) and also marks all connected edge entities (from the node's ConnectedFlowEdge buffer) with Deleted. This prepares nodes and edges for removal in later cleanup systems.

  • public static void DeleteFlowNode(EntityManager entityManager, Entity node)
    Immediate EntityManager variant: adds the Deleted component to the node and to each connected edge found in the node's ConnectedFlowEdge buffer.

  • public static void DeleteBuildingNodes(EntityCommandBuffer.ParallelWriter commandBuffer, int jobIndex, WaterPipeBuildingConnection connection, ref BufferLookup<ConnectedFlowEdge> flowConnections, ref ComponentLookup<WaterPipeEdge> flowEdges)
    Helper that deletes the producer and/or consumer nodes referenced by a WaterPipeBuildingConnection. If connection.m_ProducerEdge != Entity.Null, obtains the producer node by calling connection.GetProducerNode(ref flowEdges) and calls DeleteFlowNode for that node. Similarly for the consumer node. Uses the provided BufferLookup/ComponentLookup to resolve nodes and edges.

Remarks about assertions and validity: - Several methods use Unity.Assertions (Assert.IsTrue / Assert.AreNotEqual) to validate inputs (for example, node.Index > 0 and not Entity.Null). These assertions run in development builds and help catch invalid entity usage early. - TryGetFlowEdge only checks directed edges start->end. Use HasAnyFlowEdge to test for connection in either direction.

Usage Example

// Example: create an edge then query and update its capacities.

EntityArchetype edgeArchetype = /* obtained earlier */;
Entity start = /* existing node entity */;
Entity end = /* existing node entity */;
int fresh = 100;
int sewage = 50;

// Create using EntityManager
Entity edge = WaterPipeGraphUtils.CreateFlowEdge(entityManager, edgeArchetype, start, end, fresh, sewage);

// Later: try to find the edge and update capacities
if (WaterPipeGraphUtils.TryGetFlowEdge(start, end, ref flowConnectionsLookup, ref flowEdgesLookup, out Entity edgeEntity))
{
    // update capacities
    WaterPipeGraphUtils.TrySetFlowEdge(start, end, 150, 75, ref flowConnectionsLookup, ref flowEdgesLookup);
}

// To remove a node and all connected edges (job-friendly)
WaterPipeGraphUtils.DeleteFlowNode(commandBufferParallelWriter, jobIndex, startNodeEntity, ref flowConnectionsLookup);

Notes: - Replace flowConnectionsLookup and flowEdgesLookup with the actual BufferLookup and ComponentLookup instances you have in your system or job. - When using ParallelWriter overloads, pass the jobIndex parameter used for that job's command buffer operations.