Game.PostVanDispatchSystem
Assembly: Assembly-CSharp (game runtime assembly)
Namespace: Game.Simulation
Type: class
Base: GameSystemBase
Summary:
System responsible for handling post-van dispatch logic. It iterates PostVanRequest entities (with UpdateFrame shared component) and:
- Validates targets (mail producers, mailboxes) and reversed requests (post facilities, post vans).
- Schedules pathfinding setup for requests that need a path (via PathfindSetupSystem queue).
- Processes completed path results (PathInformation) and dispatched handlers (Dispatched) to either enqueue vehicle dispatches or reset failed requests.
- Enqueues vehicle dispatches into a NativeQueue that are consumed by a follow-up job which writes ServiceDispatch buffers or updates ServiceRequest flags.
- Uses Burst-compiled jobs (PostVanDispatchJob as IJobChunk and DispatchVehiclesJob as IJob) for high performance and runs on an interval (GetUpdateInterval returns 16).
Interacts with components/types: PostVanRequest, ServiceRequest, PathInformation, Dispatched, MailProducer, MailBox, PostFacility, PostVan, ParkedCar, Owner, CurrentDistrict, ServiceDispatch and PostConfigurationData. Uses an EndFrameBarrier command buffer to make structural changes safely at end of frame.
Fields
-
private EndFrameBarrier m_EndFrameBarrier
Holds the EndFrameBarrier system used to create an EntityCommandBuffer.Producer for safe structural changes. -
private SimulationSystem m_SimulationSystem
Reference to the SimulationSystem used to read the current simulation frame index. -
private PathfindSetupSystem m_PathfindSetupSystem
Reference to the PathfindSetupSystem used to push pathfinding setup items (SetupQueueItem). -
private EntityQuery m_RequestQuery
Query used to find PostVanRequest entities (and their UpdateFrame shared component) that this system processes. -
private EntityQuery m_PostConfigurationQuery
Query to obtain the singleton PostConfigurationData used to check configuration (e.g. mail accumulation tolerance). -
private TypeHandle __TypeHandle
Struct used to cache and assign Entity/Component/Buffer/Shared component handles/lookups for job access. -
(Nested types as fields are not present; see nested structs in Methods/Implementation summary)
Properties
- (This class exposes no public properties.)
Constructors
public PostVanDispatchSystem()
Default constructor. The system uses OnCreate to initialize its dependencies and queries.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns the system update interval. This system uses an interval of 16 ticks (returns 16) so it runs every 16 simulation frames. -
[Preserve] protected override void OnCreate()
Initializes references: gets EndFrameBarrier, SimulationSystem, PathfindSetupSystem and creates entity queries for PostVanRequest and PostConfigurationData. Calls RequireForUpdate(m_RequestQuery) so the system only runs when there are PostVanRequest entities. -
[Preserve] protected override void OnUpdate()
Main scheduling logic: - Computes the current and next update frame indices from SimulationSystem.frameIndex.
- Creates a NativeQueue
to collect vehicle dispatches from the IJobChunk. - Configures and schedules a Burst-compiled PostVanDispatchJob (IJobChunk) to process PostVanRequest chunks:
- Validates requests (targets or reversed sources).
- If service request ticks, schedules pathfinding (FindVehicleSource / FindVehicleTarget).
- For completed PathInformation or Dispatched components, enqueues vehicle dispatches or resets failed requests.
- Adds/removes PathInformation, PathElement, Dispatched components and uses EntityCommandBuffer.ParallelWriter for structural changes.
- Schedules a Burst-compiled DispatchVehiclesJob (IJob) which dequeues VehicleDispatch entries and either appends ServiceDispatch buffers on source entities or marks a ServiceRequest on the source to skip cooldown.
-
Connects job handles to the PathfindSetupSystem queue and the EndFrameBarrier (producer) and sets base.Dependency to ensure proper ordering and disposal of the NativeQueue.
-
private void __AssignQueries(ref SystemState state)
Internal helper used at compile-time / code-gen to assign queries. The implementation is minimal in the compiled source. -
protected override void OnCreateForCompiler()
Used by the generated/compiled code path to assign queries and component/handle lookups (__TypeHandle.__AssignHandles).
Nested/Burst job types (important behavior summarized):
PostVanDispatchJob : IJobChunk
(BurstCompile)- Read/write access to many component lookups and buffers (PostVanRequest, ServiceRequest, PathInformation, Dispatched, MailProducer, MailBox, PostFacility, PostVan, ParkedCar, Owner, CurrentDistrict, ServiceDispatch buffers, PostConfigurationData).
-
Executed per-chunk. Main responsibilities:
- When chunk's UpdateFrame shared component index == m_NextUpdateFrameIndex: process service request ticking and schedule pathfinding via m_PathfindQueue (FindVehicleSource / FindVehicleTarget) and add PathInformation/PathElement components.
- When chunk has Dispatched components at m_UpdateFrameIndex: verify handler still dispatches the request (ValidateHandler); if not, reset cooldown or reset failed request and remove components.
- When chunk has PathInformation at m_UpdateFrameIndex: if PathInformation contains an origin/destination, either DispatchVehicle (add Dispatched + enqueue VehicleDispatch) or ResetReverseRequest/ResetFailedRequest.
- Validation helpers:
- ValidateReversed: ensures a reversed request's source entity (PostFacility or PostVan) can accept the reversed request and registers the request on the source.
- ValidateTarget: ensures the target (MailProducer or MailBox) has accumulated enough mail and registers the request on the target.
- Pathfinding enqueue helpers:
- FindVehicleSource: builds SetupQueueItem with origin=PostVan (district-based) and destination = CurrentLocation (target).
- FindVehicleTarget: builds SetupQueueItem with origin = CurrentLocation (vehicle source) and destination = PostVanRequest.
- Uses m_CommandBuffer (parallel writer) to add/remove components on request entities and m_VehicleDispatches to enqueue final vehicle dispatches.
-
DispatchVehiclesJob : IJob
(BurstCompile) -
Dequeues VehicleDispatch entries and tries to append a ServiceDispatch buffer to the source entity. If the source has no ServiceDispatch buffer but has a ServiceRequest component, it sets the SkipCooldown flag on that ServiceRequest so the source will be scheduled/considered for dispatch.
-
Helper struct
VehicleDispatch
- Simple pair (m_Request, m_Source) used to communicate which request should be dispatched and from which source entity.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical system initialization performed 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<PostVanRequest>(), ComponentType.ReadOnly<UpdateFrame>());
m_PostConfigurationQuery = GetEntityQuery(ComponentType.ReadOnly<PostConfigurationData>());
RequireForUpdate(m_RequestQuery);
}
Notes and tips for modders: - If you add or change the PostVanRequest flow, keep in mind the job splits behavior across UpdateFrame indexes: one index prepares pathfinding (m_NextUpdateFrameIndex) and another processes results/dispatches (m_UpdateFrameIndex), so timing matters. - When adding components consumed/produced by the jobs (e.g., PathInformation, Dispatched, PathElement), ensure they are compatible with the expected lifecycle (added by the job, removed when failing/finished). - PostConfigurationData.m_MailAccumulationTolerance is used to gate whether a MailProducer/MailBox will create a request — adjust carefully if changing mail accumulation logic. - Use PathfindSetupSystem.GetQueue/AddQueueWriter to safely interact with the pathfinding setup queue when scheduling from systems.