Game.Simulation.TaxiDispatchSystem
Assembly: Assembly-CSharp
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
TaxiDispatchSystem is an ECS system responsible for processing taxi service requests (TaxiRequest entities). It runs periodically (GetUpdateInterval returns 16) and performs three main responsibilities:
- Tick and validate TaxiRequest / ServiceRequest state (cooldown, reversed requests, dispatched state).
- Start pathfinding setups for requests that need a route (via PathfindSetupSystem) and attach PathInformation / PathElement buffers to requests.
- Collect finished path results or handler dispatches and enqueue vehicle dispatches, then finalize dispatches to vehicle sources (TransportDepot, Taxi, TaxiStand, RideNeeder) by producing ServiceDispatch buffers or setting ServiceRequest flags.
The system uses two Burst-compiled jobs: - TaxiDispatchJob (IJobChunk): iterates TaxiRequest entities, validates them, schedules pathfind setups, and enqueues vehicle dispatch requests into a NativeQueue. - DispatchVehiclesJob (IJob): dequeues VehicleDispatch items and writes ServiceDispatch buffers or modifies ServiceRequest flags on vehicle sources.
It coordinates with: - EndFrameBarrier for command buffering and job dependency management. - PathfindSetupSystem to obtain a parallel pathfind queue writer. - SimulationSystem for the current frameIndex and update-frame based scheduling.
Fields
-
private EndFrameBarrier m_EndFrameBarrier
Reference to the EndFrameBarrier system used to produce a command buffer (parallel writer) so entity structural changes are applied at the end of the frame. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem used to determine the current simulation frame index and compute the update-frame scheduling. -
private PathfindSetupSystem m_PathfindSetupSystem
Reference to the PathfindSetupSystem which provides a queue writer for enqueuing pathfind setup requests. -
private EntityQuery m_RequestQuery
EntityQuery used to select entities with TaxiRequest and UpdateFrame components; the system RequiresForUpdate on this query so it only runs when taxi requests exist. -
private TypeHandle __TypeHandle
Internal struct used to cache Entity/Component type handles and ComponentLookup/BufferLookup handles used by jobs (set up in OnCreateForCompiler). -
private struct VehicleDispatch
(nested)
Small value struct used to enqueue a pair (request entity, source entity) into the NativeQueue so the DispatchVehiclesJob can apply the dispatch. -
private struct TypeHandle
(nested)
Generated helper that stores EntityTypeHandle, ComponentTypeHandle and ComponentLookup/BufferLookup instances and assigns them via __AssignHandles. -
private struct TaxiDispatchJob
(nested, BurstCompile)
IJobChunk that contains the bulk of request validation, pathfinding setup enqueuing and preparation of vehicle dispatch records. See Methods for behavior details. -
private struct DispatchVehiclesJob
(nested, BurstCompile)
IJob that consumes the VehicleDispatch queue and applies ServiceDispatch buffers or modifies ServiceRequest components on vehicle sources.
Properties
- (none public)
This system exposes no public properties. All state is internal/privately held and driven by ECS jobs.
Constructors
public TaxiDispatchSystem()
Default constructor. The system uses OnCreate to initialize system references and queries. It is marked [Preserve] on lifecycle methods to survive managed code stripping.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 16. The system uses a coarser tick rate (every 16 simulation frames) to spread work over frames. -
[Preserve] protected override void OnCreate()
Initializes references to supporting systems and builds the Request query: - Acquires EndFrameBarrier, SimulationSystem and PathfindSetupSystem via World.GetOrCreateSystemManaged.
-
Creates an EntityQuery for TaxiRequest + UpdateFrame and calls RequireForUpdate(m_RequestQuery) so the system only updates when taxi requests are present.
-
[Preserve] protected override void OnUpdate()
Main scheduling method: - Computes two update frame indices (current index and nextUpdateFrameIndex) based on SimulationSystem.frameIndex to stagger pathfinding/setup and handling.
- Creates a NativeQueue
for cross-job communication. - Prepares and schedules TaxiDispatchJob (IJobChunk) as a parallel chunk job. TaxiDispatchJob:
- Processes chunks whose UpdateFrame shared component matches either the "next" or the "current" index, performing different passes:
- For chunks with index == nextUpdateFrameIndex: validate requests and enqueue pathfind setups (FindVehicleSource or FindVehicleTarget) when ServiceRequest ticks indicate it’s time.
- For chunks with index == m_UpdateFrameIndex: handle chunks that have Dispatched or PathInformation components and either reset/complete requests or produce dispatches (enqueue VehicleDispatch).
- Uses ComponentLookup and BufferLookup to safely read/write related data like Taxi, TaxiStand, TransportDepot, RideNeeder, ParkedCar, Owner, CurrentRoute and dispatch buffers.
- Writes structural changes (add/remove components, destroy entity) via the EndFrameBarrier command buffer (as parallel writer).
- Prepares and schedules DispatchVehiclesJob (IJob) that dequeues VehicleDispatch items and:
- If the source has a ServiceDispatch buffer, adds a ServiceDispatch entry.
- Otherwise, if the source has a ServiceRequest component, sets the SkipCooldown flag on it so the source gets considered quickly.
-
Adds job dependencies to PathfindSetupSystem and EndFrameBarrier and sets base.Dependency appropriately. The NativeQueue is disposed with the final job handle.
-
protected override void OnCreateForCompiler()
Internal helper that assigns the queries and prepares the TypeHandle handles (__AssignQueries and __TypeHandle.__AssignHandles). -
private void __AssignQueries(ref SystemState state)
Auto-generated stub used at compile-time to assist handle assignment (no runtime logic in the decompiled code other than creating/disposing a temporary EntityQueryBuilder). -
(Nested Job methods – summaries)
- TaxiDispatchJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Primary chunk processing; does validation, pathfind setup enqueues, dispatch enqueues, component additions/removals and entity destruction when requests are invalid. -
DispatchVehiclesJob.Execute()
Dequeues VehicleDispatch items and writes ServiceDispatch buffers or updates ServiceRequest components on vehicle sources. -
(Core validation & helpers inside TaxiDispatchJob)
- ValidateReversed(Entity entity, Entity source)
Validates reversed requests where a vehicle (Taxi or TransportDepot) initiates a return to a request; ensures vehicle/depot is available and sets component target request where appropriate. - ValidateHandler(Entity entity, Entity handler)
Verifies whether a given handler (entity) actually has a ServiceDispatch that references the request. - ValidateTarget(Entity entity, Entity target, bool dispatched)
Validates taxi target entities such as TaxiStand or RideNeeder; ensures stand requires vehicles, checks existing taxi/taxi-request conflicts, and assigns TaxiStand.m_TaxiRequest or RideNeeder.m_RideRequest when appropriate. - ResetReverseRequest(int jobIndex, Entity entity, PathInformation pathInformation, ref ServiceRequest serviceRequest)
Enqueues a VehicleDispatch for the reverse dispatch and resets the ServiceRequest state, removing PathInformation component. - ResetFailedRequest(int jobIndex, Entity entity, bool dispatched, ref ServiceRequest serviceRequest)
Resets the ServiceRequest after a failed pathfind/dispatch and removes PathInformation/PathElement and possibly Dispatched components. - DispatchVehicle(int jobIndex, Entity entity, PathInformation pathInformation)
Prepares a VehicleDispatch using the PathInformation.m_Origin (handles parked car owner resolution) and tags the TaxiRequest entity with Dispatched(origin). - FindVehicleSource(...) and FindVehicleTarget(...)
Create PathfindParameters and SetupQueueTarget objects and enqueue SetupQueueItem instances into PathfindSetupSystem’s queue. Also add PathInformation (and PathElement buffer for source-seeking requests) to the request entity.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical setup performed by the system itself; modders can inspect or depend on the system
m_EndFrameBarrier = World.GetOrCreateSystemManaged<EndFrameBarrier>();
m_PathfindSetupSystem = World.GetOrCreateSystemManaged<PathfindSetupSystem>();
m_RequestQuery = GetEntityQuery(ComponentType.ReadOnly<TaxiRequest>(), ComponentType.ReadOnly<UpdateFrame>());
RequireForUpdate(m_RequestQuery);
}
Notes for modders: - TaxiDispatchSystem is an internal game system that coordinates taxi routing and dispatch. If you add or modify TaxiRequest, ServiceRequest, PathInformation, Dispatched, or related components (TaxiStand, Taxi, TransportDepot, RideNeeder), ensure compatibility with the system’s expectations (flags, buffer layouts and lifecycle). - The system uses UpdateFrame shared components to stagger work; tampering with UpdateFrame or frame scheduling can change when requests are processed. - If you enqueue your own ServiceDispatch entries or modify ServiceRequest flags on vehicle sources, you can integrate with the system’s dispatch mechanics (e.g., setting SkipCooldown to force faster response). - Many operations occur inside Burst jobs with ComponentLookup/BufferLookup: prefer using the same ComponentLookup patterns when writing complementary jobs to avoid race conditions and ensure you set up proper job dependencies with EndFrameBarrier and PathfindSetupSystem.