Skip to content

Game.Simulation.TaxiAISystem

Assembly: Game
Namespace: Game.Simulation

Type: class

Base: GameSystemBase

Summary:
TaxiAISystem is the main simulation system responsible for taxi vehicle behavior. It schedules a parallel IJobChunk (TaxiTickJob) to update taxi entities (boarding, disembarking, dispatch/requests, pathfinding, parking, maintenance, return-to-depot logic, queue/waypoint handling and toggling visual sign flags). It also schedules a small UpdateRouteVehiclesJob to apply route-vehicle additions/removals produced during the tick job. The system integrates with the pathfinding setup system, the end-of-frame barrier for command buffers, and simulation/time systems. Updates run periodically (interval/offset) and the system requires the taxi-car entity query to exist before it runs.


Fields

  • private EndFrameBarrier m_EndFrameBarrier
    Used to create an EntityCommandBuffer. The command buffer is used by the scheduled jobs to add/remove components, create entities and otherwise mutate ECS state at the end of the frame.

  • private PathfindSetupSystem m_PathfindSetupSystem
    Reference to the PathfindSetupSystem used to enqueue pathfinding requests produced by the taxi job.

  • private TimeSystem m_TimeSystem
    Reference to the TimeSystem to obtain the normalized time of day (used e.g. to pick route/pathfinding weights for some creatures).

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem to obtain the global simulation frame index and timing/context.

  • private EntityQuery m_VehicleQuery
    EntityQuery used to select taxi vehicle entities (CarCurrentLane + Owner + PrefabRef + PathOwner + Taxi + Target etc). This query is required for the system's update.

  • private EntityArchetype m_TaxiRequestArchetype
    Archetype used to create taxi request entities (ServiceRequest + TaxiRequest + RequestGroup) when the system issues new requests.

  • private EntityArchetype m_HandleRequestArchetype
    Archetype used to create HandleRequest entities and a corresponding Event to pass requests to other systems.

  • private ComponentTypeSet m_MovingToParkedCarRemoveTypes
    ComponentTypeSet listing components to remove from a vehicle entity when it transitions from moving to parked (moving/navigation/path components).

  • private ComponentTypeSet m_MovingToParkedAddTypes
    ComponentTypeSet listing components to add when a vehicle becomes parked (ParkedCar, Stopped, Updated).

  • private TypeHandle __TypeHandle
    Internal container of Entity/Component type handles and ComponentLookup/BufferLookup instances used to construct job data. Populated in OnCreateForCompiler / __AssignHandles.


Properties

  • None (TaxiAISystem exposes no public properties).
    The system exposes behavior via overrides (GetUpdateInterval/GetUpdateOffset/OnCreate/OnUpdate) rather than public properties.

Constructors

  • public TaxiAISystem()
    Default constructor. The system is initialized by the ECS world and OnCreate is used to configure queries, archetypes and dependencies.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns 16 — taxi updates are run every 16 simulation frames (throttled to spread work).

  • public override int GetUpdateOffset(SystemUpdatePhase phase)
    Returns 6 — update offset to schedule the system at a specific phase/time relative to other systems.

  • [Preserve] protected override void OnCreate()
    Initializes system references (EndFrameBarrier, PathfindSetupSystem, TimeSystem, SimulationSystem), creates the taxi vehicle EntityQuery, prepares archetypes for taxi requests and handle-request events, builds ComponentTypeSets used for parking transition and registers the query with RequireForUpdate. This sets up all handles the jobs later need.

  • [Preserve] protected override void OnUpdate()
    Creates and populates TaxiTickJob and UpdateRouteVehiclesJob job data, schedules the parallel chunk job to process taxi entities (TaxiTickJob) and a follow-up IJob (UpdateRouteVehiclesJob) to process route vehicle add/remove events. The method wires up the pathfind queue writer, end-frame barrier job handles, disposes temporary queues and sets base.Dependency appropriately.

  • protected override void OnCreateForCompiler()
    Internal helper used by compiler-generated code to prepare type handles and queries for the system. Calls __AssignQueries and __TypeHandle.__AssignHandles.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper (internal) used to ensure queries are properly assigned/constructed. Present for compatibility with how the system is emitted.

  • Nested types (brief summary)

  • RouteVehicleUpdate (private struct) — small value struct used to enqueue add/remove vehicle operations for a route (m_Route, m_AddVehicle, m_RemoveVehicle).
  • TaxiTickJob (private Burst-compiled IJobChunk) — main heavy job that iterates taxi entity chunks and runs Tick logic. Handles requests, dispatch selection, boarding/disembarking, parking checks, pathfinding setup, resetting paths, start/stop vehicle transitions and updates taxi/car/pathowner/target component state. Writes command-buffered operations to m_CommandBuffer and pushes route updates into a NativeQueue for the follow-up job.
  • UpdateRouteVehiclesJob (private Burst-compiled IJob) — dequeues RouteVehicleUpdate items and applies them synchronously to BoardingVehicle and Taxi components (sets boarding flags and boarding vehicle references).
  • TypeHandle (private struct) — generated container of ComponentTypeHandle/ComponentLookup/BufferLookup used to create job handles and lookups.

Notes on behavior: - TaxiTickJob uses many ComponentLookup/BufferLookup references (e.g. m_PrefabCarData, m_PrefabTaxiData, m_RouteVehicles, m_PathElements, m_TargetData, m_PathOwnerData) to perform lookups and mutate job-local copies which are later copied back to the chunk arrays or command buffer. - The job performs non-trivial logic: finding/validating parking spaces, appending/concatenating paths, path setup for transporting passengers vs returning to depot vs picking up passengers, and ensures correct component transitions for vehicle stopping/starting and parking. - The system uses m_PathfindSetupSystem.GetQueue and EndFrameBarrier.CreateCommandBuffer to integrate asynchronous pathfinding and safe entity mutations.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Acquire references to required systems
    m_EndFrameBarrier = World.GetOrCreateSystemManaged<EndFrameBarrier>();
    m_PathfindSetupSystem = World.GetOrCreateSystemManaged<PathfindSetupSystem>();
    m_TimeSystem = World.GetOrCreateSystemManaged<TimeSystem>();
    m_SimulationSystem = World.GetOrCreateSystemManaged<SimulationSystem>();

    // Build the taxi vehicle query and archetypes (actual code in the system does this already)
    m_VehicleQuery = GetEntityQuery(
        ComponentType.ReadWrite<CarCurrentLane>(),
        ComponentType.ReadOnly<Owner>(),
        ComponentType.ReadOnly<PrefabRef>(),
        ComponentType.ReadWrite<PathOwner>(),
        ComponentType.ReadWrite<Game.Vehicles.Taxi>(),
        ComponentType.ReadWrite<Target>(),
        ComponentType.Exclude<Deleted>(),
        ComponentType.Exclude<Temp>(),
        ComponentType.Exclude<TripSource>(),
        ComponentType.Exclude<OutOfControl>());

    // Ensure the system runs only when relevant taxi entities exist
    RequireForUpdate(m_VehicleQuery);
}

If you need more detail on any of the internal job logic (e.g. how boarding/disembarking is resolved, how path append/trim works, or the specific flags on Game.Vehicles.Taxi and Car), tell me which area you want documented and I will expand that section.