Game.Routes.BoardingVehicleSystem
Assembly:
Assembly-CSharp
Namespace:
Game.Routes
Type:
class
Base:
GameSystemBase
Summary:
BoardingVehicleSystem is an ECS system that keeps BoardingVehicle components consistent with the route/waypoint data. It schedules a Burst-compiled IJobChunk (BoardingVehicleJob) which iterates over entities that have a BoardingVehicle component and clears the m_Vehicle reference when the referenced vehicle is no longer valid for the stop. A vehicle is considered valid if its Target component points to the stop or its target is connected back to the stop via a Connected component. The system reacts to waypoint updates/deletions and runs after game load to validate existing boarding references.
Fields
-
private EntityQuery m_WaypointQuery
Used to detect changes to Waypoint entities (Updated or Deleted). When this query is non-empty the system executes the validation job so boarding references can be cleared for affected stops. -
private EntityQuery m_BoardingQuery
Query that matches entities with a BoardingVehicle component (read/write). The system requires this query for update; the job schedules over this query to validate/clear m_Vehicle. -
private bool m_Loaded
Flag set to true in OnGameLoaded(Context). Used once to force a validation pass immediately after a game load. -
private TypeHandle __TypeHandle
Container struct that holds EntityTypeHandle, ComponentTypeHandle, and ComponentLookup , ComponentLookup . Populated in OnCreateForCompiler via __AssignHandles; used to obtain job handles/lookups for the BoardingVehicleJob. -
private struct TypeHandle
(nested)
Holds the various type/lookup handles and provides __AssignHandles(ref SystemState) to initialize them from a SystemState. -
private struct BoardingVehicleJob
(nested, [BurstCompile])
IJobChunk that performs the per-chunk validation of BoardingVehicle components. Uses EntityTypeHandle, ComponentTypeHandle, and read-only ComponentLookup and ComponentLookup .
Properties
- None (no public properties are declared on this system)
Constructors
public BoardingVehicleSystem()
Default parameterless constructor (preserved attribute present in source). No custom construction logic beyond base.
Methods
protected override void OnCreate()
Initializes the system queries:- m_WaypointQuery: All Waypoint, Any Updated or Deleted — watches waypoint changes.
-
m_BoardingQuery: read-write BoardingVehicle components — required for update. Registers the system to require m_BoardingQuery for updates.
-
protected override void OnGameLoaded(Context serializationContext)
Called when a game is loaded; sets m_Loaded = true to force a validation pass on next update. -
private bool GetLoaded()
Helper that returns true once after a load. It returns the current m_Loaded value and clears it (sets false) when true. Used to ensure validation runs once immediately after loading. -
protected override void OnUpdate()
Main update: if GetLoaded() is true (one-time post-load) or m_WaypointQuery reports changes, schedules the BoardingVehicleJob in parallel over m_BoardingQuery. The job will validate and clear invalid m_Vehicle references. The method composes the job's handles/lookups from __TypeHandle using internal compiler interfaces and attaches the returned JobHandle to the system Dependency. -
private void __AssignQueries(ref SystemState state)
Compiler helper called from OnCreateForCompiler; the implementation shown disposes a temporary EntityQueryBuilder. Present primarily for compiler-generated setup. -
protected override void OnCreateForCompiler()
Called by generated code to initialize query/type handles: calls __AssignQueries and __TypeHandle.__AssignHandles to populate handles needed by the job. -
BoardingVehicleJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Per-chunk loop: obtains arrays for Entity and BoardingVehicle, iterates entries and: -
If BoardingVehicle.m_Vehicle != Entity.Null and IsValidBoarding(...) returns false then clears the m_Vehicle (sets to Entity.Null) and writes back the component. This method is marked with [BurstCompile] (on the struct) for performance.
-
BoardingVehicleJob.IsValidBoarding(Entity stop, Entity vehicle) : bool
Validation logic used by the job: - Tries to get Target component for the vehicle. If vehicle.Target == stop => valid.
- Otherwise, tries to get Connected component from vehicle.Target: if connected.m_Connected == stop => valid.
-
Otherwise returns false.
-
BoardingVehicleJob.IJobChunk.Execute(...)
Explicit interface implementation that forwards to the struct's Execute method.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Create queries similar to the system's setup:
m_WaypointQuery = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[1] { ComponentType.ReadOnly<Waypoint>() },
Any = new ComponentType[2]
{
ComponentType.ReadOnly<Updated>(),
ComponentType.ReadOnly<Deleted>()
}
});
m_BoardingQuery = GetEntityQuery(ComponentType.ReadWrite<BoardingVehicle>());
RequireForUpdate(m_BoardingQuery);
}
Notes and tips: - The validation job is Burst-compiled and uses ComponentLookup (component lookups) so it is efficient and safe to run in parallel. Ensure the component types (Target, Connected, BoardingVehicle) are kept up to date elsewhere to avoid false clears. - The system is driven by waypoint changes or a one-time post-load pass; if you modify other route-related data that might affect validity, make sure to update Waypoint (Updated) or otherwise trigger this system to run.