Skip to content

Game.Net.SecondaryLaneSystem

Assembly:
Namespace: Game.Net

Type: class

Base: GameSystemBase

Summary:
SecondaryLaneSystem is an ECS game system responsible for creating, updating and removing "secondary lanes" (decorative/auxiliary lane entities: crossings, parking-fit lanes, hanging lanes, track joins, etc.) for network edges. It scans owners that contain SubLane buffers and, using prefab data (SecondaryNetLane, SecondaryLaneData, NetLaneData, ParkingLaneData, etc.), computes where secondary lanes should appear, merges/joins/cuts them according to overlaps, parking slots and spacing rules, and creates/upates/deletes the SecondaryLane entities via a parallel IJobChunk (UpdateLanesJob). The job is Burst-compiled and uses many helper routines to fit lanes to parking slots, compute cut ranges and spacing, merge adjacent lanes, and generate crossing lanes.


Fields

  • private CityConfigurationSystem m_CityConfigurationSystem
    System reference used to read city-wide settings (for example, left-hand traffic and default theme used when checking requirements).

  • private ModificationBarrier4B m_ModificationBarrier
    Barrier system used to create a parallel EntityCommandBuffer so the job can safely create/update/delete entities.

  • private EntityQuery m_OwnerQuery
    Query that selects owner entities (those having SubLane buffers and Updated/Deleted) that the system processes.

  • private ComponentTypeSet m_AppliedTypes
    ComponentTypeSet used to apply "applied" created/updated markers when converting temporary lanes into permanent lanes.

  • private ComponentTypeSet m_DeletedTempTypes
    ComponentTypeSet used to mark temporary lanes as deleted when replacing/updating them.

  • private ComponentTypeSet m_HideLaneTypes
    ComponentTypeSet listing components used to hide lanes (CullingInfo, MeshBatch, MeshColor); used when creating lanes that should be hidden.

  • private TypeHandle __TypeHandle
    Internal container generated by the compiler that stores type handles and buffer lookups used by UpdateLanesJob. It wires ComponentTypeHandle/ComponentLookup/BufferLookup instances retrieved from SystemState.


Properties

  • No public properties on the system itself. The system exposes no modifiable public API surfaces; behavior is driven by ECS components and prefab data.

Constructors

  • public SecondaryLaneSystem()
    Default constructor (Preserve attribute present in source). Standard ECS system construction; system registers itself with the world and later initializes resources in OnCreate.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system: obtains CityConfigurationSystem and ModificationBarrier4B, builds the owner EntityQuery (requires SubLane buffer + Updated/Deleted), sets up ComponentTypeSet values used when creating/removing lanes and calls RequireForUpdate for the owner query. This prepares the system to run only when there are relevant changes.

  • protected override void OnUpdate() : System.Void
    Main update entry. Constructs and schedules the Burst-compiled UpdateLanesJob (IJobChunk) in parallel against m_OwnerQuery. The job receives component lookups and buffer lookups from __TypeHandle and uses a parallel EntityCommandBuffer (from m_ModificationBarrier) to perform all entity creations/updates/deletes. The job's handle is added to the modification barrier so structural changes are synchronized correctly.

  • protected override void OnCreateForCompiler() : System.Void
    Compiler-time helper used to assign queries and type handles when building with source-generated type handles. It calls __AssignQueries and __TypeHandle.__AssignHandles to set up state used in scheduling the job.

  • private void __AssignQueries(ref SystemState state) : System.Void
    Internal method used to register/assign any required queries at compile-time. (In this implementation it performs a no-op EntityQueryBuilder disposal — it's a place-holder used by generated code paths.)

  • Nested types and helpers (all inside the system):

  • UpdateLanesJob (BurstCompile, implements IJobChunk)
    The core worker. It iterates owner chunks and for each owner:

    • If the owner is marked Deleted, finds all existing secondary lane sub-entities and marks them Deleted.
    • Otherwise, collects current SubLane buffers and "old lanes" (existing secondary lane entities) into lane-buffer structures, inspects lane curve geometry and prefab secondary-lane buffers, computes lane corners, crossing lanes and cut ranges, checks requirements, fits to parking slots, calculates spacing and group cut ranges, and creates/updates/removes secondary lane entities accordingly. It contains many helper methods:
      • DeleteLanes: mark existing secondary lanes deleted for deleted owners.
      • UpdateLanes: main chunk handler that constructs lane corners, crossing lanes, cut ranges and calls CreateSecondaryLane / RemoveUnusedOldLanes.
      • FitToParkingLane: computes parking slot counts, blocked masks and bounds for fitting secondary lanes to parking spaces.
      • FillOldLaneBuffer: helper to gather old secondary lane entities present in a SubLane buffer.
      • RemoveUnusedOldLanes: removes old lanes that were not matched/updated by the current pass.
      • AddCrossingLane: collects and merges adjacent crossing lane endpoints before creating lanes.
      • CreateSecondaryLane (two overloads): create or update a single secondary lane entity. Handles reusing existing entities (from m_OldLanes), setting components (PrefabRef, Lane, Curve, Owner, Elevation, HangingLane, Temp), or creating a new entity from the prefab's lane archetype. Also handles temporary lane semantics (Temp flags and Replace).
      • GetCutRanges (two overloads): computes ranges along which secondary lane creation is cut/allowed based on parking slots and overlaps with other lanes, including slave/master grouping logic.
      • ExtendedIntersect: robust curve intersection helper that also checks intersections with start/end tangents with width consideration.
      • ReplaceTempOwner & GetOriginalLane: helper logic to support temp owner replacement and original mapping.
      • CheckRequirements: validates that a prefab's ObjectRequirement buffer is satisfied by available requirements (including default theme); caches requirement results in a per-owner NativeParallelHashSet to avoid repeated lookups. The job uses many ComponentLookup and BufferLookup members provided at schedule-time in OnUpdate.
  • LaneKey, LaneBuffer, LaneCorner, CutRange, CrossingLane
    Internal helper structs used by UpdateLanesJob to track lane geometry, existing lanes, cut ranges and crossing lanes.

  • Most of the logic is inside the Burst-compiled UpdateLanesJob; the outer system mainly schedules this job and provides required lookups.


Usage Example

// The SecondaryLaneSystem is an automatic ECS system. You don't instantiate it manually.
// To make a custom net prefab produce secondary lanes, add SecondaryNetLane entries
// to the net prefab and ensure the corresponding SecondaryLaneData prefab entity exists.
//
// Example (runs on main thread / system initialization code):
Entity myNetPrefab = /* obtain your net prefab entity */;
if (EntityManager.HasComponent<DynamicBuffer<SecondaryNetLane>>(myNetPrefab))
{
    var buf = EntityManager.GetBuffer<SecondaryNetLane>(myNetPrefab);
    // Add a simple crossing secondary lane that uses some secondary lane prefab entity:
    buf.Add(new SecondaryNetLane { m_Lane = mySecondaryLanePrefabEntity, m_Flags = SecondaryNetLaneFlags.Crossing });
}

// After you modify prefab buffers, the SecondaryLaneSystem will, on next update,
// evaluate owners (edges) that use the net prefab and create/update secondary lane entities accordingly.

Notes & tips for modders: - Secondary lane behavior is driven by prefab data: - SecondaryNetLane buffers on net prefabs define what secondary lane prefabs to attempt creating and which flags (crossing, duplicate sides, require rules) apply. - SecondaryLaneData on the secondary lane prefabs controls spacing, cut offsets, position offsets, FitToParkingSpaces and other flags. - ParkingLaneData, NetLaneData, SlaveLane, MasterLane, CarLane, PedestrianLane, TrackLane and Overlap buffers influence whether/where secondary lanes appear (e.g., fitting to parking slots, avoiding merges, or skipping overlaps). - Temporary lanes (Temp component) and owner replacement behavior are supported: the system will transfer ownership and attempt to reuse existing secondary lane entities where possible. - The heavy work is Burst-compiled in UpdateLanesJob; to debug geometry or logic, consider logging input prefab buffer contents or running the logic on smaller test cases first.