Game.ElectricityGraphReferencesSystem
Assembly:
Game (inferred from file path)
Namespace:
Game.Simulation
Type:
class
Base:
GameSystemBase
Summary:
This system tracks ElectricityFlowEdge entities and, when they are removed/marked deleted, removes references to those edge entities from the ConnectedFlowEdge buffers of the nodes they were connected to. It achieves this by scheduling a Burst-compiled IJobChunk (UpdateGraphReferencesJob) that iterates matching edge entities, reads their start/end node Entity references, and removes the corresponding ConnectedFlowEdge entries from the node buffers.
Fields
-
private EntityQuery m_EdgeGroup
This EntityQuery selects entities that represent electricity flow edges that should be processed by the system. In code it is constructed to require the ElectricityFlowEdge component and to only run when the Deleted tag is present (i.e., it processes edges being deleted). -
private TypeHandle __TypeHandle
A generated helper struct instance that caches EntityTypeHandle, ComponentTypeHandle(read-only), and BufferLookup (read/write). It is populated via __AssignHandles and used to build the job's type handles in OnUpdate.
Properties
- (none)
Constructors
public ElectricityGraphReferencesSystem()
Parameterless constructor annotated with [Preserve]. No custom initialization beyond base constructor; the system's setup occurs in OnCreate / OnCreateForCompiler.
Methods
protected override void OnCreate()
Creates the entity query m_EdgeGroup used by the system:- All: ElectricityFlowEdge (read-only)
-
Any: Deleted (read-only) This means the system runs when there are ElectricityFlowEdge entities with the Deleted tag. RequireForUpdate(m_EdgeGroup) is called so the system only updates when the query has matches.
-
protected override void OnUpdate()
Builds an UpdateGraphReferencesJob with handles obtained through InternalCompilerInterface (using the cached __TypeHandle entries and base.CheckedStateRef) and schedules it with JobChunkExtensions.Schedule against m_EdgeGroup, storing the returned JobHandle into base.Dependency. -
protected override void OnCreateForCompiler()
Compiler-time helper that assigns queries and type handles for the generated code paths: - Calls __AssignQueries(ref base.CheckedStateRef)
-
Calls __TypeHandle.__AssignHandles(ref base.CheckedStateRef)
-
private void __AssignQueries(ref SystemState state)
Generated stub that currently creates and disposes an EntityQueryBuilder (no effective runtime behavior in this implementation). Marked AggressiveInlining.
Nested Types / Job:
public struct UpdateGraphReferencesJob : IJobChunk
Burst-compiled job that removes edge references from node buffers.- Fields:
[ReadOnly] public EntityTypeHandle m_EntityType
— used to read Entity values from the chunk.[ReadOnly] public ComponentTypeHandle<ElectricityFlowEdge> m_ElectricityFlowEdgeType
— used to read the ElectricityFlowEdge component.public BufferLookup<ConnectedFlowEdge> m_ConnectedFlowEdges
— used to access node ConnectedFlowEdge buffers (read/write).
- Behavior:
- For each chunk, gets NativeArray
and NativeArray . - Iterates entries; for each edge:
- Reads its Entity id and ElectricityFlowEdge data (which contains m_Start and m_End node Entity references).
- Obtains the DynamicBuffer
for both start and end nodes via m_ConnectedFlowEdges. - Calls CollectionUtils.RemoveValue(buffer, new ConnectedFlowEdge(edge)) and likewise for the end node, removing the edge entry from both node buffers.
- The job implements the explicit IJobChunk.Execute wrapper to call its own Execute method.
- For each chunk, gets NativeArray
-
Notes:
- The job is [BurstCompile]d for performance.
- It uses BufferLookup to modify DynamicBuffers on arbitrary entities (the nodes referenced by the edges).
- CollectionUtils.RemoveValue mutates the DynamicBuffer to remove matching ConnectedFlowEdge entries.
-
private struct TypeHandle
Generated container for type handles: - Fields:
[ReadOnly] public EntityTypeHandle __Unity_Entities_Entity_TypeHandle
[ReadOnly] public ComponentTypeHandle<ElectricityFlowEdge> __Game_Simulation_ElectricityFlowEdge_RO_ComponentTypeHandle
public BufferLookup<ConnectedFlowEdge> __Game_Simulation_ConnectedFlowEdge_RW_BufferLookup
- Methods:
public void __AssignHandles(ref SystemState state)
— populates the above handles from the provided SystemState (calls state.GetEntityTypeHandle, state.GetComponentTypeHandle(isReadOnly:true), state.GetBufferLookup ).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_EdgeGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[1] { ComponentType.ReadOnly<ElectricityFlowEdge>() },
Any = new ComponentType[1] { ComponentType.ReadOnly<Deleted>() }
});
RequireForUpdate(m_EdgeGroup);
}
Notes and implementation tips: - This system is intended to run when edges are being removed (Deleted tag present). Ensure that the Deleted tag is correctly added to an edge entity before or during the procedure that removes edges so this system can clean up ConnectedFlowEdge buffers. - Because the job uses BufferLookup to mutate buffers of node entities, those node entities must exist and have ConnectedFlowEdge buffers; otherwise accessing the buffer could fail—ensure graph node entities are valid when edges are deleted. - The job uses CollectionUtils.RemoveValue which relies on ConnectedFlowEdge equality; ensure ConnectedFlowEdge equality semantics match desired behavior (it is compared by the contained edge Entity in this usage).