Game.TransformerData
Assembly:
Namespace: Game.Simulation
Type: struct
Base: System.ValueType (struct)
Summary:
TransformerData is a utility value type used by the simulation to compute a transformer's electrical capacity and current flow by walking its associated subnets and installed upgrades. It uses ComponentLookup and BufferLookup handles (most marked ReadOnly) to query the ECS world for node, connection, prefab and flow data. The computed capacity is the bottleneck between low- and high-voltage capacities; flow is accumulated from corresponding low-voltage flow edges.
Fields
-
private ComponentLookup<Deleted> m_Deleted
Lookup used to detect deleted entities (skips deleted subnets/nodes). -
private ComponentLookup<PrefabRef> m_PrefabRefs
Lookup to get the prefab reference for a subnet entity (used to find its ElectricityConnectionData). -
private ComponentLookup<ElectricityConnectionData> m_ElectricityConnectionDatas
Lookup providing prefab connection data (voltage, capacity) used to classify and sum capacities. -
private BufferLookup<InstalledUpgrade> m_InstalledUpgrades
Buffer lookup for installed upgrades on a building/entity. Used to recursively scan upgrades for additional subnets/markers. -
private BufferLookup<Game.Net.SubNet> m_SubNets
Buffer lookup for subnet buffers attached to the transformer entity (the primary source of marker nodes to process). -
private ComponentLookup<Node> m_NetNodes
Lookup to ensure a subnet entity is a valid net node (presence check). -
private ComponentLookup<ElectricityNodeConnection> m_ElectricityNodeConnections
Lookup to obtain the electricity node connection component for a subnet (used to get the associated electricity node). -
private ComponentLookup<ElectricityValveConnection> m_ElectricityValveConnections
Lookup to obtain the valve-node connection component for a subnet (used when resolving flow edges). -
private BufferLookup<ConnectedFlowEdge> m_FlowConnections
Buffer lookup containing connected flow edges for nodes; used together with m_FlowEdges to resolve flows. -
private ComponentLookup<ElectricityFlowEdge> m_FlowEdges
Lookup for electricity flow edge components (where the m_Flow value is read).
Note: Many fields are used in a ReadOnly fashion (they are marked [ReadOnly] in the source), indicating the struct is intended to only read ECS state.
Properties
- None
Constructors
public TransformerData()
Structs have an implicit parameterless constructor. Instances of TransformerData are typically created and populated by the system that holds the corresponding ComponentLookup/BufferLookup references before calling GetTransformerData.
Methods
public void GetTransformerData(Entity entity, out int capacity, out int flow)
Computes the transformer's capacity and current flow for the provided entity (transformer). Steps:- Initializes lowVoltageCapacity, highVoltageCapacity and flow to zero.
- If the transformer's subnet buffer exists, processes those marker nodes.
- If the transformer's installed-upgrades buffer exists, recursively processes upgrades that are active and have subnets.
- capacity is returned as min(lowVoltageCapacity, highVoltageCapacity).
- flow is accumulated only from low-voltage nodes where a corresponding flow edge is found.
Parameters: - entity: the transformer entity whose data to inspect. - capacity: out parameter receiving the computed capacity (bottleneck of low vs high voltage). - flow: out parameter receiving accumulated electrical flow on low-voltage side.
private void ProcessMarkerNodes(DynamicBuffer<InstalledUpgrade> upgrades, ref int lowVoltageCapacity, ref int highVoltageCapacity, ref int flow)
Iterates installed upgrades buffer:- For each InstalledUpgrade, checks whether it's active (via BuildingUtils.CheckOption against BuildingOption.Inactive).
- If active and the upgrade entity has a SubNet buffer, delegates to the subnet-processing overload to include its markers in capacity/flow totals.
-
Allows upgrades to contribute additional marker subnets recursively.
-
private void ProcessMarkerNodes(DynamicBuffer<Game.Net.SubNet> subNets, ref int lowVoltageCapacity, ref int highVoltageCapacity, ref int flow)
Iterates subnets (marker nodes) and for each: - Grabs the subnet entity and performs several checks: it must have a net node, must not be deleted, must have ElectricityNodeConnection and ElectricityValveConnection and a PrefabRef, and the prefab must have ElectricityConnectionData. If any check fails, the subnet is skipped.
- If the prefab's ElectricityConnectionData voltage is Low:
- Adds that connection capacity to lowVoltageCapacity.
- Attempts to resolve a flow edge between the valve node and electricity node via ElectricityGraphUtils.TryGetFlowEdge using m_FlowConnections and m_FlowEdges; if successful, adds the edge.m_Flow to flow.
- Otherwise (non-low voltage), adds the connection capacity to highVoltageCapacity.
- This routine is the core scan that sums capacities and flow from marker nodes.
Notes: - The code uses continued guards to skip invalid or deleted nodes. - BuildingUtils.CheckOption is used to ignore inactive upgrades.
Usage Example
// Example usage inside a SystemBase or other simulation code that has initialized the lookups.
TransformerData transformerData = new TransformerData
{
m_Deleted = GetComponentLookup<Deleted>(true),
m_PrefabRefs = GetComponentLookup<PrefabRef>(true),
m_ElectricityConnectionDatas = GetComponentLookup<ElectricityConnectionData>(true),
m_InstalledUpgrades = GetBufferLookup<InstalledUpgrade>(true),
m_SubNets = GetBufferLookup<Game.Net.SubNet>(true),
m_NetNodes = GetComponentLookup<Node>(true),
m_ElectricityNodeConnections = GetComponentLookup<ElectricityNodeConnection>(true),
m_ElectricityValveConnections = GetComponentLookup<ElectricityValveConnection>(true),
m_FlowConnections = GetBufferLookup<ConnectedFlowEdge>(true),
m_FlowEdges = GetComponentLookup<ElectricityFlowEdge>(true)
};
int capacity, flow;
transformerData.GetTransformerData(transformerEntity, out capacity, out flow);
// Use capacity and flow for simulation logic or UI display.