Game.Simulation.PrisonerTransportDispatchSystem
Assembly: Game
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
Handles dispatching of prisoner transport requests. This system processes PrisonerTransportRequest entities, validates request sources/targets (police stations, prisons, public transport), queues pathfinding setup for finding vehicle sources/targets, and enqueues vehicle dispatches to be executed at end of frame. It uses two jobs: a chunk job (PrisonerTransportDispatchJob) to inspect and prepare requests and pathfinding, and a single-threaded job (DispatchVehiclesJob) to attach dispatch records or set skip-cooldown flags on vehicle sources. The system integrates with PathfindSetupSystem for route setup and EndFrameBarrier for safe command buffer execution. It runs on a coarse interval (GetUpdateInterval returns 16).
Fields
-
private EndFrameBarrier m_EndFrameBarrier
Used to create a parallel EntityCommandBuffer and to register job producer dependencies so structural changes happen safely at the end of frame. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem to read the current simulation frame index needed to partition work across update frames. -
private PathfindSetupSystem m_PathfindSetupSystem
Reference to the pathfinding setup system where pathfind requests are enqueued (m_PathfindQueue). -
private EntityQuery m_RequestQuery
Query matching entities with PrisonerTransportRequest and UpdateFrame used to drive the system (RequireForUpdate is called with this query). -
private TypeHandle __TypeHandle
Compiler-generated wrapper that stores all the Entity/Component/Buffer/Shared component handles this system uses. Assigned in OnCreateForCompiler.
Additional nested types (not fields) of importance:
- private struct VehicleDispatch
Simple container pairing a request entity with a vehicle source entity for dispatching later.
-
private struct TypeHandle
Contains EntityTypeHandle, ComponentTypeHandles, ComponentLookup and BufferLookup members and an __AssignHandles method used to initialize them from SystemState. -
private struct PrisonerTransportDispatchJob : IJobChunk
(Burst compiled)
Chunk job that inspects request chunks, validates, schedules pathfinding, sets/removes PathInformation/PathElement/Dispatched components, and enqueues VehicleDispatch items into a NativeQueue for later processing. -
private struct DispatchVehiclesJob : IJob
(Burst compiled)
Consumes the NativeQueueand writes ServiceDispatch buffers to vehicle entities or marks ServiceRequest on vehicle entities to force a vehicle-side reaction.
Properties
- None (the system exposes no public properties)
Constructors
public PrisonerTransportDispatchSystem()
Default parameterless constructor (preserved).
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 16. Indicates this system runs at a coarse frequency (once per 16 simulation frames partitioned by frame index). -
[Preserve] protected override void OnCreate()
Initializes references to EndFrameBarrier, SimulationSystem, PathfindSetupSystem; constructs the entity query for PrisonerTransportRequest + UpdateFrame and calls RequireForUpdate to ensure system runs only if there are matching requests. -
[Preserve] protected override void OnUpdate()
Main scheduling method: - Computes a per-frame partition index from SimulationSystem.frameIndex to split work across subframes.
- Creates a NativeQueue
for cross-job communication. - Sets up PrisonerTransportDispatchJob with many component lookups/handles and writes to PathfindSetupSystem queue and EndFrameBarrier CommandBuffer.
- Schedules the chunk job (parallel), then schedules DispatchVehiclesJob which dequeues and applies ServiceDispatch entries (single-threaded).
-
Disposes the NativeQueue with the combined job dependency, registers the pathfind queue writer and EndFrameBarrier producer, and stores the job handle into base.Dependency.
-
protected override void OnCreateForCompiler()
Compiler helper that assigns internal handles and queries used by generated code. -
private void __AssignQueries(ref SystemState state)
Compiler-generated stub for query assignment; invoked by OnCreateForCompiler.
PrisonerTransportDispatchJob internal methods (key responsibilities):
- Execute(in ArchetypeChunk chunk, ...)
Processes three main phases depending on the chunk's UpdateFrame shared component index:
- If index == nextUpdateFrameIndex: validate/advance service request state and enqueue pathfind setups (FindVehicleSource / FindVehicleTarget) or destroy invalid requests.
- If index == updateFrameIndex: handle Dispatched components to check whether handler recorded the dispatch (ValidateHandler) and manage cooldowns, or handle PathInformation results to either enqueue VehicleDispatch (DispatchVehicle / ResetReverseRequest) or reset failed requests (ResetFailedRequest).
- ValidateReversed(Entity entity, Entity source)
Validates a reversed request (vehicle -> destination). Ensures a Prison has available vans or PublicTransport is idle and not parked, and registers the request as the target on the source entity.
- ValidateHandler(Entity entity, Entity handler)
Checks if the handler (vehicle/building) has a ServiceDispatch buffer entry for this request.
- ValidateTarget(Entity entity, Entity target)
Ensures target is a PoliceStation needing prisoner transport and registers the request on the police station.
- ResetReverseRequest(int jobIndex, Entity entity, PathInformation pathInformation, ref ServiceRequest serviceRequest)
Enqueues VehicleDispatch with pathInformation.m_Destination and resets the service request as a reverse request; removes PathInformation component.
- ResetFailedRequest(int jobIndex, Entity entity, bool dispatched, ref ServiceRequest serviceRequest)
Resets a failed path/service request, removes PathInformation and PathElement components and Dispatched if requested.
- DispatchVehicle(int jobIndex, Entity entity, PathInformation pathInformation)
Resolves parked car ownership to an owner entity if needed, enqueues a VehicleDispatch pair, and adds a Dispatched component on the request with the chosen vehicle source.
- FindVehicleSource(int jobIndex, Entity requestEntity, Entity target)
Builds pathfinding parameters and enqueues a SetupQueueItem to find a vehicle source for the given police station target; adds PathInformation and PathElement buffer on the request entity.
- FindVehicleTarget(int jobIndex, Entity requestEntity, Entity vehicleSource)
Builds pathfinding parameters and enqueues a SetupQueueItem to find the police station target from a vehicle source; adds PathInformation on the request entity. If vehicleSource is PublicTransport and not returning, marks origin as PathEnd.
DispatchVehiclesJob internal behavior:
- Execute()
Dequeues VehicleDispatch items; for each, if the source has a ServiceDispatch buffer, append a ServiceDispatch entry referencing the request; otherwise, if the source has a ServiceRequest component, set SkipCooldown on it to accelerate handling.
Notes: - The system heavily uses ComponentLookup/BufferLookup and shared UpdateFrame to partition processing across frames. - Structural changes (Add/Remove/Destroy entity) are recorded via EndFrameBarrier command buffer (parallel writer) to be applied later. - Pathfinding entries are pushed into PathfindSetupSystem using its queue writer.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization done by the system:
m_EndFrameBarrier = base.World.GetOrCreateSystemManaged<EndFrameBarrier>();
m_SimulationSystem = base.World.GetOrCreateSystemManaged<SimulationSystem>();
m_PathfindSetupSystem = base.World.GetOrCreateSystemManaged<PathfindSetupSystem>();
m_RequestQuery = GetEntityQuery(ComponentType.ReadOnly<PrisonerTransportRequest>(), ComponentType.ReadOnly<UpdateFrame>());
RequireForUpdate(m_RequestQuery);
}
If you want, I can also produce a shorter quick-reference listing (method signatures and brief one-line descriptions) or a UML-like summary of the nested job types and dataflow.