Game.Simulation.AircraftNavigationHelpers
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: static class
Base: System.Object
Summary:
Utility helpers and small types used by the aircraft navigation and lane-finding systems. This file contains nested helper structs used for reserving lanes, representing lane effects, caching current lane state for efficient spatial updates, and travel/collision iterators that query native quad-trees and airway maps to find suitable lanes or detect aircraft collisions. These helpers are intended for low-level simulation logic for helicopters and airplanes (e.g., finding closest lanes, maintaining lane-object buffers, bounding volume calculations, and simple collision queries).
Fields
-
private NativeQuadTree<Entity, QuadTreeBoundsXZ> m_SearchTree
Used inside CurrentLaneCache to store the quad-tree reference used to check whether an entity is already registered and to retrieve/update search bounds. This is a private field of the CurrentLaneCache instance and is used when deciding whether to add/remove/update lane-object entries. -
private Entity m_WasCurrentLane
Tracks the previously known lane for an aircraft in CurrentLaneCache to detect lane changes and issue buffer add/remove/update operations accordingly. -
private float2 m_WasCurvePosition
Stores the previous curve position (XY) along the lane curve so changes in curve parameter can trigger updates to lane-object buffers. -
private bool m_WasFlying
Cached flag indicating whether the aircraft was previously considered "flying" (AircraftLaneFlags.Flying). Used to decide whether to treat the entity as a lane object or as a flying object for quad-tree registration.
Properties
- None on the top-level static class.
The helper types themselves expose fields and small APIs (e.g., LaneReservation.CompareTo) rather than instance properties. Use the nested structs directly for the contained data.
Constructors
-
public LaneReservation(Entity lane, float offset, int priority)
Creates a lane reservation record. The offset is converted to a byte by clamping and scaling (offset * 255f rounded). Priority is stored as a byte. Use this to request a lateral offset and priority for reserving a lane. -
public LaneEffects(Entity lane, float3 sideEffects, float relativeSpeed)
Constructs a LaneEffects value describing side-effect forces (float3) and a relative speed multiplier applied when traveling on the given lane entity. -
public CurrentLaneCache(ref AircraftCurrentLane currentLane, ComponentLookup<PrefabRef> prefabRefData, NativeQuadTree<Entity, QuadTreeBoundsXZ> searchTree)
Initializes CurrentLaneCache from the current AircraftCurrentLane component, a prefab lookup and a search quad-tree. The constructor sanitizes the input lane (clearing it if the prefab lookup doesn't contain the lane) and caches the previous lane, curve position and flying flag for later change detection.
Methods
-
public int LaneReservation.CompareTo(LaneReservation other)
Implements IComparableby comparing the underlying lane Entity.Index values. Useful for sorting reservations deterministically by lane entity. -
public void CurrentLaneCache.CheckChanges(Entity entity, ref AircraftCurrentLane currentLane, LaneObjectCommandBuffer buffer, BufferLookup<LaneObject> laneObjects, Transform transform, Moving moving, AircraftNavigation navigation, ObjectGeometryData objectGeometryData)
Main update method that examines whether an aircraft's lane, curve position, or flying state changed since the cache was created. It: - Adds/removes/updates entries in LaneObjectCommandBuffer when the lane changes and when the lane buffer exists on the lane entity.
- If the current registration is via the quad-tree (not lane-object buffer), it compares stored search-tree bounds against newly calculated bounds and issues an Update registration if bounds exceed the stored bounds.
-
Determines whether to remove or add the entity to the quad-tree registration depending on the change flags. This method encapsulates the logic for keeping lane-object buffers and spatial registration consistent with the component state.
-
private Bounds3 CurrentLaneCache.CalculateMinBounds(Transform transform, Moving moving, AircraftNavigation navigation, ObjectGeometryData objectGeometryData)
Compute a conservative "minimal" bounds used to quickly test whether the current quad-tree registration still covers the entity. It factors in a scaled fraction of velocity and the aircraft's target-direction speed to expand the bounds slightly. -
private Bounds3 CurrentLaneCache.CalculateMaxBounds(Transform transform, Moving moving, AircraftNavigation navigation, ObjectGeometryData objectGeometryData)
Compute a larger bounds that approximates the maximum area the aircraft may occupy in the near future (based on velocities, object size, and offsets). Used when adding/updating quad-tree registrations to ensure enough coverage for the entity. -
public bool FindLaneIterator.Intersect(QuadTreeBoundsXZ bounds)
QuadTree iterator intersection test: returns true if the query bounds intersects the iterator's search bounds (used by native quad-tree traversal). -
public void FindLaneIterator.Iterate(QuadTreeBoundsXZ bounds, Entity edgeEntity)
Quad-tree iteration callback that inspects sub-lanes (SubLane buffer) on an edge entity. For each sub-lane it: - Filters lanes by road type (Helicopter/Airplane) and by connection lane flags.
- Computes distance from the lane bezier to the search position, first by bounding distance and then by full bezier distance if close.
-
If closer than the current minimum, updates the m_Result (AircraftCurrentLane like data) with lane, curve position and flags. This is the core lane-finding logic used when searching nearby road/connection lanes.
-
public void FindLaneIterator.Iterate(ref AirwayHelpers.AirwayData airwayData)
Airway-map based iteration: queries precomputed airway maps (helicopter/airplane maps) to find closest airway lanes and merge the result with the quad-tree search. When a closer airway lane is found, it sets the result lane and flags it as an Airway and updates the minimum distance. -
public bool AircraftCollisionIterator.Intersect(QuadTreeBoundsXZ bounds)
Checks whether a quad-tree node's bounds intersect a query line segment; used to early-out traversal when searching for aircraft collisions along a path. -
public void AircraftCollisionIterator.Iterate(QuadTreeBoundsXZ bounds, Entity entity)
Iterates entities in intersecting quad-tree nodes to locate the nearest aircraft intersecting the given line segment (Line3.Segment). Skips a provided ignore entity and non-aircraft entities. For each candidate: - Checks vertical relationship and then computes distance along the segment,
- If the candidate is closer than the current closest, updates m_Result and m_ClosestT. Used for checking potential aircraft-to-aircraft path intersections.
Usage Example
// Example: Using CurrentLaneCache inside a system/update to keep lane registration in sync
protected void UpdateAircraftRegistration(Entity entity, ref AircraftCurrentLane currentLane,
LaneObjectCommandBuffer laneBuffer, BufferLookup<LaneObject> laneObjects,
ComponentLookup<PrefabRef> prefabRefData,
NativeQuadTree<Entity, QuadTreeBoundsXZ> searchTree,
in Transform transform, in Moving moving, in AircraftNavigation navigation, in ObjectGeometryData objectGeometryData)
{
// Create the cache snapshot
var cache = new AircraftNavigationHelpers.CurrentLaneCache(ref currentLane, prefabRefData, searchTree);
// Check for changes and apply add/remove/update commands to laneBuffer or searchTree registration
cache.CheckChanges(entity, ref currentLane, laneBuffer, laneObjects, transform, moving, navigation, objectGeometryData);
}
// Example: Creating a lane reservation
var reservation = new AircraftNavigationHelpers.LaneReservation(laneEntity, offset: 0.5f, priority: 2);
// Example: Using FindLaneIterator to query quad-tree (pseudo-call; actual quad-tree APIs vary)
var iter = new AircraftNavigationHelpers.FindLaneIterator
{
m_Bounds = searchBounds,
m_Position = searchPosition,
m_MinDistance = maxSearchDistance,
m_Result = default,
m_CarType = RoadTypes.Helicopter, // or RoadTypes.Airplane
m_SubLanes = subLaneLookup,
m_CarLaneData = carLaneLookup,
m_ConnectionLaneData = connectionLaneLookup,
m_CurveData = curveLookup,
m_PrefabRefData = prefabRefLookup,
m_PrefabCarLaneData = prefabCarLaneDataLookup,
};
quadTree.Find(ref iter);