Skip to content

Game.Net.SearchSystem

Assembly: Assembly-CSharp
Namespace: Game.Net

Type: class

Base: GameSystemBase, IPreDeserialize

Summary: SearchSystem maintains spatial search structures (quadtrees) for net entities (edges, nodes, curves) and lanes used by the rendering, tools and selection systems. It builds and updates two NativeQuadTree instances — one for nets (m_NetSearchTree) and one for lanes (m_LaneSearchTree) — by scheduling burst-compiled IJobChunk jobs that iterate entity archetype chunks and insert/update/remove items in the quadtrees. It also exposes API for other systems to acquire read/write dependencies on those trees, and clears/rebuilds them during deserialization (load). This system integrates prefab/geometry metadata, culling info and editor mode to compute bounds, LOD and bounds masks for search queries.


Fields

  • private ToolSystem m_ToolSystem
    {{ YOUR_INFO }}
    Holds a reference to the ToolSystem (used to determine if the editor mode is active). Acquired in OnCreate via World.GetOrCreateSystemManaged().

  • private UndergroundViewSystem m_UndergroundViewSystem
    {{ YOUR_INFO }}
    Reference to UndergroundViewSystem (used for utility type dilation when computing lane layers/visibility).

  • private EntityQuery m_UpdatedNetsQuery
    {{ YOUR_INFO }}
    EntityQuery used to find edges/nodes that have been updated or deleted (used when not doing a full rebuild).

  • private EntityQuery m_UpdatedLanesQuery
    {{ YOUR_INFO }}
    EntityQuery used to find lanes that have been updated or deleted.

  • private EntityQuery m_AllNetsQuery
    {{ YOUR_INFO }}
    EntityQuery matching all net-related entities (edges or nodes) for full rebuilds (load path).

  • private EntityQuery m_AllLanesQuery
    {{ YOUR_INFO }}
    EntityQuery matching all lanes (lane geometry or parking lane) for full rebuilds (load path).

  • private NativeQuadTree<Entity, QuadTreeBoundsXZ> m_NetSearchTree
    {{ YOUR_INFO }}
    QuadTree storing net entities (Edge/Node/Curve/Geometry). Backing data structure updated by UpdateNetSearchTreeJob. Allocated with Allocator.Persistent in OnCreate and disposed in OnDestroy.

  • private NativeQuadTree<Entity, QuadTreeBoundsXZ> m_LaneSearchTree
    {{ YOUR_INFO }}
    QuadTree storing lane entities (lanes/parking lanes). Backing data structure updated by UpdateLaneSearchTreeJob.

  • private JobHandle m_NetReadDependencies
    {{ YOUR_INFO }}
    Aggregated JobHandle for jobs that read the net search tree. Used to chain dependencies when other systems request read access.

  • private JobHandle m_NetWriteDependencies
    {{ YOUR_INFO }}
    JobHandle representing the most recent writer to the net search tree (writer dependency).

  • private JobHandle m_LaneReadDependencies
    {{ YOUR_INFO }}
    Aggregated JobHandle for jobs that read the lane search tree.

  • private JobHandle m_LaneWriteDependencies
    {{ YOUR_INFO }}
    JobHandle representing the most recent writer to the lane search tree.

  • private bool m_Loaded
    {{ YOUR_INFO }}
    Flag set during PreDeserialize to trigger a full rebuild of both quadtrees on the following update. GetLoaded() consumes the flag.

  • private TypeHandle __TypeHandle
    {{ YOUR_INFO }}
    Internal struct holding component/entity type handles and ComponentLookup objects used by the IJobChunk jobs. Populated in OnCreateForCompiler/__AssignHandles.

  • private struct UpdateNetSearchTreeJob
    {{ YOUR_INFO }}
    Burst-compiled IJobChunk that iterates net-related archetype chunks and adds/updates/removes entries in the net quad tree. It reads many component types (EdgeGeometry, NodeGeometry, Composition, Orphan, Node, Curve, Marker, Created, Deleted, CullingInfo) and component lookups for prefab composition/mesh data to compute bounds, bounds masks and LOD.

  • public struct UpdateLaneSearchTreeJob
    {{ YOUR_INFO }}
    Burst-compiled IJobChunk that iterates lane archetype chunks and adds/updates/removes entries in the lane quad tree. It reads Curve, Owner, UtilityLane, PrefabRef and uses component lookups for lane geometry / utility lane / net data to compute bounds, layers and LOD. Note: declared public to be scheduled by the system.

  • private struct TypeHandle
    {{ YOUR_INFO }}
    Holds the per-frame EntityTypeHandle, ComponentTypeHandle (read-only) and ComponentLookup used by the jobs. Has an __AssignHandles method to bind handles from a SystemState.


Properties

  • None (no public properties exposed).
    {{ YOUR_INFO }}
    The system exposes functionality via public methods to get quadtrees and manage job dependencies, rather than via properties.

Constructors

  • public SearchSystem()
    {{ YOUR_INFO }}
    Default constructor. The system uses the ECS lifecycle methods (OnCreate, OnUpdate, OnDestroy, PreDeserialize) to initialize and manage state.

Methods

  • protected override void OnCreate()
    {{ YOUR_INFO }}
    Initializes queries, acquires references to ToolSystem and UndergroundViewSystem, and constructs the NativeQuadTree instances (m_NetSearchTree and m_LaneSearchTree). Called by the ECS when the system is created. Uses GetEntityQuery to prepare the updated/all queries and allocates NativeQuadTree with an initial cell size of 1f.

  • protected override void OnDestroy()
    {{ YOUR_INFO }}
    Disposes the NativeQuadTree instances and calls base.OnDestroy().

  • private bool GetLoaded()
    {{ YOUR_INFO }}
    Helper that returns true once if m_Loaded is set and clears the flag (consumes the loaded state). Used in OnUpdate to trigger full rebuilds after deserialization.

  • protected override void OnUpdate()
    {{ YOUR_INFO }}
    Main scheduling method. Determines whether nets/lanes need updates (either partial updates or full rebuild after load), prepares and schedules UpdateNetSearchTreeJob and/or UpdateLaneSearchTreeJob via JobChunkExtensions.Schedule, passes in the proper Entity/Component type handles and ComponentLookup references, and records write dependencies using AddNetSearchTreeWriter/AddLaneSearchTreeWriter. The scheduled jobs fill/update/remove entries in the quadtrees. Finally, it combines job handles and assigns base.Dependency.

  • public NativeQuadTree<Entity, QuadTreeBoundsXZ> GetNetSearchTree(bool readOnly, out JobHandle dependencies)
    {{ YOUR_INFO }}
    Returns a reference to the net search tree. Also outputs a JobHandle representing the dependencies a caller must respect before accessing the tree. If readOnly is true, the dependency returned is the current net writer (m_NetWriteDependencies); otherwise the combined read+write dependencies are returned.

  • public NativeQuadTree<Entity, QuadTreeBoundsXZ> GetLaneSearchTree(bool readOnly, out JobHandle dependencies)
    {{ YOUR_INFO }}
    Same as GetNetSearchTree but for the lane search tree.

  • public void AddNetSearchTreeReader(JobHandle jobHandle)
    {{ YOUR_INFO }}
    Register a job handle as a reader of the net search tree; it will be combined into m_NetReadDependencies to prevent writers from starting early.

  • public void AddNetSearchTreeWriter(JobHandle jobHandle)
    {{ YOUR_INFO }}
    Set a job as the current writer to the net search tree (m_NetWriteDependencies). Replaces the previous writer.

  • public void AddLaneSearchTreeReader(JobHandle jobHandle)
    {{ YOUR_INFO }}
    Register a job handle as a reader of the lane search tree.

  • public void AddLaneSearchTreeWriter(JobHandle jobHandle)
    {{ YOUR_INFO }}
    Set a job as the current writer to the lane search tree.

  • public void PreDeserialize(Context context)
    {{ YOUR_INFO }}
    Called before deserialization (loading). Completes outstanding net/lane dependencies, clears both quadtrees and sets m_Loaded = true to force a full rebuild on the next update.

  • public static MeshLayer GetLayers(Owner owner, UtilityLane utilityLane, MeshLayer defaultLayers, ref ComponentLookup<PrefabRef> prefabRefs, ref ComponentLookup<NetData> netDatas, ref ComponentLookup<NetGeometryData> netGeometryDatas)
    {{ YOUR_INFO }}
    Utility function that resolves lane mesh layers for lanes whose defaultLayers are a special combined value (Pipeline | SubPipeline). Uses owner and utility flags to decide whether the lane should use Pipeline or SubPipeline layers.

  • public static bool IsNetOwnerPipeline(Owner owner, ref ComponentLookup<PrefabRef> prefabRefs, ref ComponentLookup<NetData> netDatas, ref ComponentLookup<NetGeometryData> netGeometryDatas)
    {{ YOUR_INFO }}
    Determines whether an owner entity represents a pipeline-type net (based on NetData required layers and geometry flags). Used by GetLayers.

  • private void __AssignQueries(ref SystemState state)
    {{ YOUR_INFO }}
    Compiler-generated helper for query assignment. Present for the compiled system lifecycle; in this implementation it simply creates and disposes an EntityQueryBuilder placeholder.

  • protected override void OnCreateForCompiler()
    {{ YOUR_INFO }}
    Compiler helper called during system creation; assigns query/type handles via __AssignQueries and __TypeHandle.__AssignHandles.

  • private void __AssignHandles(ref SystemState state) (on TypeHandle)
    {{ YOUR_INFO }}
    Assigns all EntityTypeHandle, ComponentTypeHandle and ComponentLookup values from a SystemState. Used by OnCreateForCompiler.

  • IJobChunk.Execute implementations (UpdateNetSearchTreeJob.Execute and UpdateLaneSearchTreeJob.Execute)
    {{ YOUR_INFO }}
    Detailed chunk-processing logic that:

  • Removes entities from the tree if Deleted component present.
  • Adds entries when Created or on full-load rebuilds.
  • Computes bounds (Bounds3) from EdgeGeometry/NodeGeometry/Curve/Bezier and expands them using prefab mesh/geometry size where available.
  • Computes BoundsMask based on marker/editor/culling/overridden flags and default layers.
  • Calculates LOD limits using prefab min LOD or rendering utils.
  • Calls m_SearchTree.Add or m_SearchTree.Update (UpdateNetSearchTreeJob uses Add on created/loaded path and Update on update path; similar for lanes).

Note: both jobs are Burst-compiled for performance and operate on NativeQuadTree provided by the system.


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Typical setup is done by SearchSystem itself, but other systems can acquire
    // the quadtrees and ensure proper job dependencies when accessing them.

    // Example: requesting the net search tree for read-only access
    JobHandle deps;
    var searchSystem = World.GetOrCreateSystemManaged<Game.Net.SearchSystem>();
    var netTree = searchSystem.GetNetSearchTree(readOnly: true, out deps);

    // Wait for dependencies if you need immediate synchronous access (avoid on main thread if possible).
    deps.Complete();

    // Query the tree (example: point search API is hypothetical; use whichever API the NativeQuadTree provides)
    // var results = netTree.QueryPoint(new float2(10f, 20f));
}