Game.Pathfind.LanePoliciesSystem
Assembly: Assembly-CSharp.dll
Namespace: Game.Pathfind
Type: class
Base: GameSystemBase
Summary:
LanePoliciesSystem listens for policy modification events (city / district / building policy changes) and marks affected lane entities so the pathfinding system can re-evaluate them. It inspects policy changes (Modify components), computes which districts or buildings require lane checks (parking, car, pedestrian/ transit), then schedules two Burst jobs:
- CheckDistrictLanesJob (IJobChunk) — scans BorderDistrict entities and their SubLane buffers to mark sub-lanes that match the required lane types.
- CheckBuildingLanesJob (IJobParallelFor) — walks building sub-objects/sub-nets/sub-lanes to mark parking/garage lanes near modified buildings.
Marking is done by adding a PathfindUpdated component to lane entities through a ModificationBarrier (EntityCommandBuffer) so later systems can process the updates. The system also supports global city-wide policy checks that can mark all car or parking lanes via queries.
Fields
-
private ModificationBarrier5 m_ModificationBarrier
Responsible for producing EntityCommandBuffers used to add PathfindUpdated components safely from jobs. The barrier also receives job handles so playback waits for scheduled jobs. -
private EntityQuery m_PolicyModifyQuery
Query that selects Modify components (policy modifications). The system requires this query to run and reads the Modify component data in OnUpdate. -
private EntityQuery m_LaneOwnerQuery
Query selecting entities that own lanes: entities with BorderDistrict and SubLane buffers (and not Temp/Updated/Deleted). Used to schedule CheckDistrictLanesJob. -
private EntityQuery m_CarLaneQuery
Query matching all car lane entities that are candidates for a global car-lane update (used when a city-wide policy affects all car lanes). -
private EntityQuery m_ParkingLaneQuery
Query matching all parking lane entities used for global parking-lane updates. -
private TypeHandle __TypeHandle
Struct that caches ComponentTypeHandle / BufferTypeHandle / ComponentLookup / BufferLookup instances used by the jobs. Assigned with __AssignHandles for the current SystemState. -
(Nested)
private enum LaneCheckMask
Mask used internally to represent which lane categories must be rechecked: ParkingUnknown = 1, CarUnknown = 2, PedestrianUnknown = 4. -
(Nested)
private struct CheckDistrictLanesJob
Burst compiled IJobChunk that iterates BorderDistrict chunks and their SubLane buffers, checks lane component types (parking, car, pedestrian) and issues PathfindUpdated via a parallel command buffer for matching sub-lanes. -
(Nested)
private struct CheckBuildingLanesJob
Burst compiled IJobParallelFor that iterates a list of buildings to check, traverses their sub-nets/sub-objects/sub-lanes and issues PathfindUpdated for parking/garage lanes found. -
(Nested)
private struct TypeHandle
Holds ComponentTypeHandle / BufferTypeHandle / ComponentLookup / BufferLookup fields and provides __AssignHandles(ref SystemState) to initialize them.
Properties
- (No public properties)
This system does not expose public properties. All state is managed internally and coordinated through EntityQueries, command buffers and job scheduling.
Constructors
public LanePoliciesSystem()
Default constructor. The system is constructed by the ECS world; initialization occurs in OnCreate.
Methods
protected override void OnCreate()
Creates or retrieves the ModificationBarrier5, sets up EntityQueries used by the system:- m_PolicyModifyQuery -> Modify components (required for update)
- m_LaneOwnerQuery -> BorderDistrict + SubLane buffers (exclude Temp/Updated/Deleted)
- m_CarLaneQuery -> Game.Net.CarLane (exclude Temp/Updated/Deleted)
-
m_ParkingLaneQuery -> Game.Net.ParkingLane (exclude Temp/Updated/Deleted) Requires m_PolicyModifyQuery for updates so the system only runs when policy modifications are present.
-
protected override void OnUpdate()
Main logic: - Reads all Modify components (policy modifications) into a temporary NativeArray.
- For each Modify entry, determines what lane categories must be rechecked:
- City-level options (CityOptionData / CityModifierData) → may set CarUnknown / ParkingUnknown globally.
- District-level options (DistrictOptionData / DistrictModifierData) → per-district LaneCheckMask collected into a NativeParallelHashMap
. - Building-level options (BuildingOptionData / BuildingModifierData) → buildings needing parking checks are collected into a NativeList
.
- If city-level masks require global update, adds PathfindUpdated to matching queries (car or parking) using an EntityCommandBuffer from the ModificationBarrier.
- If any districts need checking, schedules CheckDistrictLanesJob (IJobChunk) over m_LaneOwnerQuery; it will add PathfindUpdated to matching sub-lanes.
- If any buildings need checking, schedules CheckBuildingLanesJob (IJobParallelFor) to walk building sub-nets/objects and mark parking/garage sub-lanes.
-
Disposes temporary Native containers with correct job dependencies and registers job handles with the ModificationBarrier so command buffer playback waits for producer jobs.
-
protected override void OnCreateForCompiler()
Compiler-time helper used to ensure queries and handles are assigned when compiled with il2cpp/Burst. Calls __AssignQueries and __TypeHandle.__AssignHandles. -
private void __AssignQueries(ref SystemState state)
Internal helper (inlined) — used at compile-time to construct/assign any EntityQuery state the system expects (kept minimal in this decompiled form). -
private struct CheckDistrictLanesJob.Execute(...)
Implementation of the chunk job: for each BorderDistrict it composes lane masks from the check-district map, iterates the district's SubLane buffer and adds PathfindUpdated to matching lane types (checked via ComponentLookup.HasComponent). -
private struct CheckBuildingLanesJob.Execute(int index)
Walks building entries provided by m_CheckBuildings and delegates to helper methods that recursively traverse sub-objects, sub-nets and sub-lanes to find parking and garage lanes. Adds PathfindUpdated for each matching lane.
Notes on threading & safety: - Jobs are Burst-compiled and use ComponentLookup/BufferLookup handles obtained from __TypeHandle. - AddComponent calls are performed via an EntityCommandBuffer.ParallelWriter produced by the ModificationBarrier to be safe from job threads. - Temporary Native containers (NativeParallelHashMap, NativeList, NativeArray) are disposed with job dependencies to avoid race conditions.
Usage Example
// Example: trigger a policy modification so LanePoliciesSystem will process affected lanes.
// This shows how a mod could create a Modify component entity — the system will pick it up in OnUpdate.
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
// Suppose districtEntity is the district entity and policyEntity is the policy entity you applied/changed.
Entity modifyEntity = em.CreateEntity();
em.AddComponentData(modifyEntity, new Modify {
m_Entity = districtEntity,
m_Policy = policyEntity
});
// After this is created, LanePoliciesSystem will run (it requires Modify entries) and schedule
// jobs that add PathfindUpdated to affected lanes. Those lanes will then be re-evaluated by
// downstream pathfinding systems.
(Notes: Types like Modify, PathfindUpdated, ModificationBarrier5 and many internal component types are game-internal ECS types. When modding, use the game's provided APIs and be mindful of threading / world access constraints.)