Game.Debug.WaterPipeDebugSystem
Assembly:
Game
Namespace:
Game.Debug
Type:
public class
Base:
GameSystemBase
Summary:
A compiler-generated ECS system used for visual debugging of the water distribution network (water pipes) in Cities: Skylines 2. The system gathers node and edge component data (nodes, edges and water-pipe-specific components), uses the GizmosSystem to draw wire spheres at node positions and wire cylinders along edges to visualize fresh and sewage flow vs capacity. The system is disabled by default and intended for debugging/visualization only.
Fields
-
private struct TypeHandle
Holds ComponentLookup handles used by the system: WaterPipeNode, Node, Edge, WaterPipeNodeConnection and WaterPipeEdge (all as read-only lookups). It exposes __AssignHandles(ref SystemState) which initializes those lookups from the given SystemState. This nested struct centralizes component lookup references for the system. -
private EntityQuery m_NodeGroup
EntityQuery matching entities with Node and WaterPipeNodeConnection components. Used to collect node component data and their pipe-connection info. -
private EntityQuery m_EdgeGroup
EntityQuery matching entities with Edge and WaterPipeNodeConnection components. Used to iterate edges that have water-pipe node connections. -
private EntityQuery m_OtherGroup
EntityQuery matching entities that have WaterPipeNodeConnection but exclude Node and Edge. (Likely for other types of pipe-connected entities.) -
private GizmosSystem m_GizmosSystem
Reference to the GizmosSystem used to draw debug primitives (spheres, cylinders, etc.). Acquired in OnCreate via base.World.GetOrCreateSystemManaged(). -
private TypeHandle __TypeHandle
Instance of the nested TypeHandle struct storing the component lookups for this system.
Properties
- This type exposes no public properties.
Constructors
public WaterPipeDebugSystem()
Parameterless public constructor marked with [Preserve] in the compiled code. The system initialization logic occurs in OnCreate / OnCreateForCompiler rather than the constructor.
Methods
-
protected override void OnCreate()
Initializes the system: retrieves/creates the GizmosSystem, sets up the three EntityQuery groups (m_NodeGroup, m_EdgeGroup, m_OtherGroup) with appropriate ComponentType filters, and disables the system by default (base.Enabled = false). Marked with [Preserve]. Use this to ensure the system is ready to collect pipe data when enabled. -
protected override void OnUpdate()
Main logic that runs each frame when the system is enabled. Summary of operations: - Ensures required ComponentLookup objects are available via InternalCompilerInterface.GetComponentLookup and the stored TypeHandle.
- Reads node and connection component arrays from m_NodeGroup (Node and WaterPipeNodeConnection).
- Obtains a GizmoBatcher from m_GizmosSystem (and completes any returned JobHandle dependencies).
- Draws wire spheres at node positions.
- Reads edge entities and their Edge component data from m_EdgeGroup and for each edge:
- Computes the edge midpoint and draws a sphere there.
- If the edge's start or end node has a WaterPipeNodeConnection, attempts to find the corresponding WaterPipeEdge using FindEdge.
- If found, reads fresh and sewage flows and capacities from the WaterPipeEdge component and draws wire cylinders offset from the edge midpoint to visualize flows and capacities (different colours for fresh/sewage and flow vs capacity).
-
Disposes all temporary NativeArray allocations. The method heavily uses ComponentLookup, DynamicBuffer
, and the GizmoBatcher draw calls (DrawWireSphere, DrawWireCylinder). -
private static bool FindEdge(Entity node1, Entity node2, out Entity edge, DynamicBuffer<ConnectedFlowEdge> edgeBuffer, ComponentLookup<WaterPipeEdge> edges)
Helper that searches a node's ConnectedFlowEdge buffer for an edge that connects to node2. If found, sets edge to the found edge entity and returns true. Otherwise sets edge = Entity.Null and returns false. It inspects WaterPipeEdge components to compare m_Start and m_End against node2. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler-generated placeholder that currently only creates and disposes an EntityQueryBuilder. Called from OnCreateForCompiler to ensure queries are assigned when the system is created by the compiler/runtime. -
protected override void OnCreateForCompiler()
Compiler-time / runtime hook used to initialize queries and assign component lookups via the TypeHandle. Calls __AssignQueries and __TypeHandle.__AssignHandles(ref base.CheckedStateRef). -
private void TypeHandle.__AssignHandles(ref SystemState state)
(Part of the nested TypeHandle) Initializes the ComponentLookupfields by calling state.GetComponentLookup (isReadOnly: true) for all required component types. Marked with AggressiveInlining in the compiled source.
Notes: - The system uses many temporaries (NativeArray allocations and DynamicBuffer reads) and explicitly disposes them to avoid leaks. - Gizmo drawing is performed via GizmoBatcher and the code completes any dependencies it receives from GetGizmosBatcher before drawing. - The system is intended for debugging only; it is disabled by default (base.Enabled = false) and is marked [CompilerGenerated] (likely injected/modified by build-time tooling).
Usage Example
// Example: enable the debug visualization at runtime (pseudo-code)
var world = World.DefaultGameObjectInjectionWorld;
var debugSystem = world.GetOrCreateSystemManaged<Game.Debug.WaterPipeDebugSystem>();
// Enable the system so OnUpdate runs each frame and draws the pipe gizmos
debugSystem.Enabled = true;
// The system's own OnCreate sets up its queries and GizmosSystem. When enabled,
// it will draw wire spheres at pipe node positions and cylinders to show flow/capacity.
Additional example (relevant OnCreate snippet from the system):
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
m_NodeGroup = GetEntityQuery(ComponentType.ReadOnly<Node>(), ComponentType.ReadOnly<WaterPipeNodeConnection>());
m_EdgeGroup = GetEntityQuery(ComponentType.ReadOnly<Edge>(), ComponentType.ReadOnly<WaterPipeNodeConnection>());
m_OtherGroup = GetEntityQuery(ComponentType.Exclude<Node>(), ComponentType.Exclude<Edge>(), ComponentType.ReadOnly<WaterPipeNodeConnection>());
base.Enabled = false; // disabled by default
}
{{ Additional notes: This system depends on several game-specific ECS component types: Node, Edge, WaterPipeNode, WaterPipeNodeConnection, WaterPipeEdge, ConnectedFlowEdge, and uses the game's GizmosSystem for rendering. When modifying or reusing this system in a mod, ensure the component types and Gizmos API are available and match the game's runtime version. Be careful to dispose temporary NativeArray allocations and to respect read-only/read-write semantics when accessing component data. }}