Game.Simulation.Flow.Connection
Assembly:
Namespace: Game.Simulation.Flow
Type: struct
Base: System.ValueType
Summary:
Represents a directed connection between two nodes in the flow simulation. A connection references an edge by index (m_Edge
) and records the start and end node indices (m_StartNode
, m_EndNode
) together with a boolean (m_Backwards
) that indicates whether the connection uses the edge in the edge's forward or reverse orientation. The struct provides helpers to query capacity, final flow and residual capacity for the connection by looking up the referenced Edge
in a NativeArray<Edge>
.
Fields
-
public int m_StartNode
Index of the start node for this connection (node index in the simulation's node array). -
public int m_EndNode
Index of the end node for this connection (node index in the simulation's node array). -
public int m_Edge
Index of the edge in aNativeArray<Edge>
that this connection refers to. Methods in this struct use this index to look up the correspondingEdge
. -
public bool m_Backwards
If true, this connection treats the referenced edge in its backward orientation; otherwise it treats the edge in its forward orientation.
Properties
- (None)
Constructors
public Connection()
Default value-type constructor (provided by C# for structs). Typical instances are created with field-initializers or by copying.
Methods
-
public Connection Reverse()
Returns a newConnection
with start and end nodes swapped andm_Backwards
toggled. The returned connection references the same edge index (m_Edge
) but with reversed direction. -
public int GetOutgoingCapacity(NativeArray<Edge> edges)
Returns the capacity of the underlying edge in the connection's outgoing direction (i.e., usingm_Backwards
to select orientation). Internally callsedges[m_Edge].GetCapacity(m_Backwards)
. -
public int GetIncomingCapacity(NativeArray<Edge> edges)
Returns the capacity of the underlying edge in the connection's incoming direction (i.e., opposite orientation). Internally callsedges[m_Edge].GetCapacity(!m_Backwards)
. -
public int GetOutgoingFinalFlow(NativeArray<Edge> edges)
Returns the final flow value on the underlying edge in the outgoing orientation. Internally callsedges[m_Edge].GetFinalFlow(m_Backwards)
. -
public int GetIncomingFinalFlow(NativeArray<Edge> edges)
Returns the final flow value on the underlying edge in the incoming orientation. Internally callsedges[m_Edge].GetFinalFlow(!m_Backwards)
. -
public int GetOutgoingResidualCapacity(NativeArray<Edge> edges)
Returns the residual capacity of the underlying edge in the outgoing orientation. Internally callsedges[m_Edge].GetResidualCapacity(m_Backwards)
. -
public int GetIncomingResidualCapacity(NativeArray<Edge> edges)
Returns the residual capacity of the underlying edge in the incoming orientation. Internally callsedges[m_Edge].GetResidualCapacity(!m_Backwards)
.
Notes:
- All methods that accept NativeArray<Edge> edges
expect m_Edge
to be a valid index into that array. Callers are responsible for bounds-safety.
- The Edge
type is expected to expose GetCapacity(bool backwards)
, GetFinalFlow(bool backwards)
and GetResidualCapacity(bool backwards)
. The boolean parameter selects orientation relative to the connection.
- Because this struct uses NativeArray<T>
for lookups it is intended to be usable from Unity job code / burst-compiled contexts; keep job-safety and thread-safety rules in mind when using the methods.
Usage Example
// edges: NativeArray<Edge> populated elsewhere
Connection conn = new Connection {
m_StartNode = 10,
m_EndNode = 20,
m_Edge = 5,
m_Backwards = false
};
// Query outgoing capacity and flow
int outCapacity = conn.GetOutgoingCapacity(edges);
int outFlow = conn.GetOutgoingFinalFlow(edges);
// Query incoming (opposite orientation)
int inCapacity = conn.GetIncomingCapacity(edges);
int inFlow = conn.GetIncomingFinalFlow(edges);
// Create reversed connection
Connection reversed = conn.Reverse();
// reversed.m_StartNode == conn.m_EndNode
// reversed.m_Backwards == !conn.m_Backwards
Additional tips:
- Validate m_Edge
before calling the methods to avoid IndexOutOfRangeException when not running inside contexts that automatically guarantee bounds.
- When used inside jobs, ensure the NativeArray<Edge>
is passed in with appropriate access (ReadOnly/ReadWrite) and disposed properly when no longer needed.