Game.Simulation.ElectricityFlowEdge
Assembly: Game
Namespace: Game.Simulation
Type: struct
Base: Implements IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a single directed/undirected electricity "edge" in the simulation graph between two Entities (start and end). Stores the current flow, maximum capacity and a set of flags describing directionality and special states (bottleneck, disconnected, etc.). Designed to be used as an ECS component and serialized for save/load compatibility. Deserialization contains version checks to preserve backwards compatibility with older save formats.
Fields
-
public int m_Index
Index/id for this edge. Typically used by the electricity subsystem to identify or index the edge in internal arrays/collections. -
public Entity m_Start
Entity at the start end of the edge (source node). -
public Entity m_End
Entity at the end end of the edge (target node). -
public int m_Capacity
Maximum supported capacity (bandwidth) of the edge in the simulation's internal units. -
public int m_Flow
Current flow value on the edge in the simulation's internal units. Positive/negative interpretation depends on the edge direction and FlowDirection. -
public ElectricityFlowEdgeFlags m_Flags
Bitmask flags describing the edge. Flags include direction bits (ForwardBackward) and status bits such as Bottleneck, BeyondBottleneck, Disconnected. The flags are used by the direction property and the boolean helpers below.
Properties
-
public FlowDirection direction { get; set; }
Encodes/decodes the direction of flow using the ForwardBackward bits of m_Flags. The getter returns the FlowDirection cast from the ForwardBackward portion of m_Flags. The setter clears the ForwardBackward bits then sets them according to the supplied FlowDirection value. This property does not affect other flags. -
public bool isBottleneck { get; }
True when the Bottleneck flag is set on m_Flags. Indicates the edge is currently a flow-limiting bottleneck in the network. -
public bool isBeyondBottleneck { get; }
True when the BeyondBottleneck flag is set. Used to mark edges downstream of a bottleneck. -
public bool isDisconnected { get; }
True when the Disconnected flag is set. Marks the edge as not connected in the current network topology.
Constructors
public ElectricityFlowEdge()
Default struct constructor. All fields default (m_Index = 0, m_Start/m_End = default Entity, m_Capacity = 0, m_Flow = 0, m_Flags = 0). In practice instances are typically created and then fields set explicitly by the electricity system.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data in a fixed order to the provided writer:- m_Start (Entity)
- m_End (Entity)
- m_Flow (int)
- m_Capacity (int)
-
m_Flags as a single byte This ordering must match Deserialize. The flags are serialized as a byte (so only the low 8 bits are persisted).
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields in the same order as Serialize. Contains version checks to maintain compatibility: - For reader.context.version > Version.electricityImprovements2: reads a byte and uses that value as m_Flags.
- For Version.electricityImprovements <= reader.context.version <= Version.electricityImprovements2: reads an int (legacy saved value) and sets m_Flags = ElectricityFlowEdgeFlags.ForwardBackward (legacy behavior).
- For older versions (below electricityImprovements): sets m_Flags = ElectricityFlowEdgeFlags.ForwardBackward (default). These branches are present to handle older save formats where flags were not stored as a byte or had different semantics.
Notes: - The struct implements IComponentData so it can be attached to ECS Entities. - The ISerializable implementation ensures this component can be written to/loaded from the game's save data. - The code expects existing enums/types: FlowDirection, ElectricityFlowEdgeFlags, Version, and the serialization context on reader/writer types.
Usage Example
// Create and initialize an electricity edge between two entities
var edge = new ElectricityFlowEdge();
edge.m_Index = 42;
edge.m_Start = startEntity;
edge.m_End = endEntity;
edge.m_Capacity = 1000;
edge.m_Flow = 500;
edge.direction = FlowDirection.Forward; // sets the ForwardBackward bits in m_Flags
// Check flags
if (edge.isBottleneck) {
// handle bottleneck visualization/logic
}
// During save/load the game's serializer will call:
// edge.Serialize(writer);
// and on load:
// edge.Deserialize(reader);