Skip to content

Game.Simulation.TransportStopSystem

Assembly: Game
Namespace: Game.Simulation

Type: public class

Base: GameSystemBase

Summary:
TransportStopSystem is a simulation system responsible for updating TransportStop components on transport stop entities (bus/tram/metro/boat/taxi stops). It runs at a coarse interval (256 frames) and recalculates each stop's comfort and loading factors from prefab data and any owning TransportStation (if present). When calculated values or active state change, the system enqueues PathfindUpdated components (via an EndFrameBarrier command buffer) on affected stops and on connected route waypoints so pathfinding can react to the change. The work is performed in a Burst-compiled IJobChunk (TransportStopTickJob) and scheduled in parallel.


Fields

  • private const uint UPDATE_INTERVAL = 256u
    UPDATE_INTERVAL used by GetUpdateInterval to control how often this system updates (every 256 frames).

  • private EntityQuery m_StopQuery
    Query selecting entities with Game.Routes.TransportStop (excluding Temp and Deleted) — the set of stops processed by this system.

  • private EndFrameBarrier m_EndFrameBarrier
    Reference to the EndFrameBarrier system used to create a parallel command buffer. The command buffer is used to add PathfindUpdated components to entities at end of frame.

  • private TypeHandle __TypeHandle
    Internal struct used to cache ECS type and buffer handles and component lookups for use inside the job. Assigned in OnCreateForCompiler.

Properties

  • None (this system exposes no public properties).

Constructors

  • public TransportStopSystem()
    Default constructor. System initialization and setup are done in OnCreate/OnCreateForCompiler.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns 256 — the update interval in frames for this system.

{{ YOUR_INFO }} Example: the framework calls this to know the update cadence; the system only needs to process its query once per 256 frames.

  • [Preserve] protected override void OnCreate()
    Initializes the system: obtains EndFrameBarrier, creates the m_StopQuery to select TransportStop entities (excluding Temp and Deleted) and calls RequireForUpdate(m_StopQuery) so the system only runs when there are matching entities.

{{ YOUR_INFO }} Important: m_EndFrameBarrier is used to create a parallel command buffer. The query filters ensure only real (non-temp/non-deleted) transport stops are processed.

  • [Preserve] protected override void OnUpdate()
    Constructs and schedules the Burst-compiled TransportStopTickJob in parallel over m_StopQuery, passing in Entity/Component/Buffer type handles and component lookups from __TypeHandle. The returned JobHandle is registered with m_EndFrameBarrier via AddJobHandleForProducer and assigned to base.Dependency.

{{ YOUR_INFO }} The job: - Reads PrefabRef and optional Prefab TransportStopData to compute base comfort/loading. - Walks owner chain (using Owner component) to find a TransportStation affecting comfort/loading and active state. - Compares computed values with stored Game.Routes.TransportStop values and, if changed, adds PathfindUpdated to the stop (and to any connected route waypoints). For chunks containing a TaxiStand component, the stop entity itself also receives PathfindUpdated. - Updates the TransportStop component's m_ComfortFactor, m_LoadingFactor, and StopFlags.Active bit.

  • private void __AssignQueries(ref SystemState state)
    Internal method used during compiler-driven initialization. In this compiled form it creates (and disposes) an EntityQueryBuilder placeholder. Used by OnCreateForCompiler.

{{ YOUR_INFO }} This is an implementation artifact of the generated system code.

  • protected override void OnCreateForCompiler()
    Compiler/runtime helper that calls __AssignQueries and assigns handles via __TypeHandle.__AssignHandles. Ensures type handles and lookups are prepared for job scheduling.

{{ YOUR_INFO }} Called by framework when the system is constructed by the managed runtime/compiler pipeline.

  • (Nested) private struct TransportStopTickJob : IJobChunk
    Burst-compiled job that executes the per-chunk logic described above. Key behavior:
    • Reads Entity, PrefabRef, Owner, optional TaxiStand, and ConnectedRoute buffers.
    • Uses component lookups to read TransportStopData (prefab) and TransportStation (owner chain).
    • Computes new comfort/loading values and active flag, compares with stored TransportStop component, and issues PathfindUpdated via the provided EntityCommandBuffer.ParallelWriter for entities that need updates.
    • Utility method GetTransportStation(Entity owner) walks the Owner chain to locate a TransportStation entity.

{{ YOUR_INFO }} The job is scheduled with JobChunkExtensions.ScheduleParallel and runs across chunks in parallel with Burst optimizations.

  • (Nested) private struct TypeHandle
    Holds cached EntityTypeHandle, ComponentTypeHandles and ComponentLookup instances required by the job. It has a method __AssignHandles(ref SystemState state) to initialize these handles/read-only settings.

{{ YOUR_INFO }} This struct mirrors how Unity ECS caches type handles to avoid repeated GetComponentTypeHandle/GetBufferTypeHandle calls per update.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Obtain the end-of-frame barrier to push PathfindUpdated via a command buffer
    m_EndFrameBarrier = base.World.GetOrCreateSystemManaged<EndFrameBarrier>();

    // Query all real transport stops (exclude Temp and Deleted)
    m_StopQuery = GetEntityQuery(
        ComponentType.ReadOnly<Game.Routes.TransportStop>(),
        ComponentType.Exclude<Temp>(),
        ComponentType.Exclude<Deleted>()
    );

    // Only run this system if there are matching entities
    RequireForUpdate(m_StopQuery);
}

Additional notes: - The system uses an update interval of 256 frames to reduce frequency of expensive updates. - When changing TransportStop-related prefab data or TransportStation ownership/flags in mods, consider ensuring PathfindUpdated is added so pathfinding reacts — this system demonstrates the canonical way via EndFrameBarrier + ParallelWriter. - TransportStopTickJob marks TaxiStand-containing chunks specially so taxi stands can trigger pathfind updates on their entity directly.