Game.Serialization.ConnectedFlowEdgeSystem
Assembly: Assembly-CSharp (game code)
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
ConnectedFlowEdgeSystem is a Unity ECS system used by the game to populate per-node ConnectedFlowEdge buffers by scanning edge entities that represent electricity and water connections. It schedules a Burst-compiled IJobChunk (ConnectedFlowEdgeJob) that iterates chunks containing ElectricityFlowEdge and WaterPipeEdge components, and for each edge adds a ConnectedFlowEdge entry to the DynamicBuffer of both the start and end node entities. Duplicate entries are avoided by using CollectionUtils.TryAddUniqueValue. The system requires entities that have either ElectricityFlowEdge or WaterPipeEdge to run and uses BufferLookup to write into the ConnectedFlowEdge buffers of node entities.
Fields
-
private Unity.Entities.EntityQuery m_Query
ConnectedFlowEdgeSystem stores an EntityQuery that matches any entities that have either an ElectricityFlowEdge or a WaterPipeEdge component. This query is created in OnCreate and passed to the job scheduler in OnUpdate. The system calls RequireForUpdate(m_Query) so it only updates when matching entities exist. -
private ConnectedFlowEdgeSystem.TypeHandle __TypeHandle
An internal struct holding cached type handles / buffer lookups used by the job: an EntityTypeHandle, ComponentTypeHandle(read-only), ComponentTypeHandle (read-only), and a BufferLookup (read/write). The system initializes these handles in OnCreateForCompiler / __AssignHandles (used by the code-generated style for safety with incremental updates).
Properties
- This type does not expose public properties.
Constructors
public ConnectedFlowEdgeSystem()
Default parameterless constructor. The system uses Unity's ECS lifecycle methods (OnCreate, OnUpdate) for initialization and behavior; no custom constructor logic is required beyond the default.
Methods
protected override void OnCreate()
Creates the m_Query with an Any clause matching entities that have either ElectricityFlowEdge or WaterPipeEdge (both read-only). Calls RequireForUpdate(m_Query) so the system only runs when such edges are present.
Key behavior: - m_Query = GetEntityQuery(new EntityQueryDesc { Any = [ ElectricityFlowEdge (RO), WaterPipeEdge (RO) ] });
protected override void OnUpdate()
Prepares and schedules the ConnectedFlowEdgeJob:- Fills the job struct fields by obtaining the current EntityTypeHandle and ComponentTypeHandles via InternalCompilerInterface.Get... calls referencing the cached __TypeHandle.
-
Schedules the job with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and assigns the returned JobHandle to base.Dependency.
-
protected override void OnCreateForCompiler()
Internal helper used by generated code patterns: sets up query assignments and assigns the type handles using __AssignQueries and __TypeHandle.__AssignHandles. Ensures the TypeHandle is populated in environments where generated safety checks are used. -
private void __AssignQueries(ref SystemState state)
Small helper that currently constructs and disposes an EntityQueryBuilder (no-op in this compiled form) — present to match the pattern used by the burst/IL post-processor. -
ConnectedFlowEdgeJob (nested struct, Burst-compiled)
- Fields:
- EntityTypeHandle m_EntityType (read-only)
- ComponentTypeHandle
m_ElectricityFlowEdgeType (read-only) - ComponentTypeHandle
m_WaterPipeEdgeType (read-only) - BufferLookup
m_ConnectedFlowEdges (read/write)
- Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : void
- Obtains native arrays for Entity and the two component types from the chunk.
- Iterates electricity-flow-edge component array: for each edge, fetches the start and end node buffers via m_ConnectedFlowEdges[ nodeEntity ] and adds the edge entity to both buffers using CollectionUtils.TryAddUniqueValue(buffer, new ConnectedFlowEdge(edge)).
- Iterates water-pipe-edge component array similarly.
- Ensures each node's ConnectedFlowEdge buffer contains unique entries for connected edges.
-
The job implements IJobChunk and is decorated with [BurstCompile] for performance.
-
private struct TypeHandle
- Holds the actual handles used to access components/buffers in jobs. Provides __AssignHandles(ref SystemState state) which calls state.GetEntityTypeHandle(), state.GetComponentTypeHandle
(isReadOnly: true) and state.GetBufferLookup () to populate the fields. This enables faster job scheduling and safety with the Entity Component System.
Usage Example
// Example usage pattern (conceptual):
// Ensure node entities have a DynamicBuffer<ConnectedFlowEdge> attached, then create edge entities
// with ElectricityFlowEdge or WaterPipeEdge components. ConnectedFlowEdgeSystem will run and populate
// each node's ConnectedFlowEdge buffer with the connecting edge entity references.
// Add a ConnectedFlowEdge buffer to a node entity:
entityManager.AddBuffer<ConnectedFlowEdge>(nodeEntity);
// Create an electricity edge entity that connects nodeA and nodeB:
var edge = entityManager.CreateEntity(typeof(ElectricityFlowEdge));
entityManager.SetComponentData(edge, new ElectricityFlowEdge { m_Start = nodeA, m_End = nodeB });
// After the next system update, ConnectedFlowEdgeSystem's job will add a ConnectedFlowEdge(entry)
// to the ConnectedFlowEdge buffers on nodeA and nodeB. The system avoids duplicate additions.
Notes / Implementation details: - The job uses CollectionUtils.TryAddUniqueValue to prevent duplicate ConnectedFlowEdge entries. - Both ElectricityFlowEdge and WaterPipeEdge are read-only inputs; ConnectedFlowEdge buffers are written using BufferLookup (m_ConnectedFlowEdges). - The job is scheduled via JobChunkExtensions.Schedule and runs in a Burst-compiled context for performance.