Game.Net.EdgeMappingSystem
Assembly: Assembly-CSharp
Namespace: Game.Net
Type: class
Base: GameSystemBase
Summary: EdgeMappingSystem updates EdgeMapping components for lanes by mapping lane endpoints to parent edges or nodes and computing curve deltas. It schedules a Burst-compiled IJobChunk (UpdateMappingJob) that iterates lane archetype chunks and fills/updates EdgeMapping data. The system processes only updated lanes each frame, but forces a full pass once when the game is loaded to ensure mappings are correct after load.
Fields
-
private EntityQuery m_UpdatedLanesQuery
This query selects lanes whose EdgeMapping has been marked Updated. Used for incremental updates each frame (cheaper). -
private EntityQuery m_AllLanesQuery
Query that selects all lanes with EdgeMapping. Used to force a full re-computation (used once after load). -
private bool m_Loaded
Flag set by OnGameLoaded to true; consumed by GetLoaded() to cause one full update pass on next OnUpdate. Acts as a one-shot trigger. -
private TypeHandle __TypeHandle
Holds cached ComponentTypeHandle/ComponentLookup/BufferLookup instances (in the nested TypeHandle struct). Populated in OnCreateForCompiler and used to get actual handles during OnUpdate via InternalCompilerInterface.GetComponentTypeHandle / GetComponentLookup / GetBufferLookup. -
private struct UpdateMappingJob
(nested, BurstCompile) IJobChunk implementation that performs the per-chunk mapping work. It contains all ComponentTypeHandle/ComponentLookup/BufferLookup needed to read Lane, Curve, Owner, Edge, Temp, Hidden and write EdgeMapping results. It implements the mapping logic through helper methods GetNodeEdgeMapping, GetEdgeNodeMapping and GetCurveDelta. -
private struct TypeHandle
(nested) Struct with fields for read-only/read-write ComponentTypeHandle, ComponentLookup and BufferLookup instances and an __AssignHandles method to initialize them from a SystemState. Used to reduce repeated handle construction costs.
Properties
- None (the system exposes no public properties).
Constructors
public EdgeMappingSystem()
Default constructor marked with [Preserve]. Typical ECS system constructor; no special initialization here — actual query setup happens in OnCreate.
Methods
protected override void OnCreate() : System.Void
Sets up entity queries:- m_UpdatedLanesQuery = query for EdgeMapping + Updated.
-
m_AllLanesQuery = query for EdgeMapping. Called when the system is created.
-
protected override void OnGameLoaded(Context serializationContext) : System.Void
Called when the game has finished loading. Sets m_Loaded = true to force a full pass on the next OnUpdate. -
private bool GetLoaded() : System.Boolean
Consumes the m_Loaded flag: if true, it clears it and returns true; otherwise returns false. Used by OnUpdate to decide whether to run the full lanes query this frame. -
protected override void OnUpdate() : System.Void
Main update method. It chooses either m_AllLanesQuery (if GetLoaded() was true) or m_UpdatedLanesQuery, then prepares an UpdateMappingJob filled with current ComponentTypeHandle/Lookup/BufferLookup instances (via InternalCompilerInterface.Get* passing handles from __TypeHandle and base.CheckedStateRef). The job is scheduled with JobChunkExtensions.ScheduleParallel if the query isn't empty. The system uses base.Dependency to chain dependencies.
Important notes: - The job is Burst-compiled for performance. - The job reads Lane, Curve, Owner, EdgeLane/NodeLane markers and writes EdgeMapping. - The job uses ComponentLookup and BufferLookup to access other entities' Curve/Edge data and adjacency buffers.
-
private void __AssignQueries(ref SystemState state) : System.Void
Called from OnCreateForCompiler to perform any required query initialization for the compiler. In this compiled form the method just creates and disposes an EntityQueryBuilder; TypeHandle handles are assigned separately. -
protected override void OnCreateForCompiler() : System.Void
Compiler support path that calls __AssignQueries and __TypeHandle.__AssignHandles to initialize cached handles for the compiled code path. -
protected struct TypeHandle.__AssignHandles(ref SystemState state) : System.Void
Initializes all ComponentTypeHandle, ComponentLookup and BufferLookup fields in the nested TypeHandle from the provided SystemState. This is used so the code generator can hold onto handle fields.
Nested UpdateMappingJob methods (run inside the job):
void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void
Main IJobChunk chunk execution. For each lane in the chunk:- Reads Lane, Curve, Owner and checks whether the entity has EdgeLane or NodeLane components.
- If EdgeLane, fills parent edge and computes curve delta (GetCurveDelta).
- If NodeLane, tries to find mapping by scanning connected edges/nodes using the ConnectedEdges / ConnectedNodes buffers (GetNodeEdgeMapping or GetEdgeNodeMapping).
-
Writes EdgeMapping result into the chunk's EdgeMapping buffer/array.
-
private EdgeMapping GetNodeEdgeMapping(Lane lane, Curve laneCurve, Entity node) : EdgeMapping
Finds parent edge(s) for a lane attached to a node by iterating connected edges of the node and examining connected nodes of those edges. Computes which parent is edge vs node, sets m_Parent1/m_Parent2 and computes m_CurveDelta1/m_CurveDelta2 depending on geometry and adjacency. Contains logic for swapping parents so ordering is consistent. Uses math helpers (MathUtils.Divide) to split bezier and compute deltas when necessary. -
private EdgeMapping GetEdgeNodeMapping(Lane lane, Entity edge) : EdgeMapping
Handles case where the lane is on an edge that connects to node(s). Examines the ConnectedNode buffer for the edge and finds matching connected node positions for the lane endpoints. Sets parents and curve deltas accordingly. -
private float2 GetCurveDelta(Bezier4x3 laneCurve, Entity edge) : float2
Looks up the Curve component for the provided edge (via ComponentLookup) and computes distances between the lane bezier endpoints and the edge bezier endpoints to fill a float2 delta (x = distance to A, y = distance to D). Returns default(float2) if Curve component is not available. -
void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Explicit interface implementation that forwards to the internal Execute method. Required for IJobChunk.
General notes for modders: - This system assumes several component types are present: Lane, EdgeLane, NodeLane, Curve, Owner, EdgeMapping, ConnectedEdge, ConnectedNode, Temp, Hidden. Ensure compatibility if injecting/modifying these components. - The job uses ComponentLookup/BufferLookup by Entity to read other entity data. Those lookups must be up-to-date and created with isReadOnly true where appropriate. - The system schedules the job with ScheduleParallel — data layout and archetype chunking impact performance; Burst gives high performance. - The system runs a full recompute once after OnGameLoaded; subsequent updates process only updated EdgeMapping entities (via Updated tag).
Usage Example
// Example (conceptual): the system schedules a Burst IJobChunk (UpdateMappingJob)
// to update EdgeMapping for lanes. This mirrors the system's OnUpdate behavior.
[Preserve]
protected override void OnUpdate()
{
EntityQuery query = GetLoadedOnce() ? m_AllLanesQuery : m_UpdatedLanesQuery;
if (!query.IsEmptyIgnoreFilter)
{
var jobData = new UpdateMappingJob {
m_LaneType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Net_Lane_RO_ComponentTypeHandle, ref base.CheckedStateRef),
// ... assign other handles / lookups from __TypeHandle same as the system does ...
};
base.Dependency = JobChunkExtensions.ScheduleParallel(jobData, query, base.Dependency);
}
}
This example demonstrates how the system builds the job and schedules it; modders can refer to the job logic to understand how EdgeMapping entries are computed or to create compatible systems that produce/consume EdgeMapping data.