Skip to content

Game.Routes.WaypointConnectionSystem

Assembly: Assembly-CSharp (game code)
Namespace: Game.Routes

Type: class

Base: GameSystemBase

Summary:
WaypointConnectionSystem is a game ECS system responsible for maintaining and updating waypoint connection data used by the routing/pathfinding layers. It responds to changes in waypoint, net, and lot geometry by collecting updated entities, finding/validating nearest lanes and connections (access lanes and route lanes), updating PathTargets and route segments, and issuing component updates via an EntityCommandBuffer (ModificationBarrier). The system uses several Burst-compiled jobs (IJobChunk, IJobParallelForDefer, IJob) and spatial quad-tree iterators to efficiently find affected lanes/net objects and to deduplicate/queue waypoint updates.


Fields

  • private ModificationBarrier5 m_ModificationBarrier
    Used to create an EntityCommandBuffer. The command buffer is used to apply component modifications (e.g., adding Updated / PathfindUpdated components, creating PathTargetMoved events) from jobs in a thread-safe manner.

  • private Game.Net.UpdateCollectSystem m_NetUpdateCollectSystem
    Reference to the system that collects updates for nets. Used to get updated net bounds and to determine whether nets were updated this frame.

  • private Game.Net.SearchSystem m_NetSearchSystem
    Reference to the net search system providing a net search tree (NativeQuadTree) used by lane-finding jobs.

  • private AirwaySystem m_AirwaySystem
    Reference to the airway system that provides airway maps (airplane/helicopter) used when finding air lanes for airborne route connections.

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    Reference to the object search system; used for static object search trees when searching affected objects.

  • private Game.Areas.UpdateCollectSystem m_AreaUpdateCollectSystem
    Reference to the system that collects updates for lots/areas. Used to get updated lot bounds.

  • private Game.Areas.SearchSystem m_AreaSearchSystem
    Reference to area search system providing area search tree used when searching areas/triangles.

  • private SearchSystem m_RouteSearchSystem
    Reference to route search system used to find route-search items (routes/waypoints) in a spatial index.

  • private EntityQuery m_WaypointQuery
    EntityQuery used to find entities of interest (Updated + any of Waypoint / AccessLane / RouteLane / ConnectedRoute) and to detect Deleted items. Drives whether Update work should run.

  • private EntityArchetype m_PathTargetEventArchetype
    Archetype used to create PathTargetMoved event entities that are generated when a PathTarget moves.

  • private TypeHandle __TypeHandle
    Internal helper struct that stores component/handle lookups (ComponentTypeHandle, ComponentLookup, BufferLookup) used by the jobs. Populated in OnCreateForCompiler.

Properties

  • None (no public properties exposed)

Constructors

  • public WaypointConnectionSystem()
    Default constructor. The system initialization happens in OnCreate / OnCreateForCompiler; constructor does not perform heavy initialization.

Methods

  • protected override void OnCreate()
    Initializes references to required systems (ModificationBarrier5, net/object/area search & collect systems, airway system, route search system). Builds the m_WaypointQuery (entities with Updated and any of Waypoint/AccessLane/RouteLane/ConnectedRoute, excluding Deleted), and creates the m_PathTargetEventArchetype. Called when the system is created.

  • protected override void OnUpdate()
    Main logic executed each frame when relevant changes are detected. High-level flow:

  • If waypoint query is not empty or nets/lots were updated, allocate a NativeList for updated entities.
  • Schedule UpdateWaypointReferencesJob (IJobChunk) to synchronize connected-route buffers, remove stale references, and collect initial updated waypoint entities.
  • If nets or lots were updated, schedule FindUpdatedWaypointsJob (IJobParallelForDefer) that expands updated bounds and iterates route and object quad-trees to find potentially affected waypoints/objects; results are copied from a NativeQueue into the updated list via DequeUpdatedWaypointsJob.
  • Run RemoveDuplicatedWaypointsJob to deduplicate updated list.
  • Schedule FindWaypointConnectionsJob (IJobParallelForDefer) to process each updated waypoint:
    • Determine actual position/elevation of waypoint (from Position or Transform/Elevation components).
    • Determine existing Connected reference and prefer-owner/master-lot heuristics.
    • Find suitable AccessLane and/or RouteLane using FindLane (either direct container lookup or spatial search via a LaneIterator that inspects nets/areas), possibly moving offsets and validating connections (ValidateConnection).
    • Update AccessLane and RouteLane components; enqueue PathTargetMoved events if a Position moved.
    • Mark connected route segments and path targets as Updated / PathfindUpdated when appropriate; write component changes via command buffer.
    • For moved waypoints, UpdateSurfaces marks area surfaces as Updated.
    • Enqueue PathTargets to be cleared (ClearPathTargetsJob).
  • Schedule ClearPathTargetsJob to clear PathTargets entries dequeued by the FindWaypointConnectionsJob.
  • Dispose temporary native collections and register job dependencies with modification barrier and search systems.

  • protected override void OnCreateForCompiler()
    Helper used by generated/compiled code: assigns queries and calls TypeHandle.__AssignHandles to initialize typed handles/lookups. This is part of the pattern used for safely building job handle/component lookups.

  • private void __AssignQueries(ref SystemState state)
    Internal helper used in OnCreateForCompiler; currently builds an empty EntityQueryBuilder (pattern preserved for compiler-generated flows).

  • Several nested Burst-compiled job structs:

  • UpdateWaypointReferencesJob (IJobChunk): updates connected-route buffers when Waypoint/Connected/Created/Deleted/Temp changes; collects updated waypoint entities.
  • FindUpdatedWaypointsJob (IJobParallelForDefer): expands bounds and queries route and object quad-trees to find waypoints/objects within updated bounds, enqueuing results.
  • DequeUpdatedWaypointsJob (IJob): drains the NativeQueue into a NativeList, sorts and deduplicates entries.
  • RemoveDuplicatedWaypointsJob (IJob): sorts and deduplicates an existing NativeList of Entities.
  • FindWaypointConnectionsJob (IJobParallelForDefer): heavy worker that finds and validates lane connections for each updated waypoint, updates components, generates PathTargetMoved events and schedules path target clearing.
  • ClearPathTargetsJob (IJob): consumes enqueued PathTargetInfo items to clear PathTargets data on segments.
  • Various nested iterator structs (RouteIterator, ObjectIterator, LaneIterator, SurfaceIterator) used by the jobs to traverse quad-trees and area search trees.

  • Note: The system contains many private helper methods inside FindWaypointConnectionsJob (GetOwnerBuilding, UpdateSurfaces, ValidateConnection, ValidateConnectedEdges, GetLaneContainer, GetMasterLot, MoveLaneOffsets, FindLane). These handle lane-finding heuristics, lane offset adjustments, connected-edge validation, and master lot lookups.

Usage Example

// Typical usage inside other game code / mods to ensure the system runs or to inspect it:
var world = World.DefaultGameObjectInjectionWorld; // or obtain the correct World
var waypointSystem = world.GetExistingSystemManaged<Game.Routes.WaypointConnectionSystem>();
if (waypointSystem == null)
{
    // create or get system
    waypointSystem = world.GetOrCreateSystemManaged<Game.Routes.WaypointConnectionSystem>();
}

// The system runs automatically by the ECS scheduler each frame.
// You can enqueue changes (add Updated components, modify waypoints, nets or lots) and the system will detect
// and process them in its OnUpdate. To force immediate processing (not recommended), you could call:
waypointSystem.Update(); // Only in contexts where synchronous update is valid.

// Example: Mark a waypoint entity as Updated to trigger re-evaluation.
// entityManager.SetComponentData(waypointEntity, new Updated());

Additional notes: - The system is heavily optimized for multithreaded Burst execution and uses NativeQuadTree iterators to localize searches. - When modifying route/waypoint related components from user code or mods, ensure you follow ECS thread-safety rules and component access patterns; let this system respond by adding Updated/Deleted/etc. as appropriate.