Skip to content

Game.LaneBlockSystem

Assembly: Assembly-CSharp
Namespace: Game.Objects

Type: class

Base: GameSystemBase

Summary:
LaneBlockSystem is an entities/system implementation that detects which net lanes are "blocked" by in-world placed objects (e.g., props, buildings, or other objects that intersect lanes). It scans entities that have a BlockedLane buffer and a Transform (and Created/Updated/Deleted tags), queries the net search quadtree, and writes BlockedLane entries and lane-object mappings via a LaneObjectUpdater/LaneObjectCommandBuffer. The heavy-lifting is performed inside a Burst-compiled FindBlockedLanesJob which iterates nearby sub-lanes and computes precise proximity along Bezier curves to record blocked lane segments. The system integrates with Game.Net.SearchSystem to read the net search tree in a job-friendly way.


Fields

  • private Game.Net.SearchSystem m_NetSearchSystem
    Used to obtain a read-only NativeQuadTree of network geometry (sub-lanes) for spatial queries. The system registers itself as a reader while the job runs.

  • private EntityQuery m_ObjectQuery
    An EntityQuery that matches entities with a BlockedLane buffer and a Transform component, and any of the Created/Updated/Deleted tags, excluding Vehicle and Temp. Required for the system to run.

  • private LaneObjectUpdater m_LaneObjectUpdater
    Helper/updater that collects lane-object mapping changes produced by the job (LaneObjectCommandBuffer) and applies them to the global lane-object registry.

  • private TypeHandle __TypeHandle
    Generated type handle container for all Component/Buffer/Entity type handles used when scheduling the FindBlockedLanesJob. Assigned in OnCreateForCompiler.

(Additionally the system defines a nested Burst-compiled job type FindBlockedLanesJob and nested TypeHandle struct; those are internal to the system job scheduling and execution.)

Properties

  • (None public on this system)

Constructors

  • public LaneBlockSystem()
    Default constructor. The system is also initialized further in OnCreate.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system: obtains the Game.Net.SearchSystem instance, sets up the m_ObjectQuery to match objects with BlockedLane + Transform and Created/Updated/Deleted tags (excluding Vehicle and Temp), creates the LaneObjectUpdater and marks the query as required for update.

  • protected override void OnUpdate() : System.Void
    Creates and schedules the Burst-compiled FindBlockedLanesJob (JobChunk) to process all matching entities in parallel. The job:

  • Gets the net search tree (m_NetSearchSystem.GetNetSearchTree) and a LaneObjectCommandBuffer from m_LaneObjectUpdater.Begin.
  • For created entities, it computes blocked lanes and appends them to the BlockedLane buffer.
  • For deleted entities, it removes lane-object mappings for previously recorded blocked lanes.
  • For updated entities, it clears and recomputes blocked lanes. After scheduling it registers the job as a reader of the net search tree, and calls m_LaneObjectUpdater.Apply to apply collected mapping changes, updating the system's base.Dependency with the returned handle.

  • protected override void OnCreateForCompiler() : System.Void
    Compiler-time initialization helper that assigns internal query handles and component lookups via __AssignQueries and __TypeHandle.__AssignHandles. (Used for generated type handle wiring.)

  • private void __AssignQueries(ref SystemState state) : System.Void
    Internal helper used by OnCreateForCompiler to set up/validate queries for the compiler; minimal work in this implementation.

Nested types & job details (summary): - FindBlockedLanesJob (BurstCompile, implements IJobChunk)
- Iterates matching archetype chunks. For each entity: - If the Created tag is present, adds blocked lanes. - If the Deleted tag is present, removes previously recorded lane mappings. - Otherwise, recomputes blocked lanes. - Uses a FindBlockedLanesIterator that implements a quad-tree iterator interface; the iterator: - Computes object bounds using ObjectUtils.CalculateBounds(transform). - Iterates nearby net sub-lanes via m_NetSearchTree.Iterate(ref iterator). - For each sub-lane that is a physical lane (non-master lane), it fetches the sub-lane's Bezier curve, prefab lane data (width), and performs precise distance tests to determine intersection with the object's effective radius. - If intersection occurs, clamps the t-interval along the Bezier to the overlapping segment and appends a BlockedLane (subLane Entity + float2(tMin, tMax)) to the object's buffer and to the LaneObjectCommandBuffer.

Important notes: - The job is Burst-compiled for performance and uses component lookups and buffer lookups to avoid accidental structural changes inside the job. - The net search tree is accessed read-only and the system registers a reader to the search system while the job is in flight.

Usage Example

// Typical usage: the LaneBlockSystem runs automatically each ECS tick.
// To create an object entity that will be considered by the system, add
// a BlockedLane dynamic buffer, a Transform and a PrefabRef, and tag it (Created/Updated) as needed.

EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;

// Create an entity archetype (example)
EntityArchetype archetype = em.CreateArchetype(
    typeof(Transform),
    typeof(PrefabRef),
    typeof(DynamicBuffer<BlockedLane>),
    typeof(Created) // mark as newly created so the system computes blocked lanes
);

// Instantiate entity and set components
Entity obj = em.CreateEntity(archetype);
em.SetComponentData(obj, new Transform { m_Position = new float3(10f, 0f, 20f), m_Rotation = quaternion.identity });
em.SetComponentData(obj, new PrefabRef { m_Prefab = myPrefabEntity });

// After creation, LaneBlockSystem's OnUpdate will discover this entity (via the query),
// run FindBlockedLanesJob and append BlockedLane entries to the object's BlockedLane buffer,
// and also populate internal lane-object mappings via LaneObjectUpdater.

If you need more detail on any nested type (FindBlockedLanesJob, FindBlockedLanesIterator) or the exact math used to clamp lane t-ranges, tell me which part you want expanded and I will document it.