Game.Pathfind.ParkingLaneDataSystem
Assembly: Assembly-CSharp
Namespace: Game.Pathfind
Type: class
Base: GameSystemBase
Summary:
ParkingLaneDataSystem is an ECS system responsible for updating parking-related lane data each frame (or when entities are marked Updated/PathfindUpdated). It iterates over parking lanes, garage lanes and certain spawn locations and computes values such as free space, vehicle counts, parking fees, comfort factors and various access flags. The heavy lifting is performed inside a Burst-compiled IJobChunk (UpdateLaneDataJob) which reads many prefab/component lookups and uses a moving-object search tree to count parked vehicles and trains. The system also interacts with the City and Object search systems to retrieve city modifiers and the moving object search tree used for parked vehicle queries.
Fields
-
private Game.Objects.SearchSystem m_ObjectSearchSystem
The search system used to retrieve the moving-object search tree for counting parked/moving objects in the Update job. -
private CitySystem m_CitySystem
Reference to the CitySystem used to get the current city entity and associated city modifiers/options (e.g. taxi starting fee). -
private EntityQuery m_LaneQuery
EntityQuery used to drive the system update. It matches entities with Updated/PathfindUpdated and any of: ParkingLane, GarageLane or SpawnLocation and excludes Deleted/Temp; this query is required for the system to run. -
private TypeHandle __TypeHandle
Internal struct that stores EntityTypeHandle / ComponentTypeHandle / BufferTypeHandle and ComponentLookup/BufferLookup instances used by the IJobChunk. It is assigned during OnCreateForCompiler and used when scheduling the UpdateLaneDataJob.
Properties
- (none)
This system does not expose public properties.
Constructors
public ParkingLaneDataSystem()
Default constructor. The system relies on OnCreate to initialize references and queries; the constructor itself is effectively empty and preserved for ECS system instantiation.
Methods
-
[Preserve] protected override void OnCreate()
Initializes the system: obtains managed systems (SearchSystem and CitySystem), sets up the m_LaneQuery that drives updates, and calls RequireForUpdate(m_LaneQuery) so the system only runs when matching entities are present. This is where the system prepares the query filter for parking/garage/spawn entities. -
[Preserve] protected override void OnUpdate()
Schedules the Burst-compiled UpdateLaneDataJob (IJobChunk) to run in parallel over m_LaneQuery. The method: - Builds and assigns all required type/lookup handles from __TypeHandle (via InternalCompilerInterface.Get* calls).
- Asks the SearchSystem for a read-only moving object search tree and includes its dependency.
- Schedules the job with JobChunkExtensions.ScheduleParallel and combines dependencies with base.Dependency.
-
Registers the job as a reader of the moving object search tree (m_ObjectSearchSystem.AddMovingSearchTreeReader) and stores the returned JobHandle into base.Dependency so the ECS system will correctly wait for job completion where necessary.
-
protected override void OnCreateForCompiler()
Called by generated/compiled code paths: assigns query handles and invokes __TypeHandle.__AssignHandles for the system state so that type handles are available for the jobs when compiled/stripped. This method is part of the boilerplate used when converting systems into their AOT/Burst-compatible forms. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Internal helper used to populate/validate queries at compile-time / for the generated system. It contains an EntityQueryBuilder call; this method is part of the compiler-generated wiring and typically no user changes are required. -
(Nested) private struct UpdateLaneDataJob : IJobChunk (Burst compiled)
This nested, Burst-compiled job contains the main logic for updating: - Handles three different archetypes in one job: ParkingLane, GarageLane and SpawnLocation.
- For ParkingLane: computes parkingLane.m_FreeSpace by calling CalculateFreeSpace, sets flags (ParkingDisabled, AllowEnter, AllowExit), sets taxi/start fees and parking access restriction, parking fee and comfort from building/prefab/district/prefab parking facility data.
- For GarageLane: obtains garage capacity, comfort and vehicle count via CountVehicles and GetParkingStats; sets ConnectionLane flags accordingly.
- For SpawnLocation (Air/Track): marks spawnLocation.m_Flags with SpawnLocationFlags.ParkedVehicle when vehicles/trains are present.
- Uses a CountVehiclesIterator to query a NativeQuadTree
(moving object search tree) for parked cars/trains, filtering by controller ownership and parked/parked-train components. - Contains helper methods used by the job: GetBlockedRange, GetParkingStats, GetDistrictParkingFee, GetBuildingParkingFee, CountVehicles (two overloads), CalculateFreeSpace. These implement most of the domain logic used to determine fees, capacities, and free space on a lane; they read many lookups/buffers (owners, prefabs, modifiers, installed upgrades, lane objects/overlaps, etc.).
Notes about the job: - It is Burst-compiled for performance and scheduled in parallel. - It reads many component lookups and buffer lookups (marked read-only where applicable) and writes to ParkingLane / ConnectionLane / GarageLane / SpawnLocation components. - The job uses the moving-object search tree obtained from the SearchSystem to count parked vehicles in spatial bounds.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization performed by ParkingLaneDataSystem:
m_ObjectSearchSystem = base.World.GetOrCreateSystemManaged<Game.Objects.SearchSystem>();
m_CitySystem = base.World.GetOrCreateSystemManaged<CitySystem>();
// Construct a query that updates when parking/garage/spawn locations are updated,
// and require it for update so the system only runs when relevant entities change.
m_LaneQuery = GetEntityQuery(new EntityQueryDesc {
All = new ComponentType[] { ComponentType.ReadOnly<Updated>() },
Any = new ComponentType[] {
ComponentType.ReadOnly<Game.Net.ParkingLane>(),
ComponentType.ReadOnly<GarageLane>(),
ComponentType.ReadOnly<Game.Objects.SpawnLocation>()
},
None = new ComponentType[] {
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Temp>()
}
}, new EntityQueryDesc {
All = new ComponentType[] { ComponentType.ReadOnly<PathfindUpdated>() },
Any = new ComponentType[] {
ComponentType.ReadOnly<Game.Net.ParkingLane>(),
ComponentType.ReadOnly<GarageLane>(),
ComponentType.ReadOnly<Game.Objects.SpawnLocation>()
},
None = new ComponentType[] {
ComponentType.ReadOnly<Updated>(),
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Temp>()
}
});
RequireForUpdate(m_LaneQuery);
}
Notes / Modding tips: - The main computation is in UpdateLaneDataJob; when modding you can either: - Replace or patch specific helper methods (e.g. GetBuildingParkingFee, GetDistrictParkingFee) to change fees or behavior, or - Insert an additional job or system that runs after ParkingLaneDataSystem to adjust computed parking values if needed. - Be careful when changing counting logic that uses the moving-object search tree; thread-safety and register/unregister of readers is handled by the SearchSystem and system's job scheduling—mismatches can cause race conditions. - Many values rely on prefab data (ParkingLaneData, ParkingFacilityData, Building modifiers, City modifiers). To change defaults you can modify prefab components or apply modifiers via existing game systems (District/Building/City modifiers).