Game.Net.UpdateCollectSystem
Assembly:
Assembly-CSharp (game runtime)
Namespace:
Game.Net
Type:
class
Base:
GameSystemBase
Summary:
UpdateCollectSystem collects and exposes updated world-space bounds for net (roads/edges/nodes) and lane geometry. It observes ECS component changes (Created / Updated / Deleted) for net and lane geometry, schedules Burst-compiled IJobChunk jobs to compute 2D XZ bounds for changed entities, aggregates them into native lists, and coordinates job dependencies with the SearchSystem so other systems can safely read updated search-tree areas. The system maintains separate queues and dependency tracking for nets and lanes, and exposes methods to obtain the result lists and register readers (dependency handles).
Fields
-
private EntityQuery m_NetGeometryQuery
The ECS query used to find net geometry entities (EdgeGeometry / NodeGeometry) that have been Created, Updated or Deleted. -
private EntityQuery m_LaneGeometryQuery
The ECS query used to find lane geometry entities (LaneGeometry + UtilityLane) that have been Created, Updated or Deleted. -
private SearchSystem m_SearchSystem
Reference to the global SearchSystem used to obtain read-only net and lane search trees and to register readers so job dependencies are tracked. -
private NativeList<Bounds2> m_UpdatedNetBounds
Persistent native list that accumulates XZ bounds for nets that were changed on the current update. Returned by GetUpdatedNetBounds. -
private JobHandle m_NetWriteDependencies
JobHandle representing the writer dependency for the net-updated bounds; callers should wait on this when reading m_UpdatedNetBounds. -
private JobHandle m_NetReadDependencies
Accumulated read dependencies for systems that registered as readers of the net bounds (via AddNetBoundsReader). -
private JobHandle m_LaneWriteDependencies
JobHandle representing the writer dependency for the lane-updated bounds; callers should wait on this when reading m_UpdatedLaneBounds. -
private JobHandle m_LaneReadDependencies
Accumulated read dependencies for systems that registered as readers of the lane bounds (via AddLaneBoundsReader). -
private NativeList<Bounds2> m_UpdatedLaneBounds
Persistent native list that accumulates XZ bounds for lanes that were changed on the current update. Returned by GetUpdatedLaneBounds. -
private TypeHandle __TypeHandle
Generated helper/struct that caches component and entity type handles / lookups required by the scheduled jobs. Assigned in OnCreateForCompiler. -
private struct CollectUpdatedNetBoundsJob
(nested)
Burst-compiled IJobChunk that inspects net-related chunks (EdgeGeometry+Start/End Node or NodeGeometry) and enqueues computed XZ bounds to a NativeQueue for later transfer to m_UpdatedNetBounds. Handles Created / Deleted / Updated cases and compares against the SearchTree to determine whether to produce merged bounds. -
private struct CollectUpdatedLaneBoundsJob
(nested)
Burst-compiled IJobChunk that inspects lane-related chunks (Curve + PrefabRef) and enqueues computed XZ bounds to a NativeQueue. Expands lane bounds using NetLaneGeometryData when available. Handles Created / Deleted / Updated similar to net job. -
private struct DequeueBoundsJob
(nested)
IJob that dequeues all bounds from a NativeQueue into a NativeList (used for both nets and lanes).
Properties
-
public bool netsUpdated { get; private set; }
Indicates whether there are pending net updates collected this frame (i.e., m_UpdatedNetBounds contains results and m_NetWriteDependencies must be waited on before reading). External systems should use GetUpdatedNetBounds(out JobHandle) to obtain the list and required dependency. -
public bool lanesUpdated { get; private set; }
Indicates whether there are pending lane updates collected this frame. External systems should use GetUpdatedLaneBounds(out JobHandle) to obtain the list and required dependency.
Constructors
public UpdateCollectSystem()
Default constructor invoked by the ECS. Initialization that depends on World or SystemState is performed in OnCreate / OnCreateForCompiler.
Methods
-
[Preserve] protected override void OnCreate()
: System.Void
Sets up entity queries for net and lane geometry, obtains the SearchSystem, and allocates persistent NativeLists used to store computed updated bounds (m_UpdatedNetBounds and m_UpdatedLaneBounds). Called when the system is created. -
[Preserve] protected override void OnDestroy()
: System.Void
Completes outstanding job dependencies (both read and write dependencies for nets and lanes) and disposes the persistent NativeLists. Ensures no jobs remain that would access disposed memory. -
[Preserve] protected override void OnUpdate()
: System.Void
Main update logic: - Checks whether net/lane queries are empty and clears/tears down previous lists and dependencies if nothing is present.
- When there are changes, schedules Burst IJobChunk jobs (CollectUpdatedNetBoundsJob and/or CollectUpdatedLaneBoundsJob) to compute bounds in parallel into temporary NativeQueues.
- Schedules a DequeueBoundsJob to transfer queued bounds into the persistent NativeList.
- Obtains read-only search trees from SearchSystem (m_SearchSystem.GetNetSearchTree / GetLaneSearchTree) and registers the job handles with the SearchSystem to ensure safe concurrent reads.
-
Tracks writer and reader JobHandles (m_NetWriteDependencies, m_NetReadDependencies, m_LaneWriteDependencies, m_LaneReadDependencies) so other systems can synchronize.
-
public NativeList<Bounds2> GetUpdatedNetBounds(out JobHandle dependencies)
: NativeList
Returns the native list containing collected net bounds and outputs the JobHandledependencies
that the caller must complete before reading the list (this is the writer dependency: m_NetWriteDependencies). -
public void AddNetBoundsReader(JobHandle handle)
: System.Void
Registers a read dependency for net bounds consumers; combines the provided handle with m_NetReadDependencies so OnUpdate will wait for that reader before freeing/overwriting m_UpdatedNetBounds. -
public NativeList<Bounds2> GetUpdatedLaneBounds(out JobHandle dependencies)
: NativeList
Returns the native list containing collected lane bounds and outputs the JobHandledependencies
that the caller must complete before reading (m_LaneWriteDependencies). -
public void AddLaneBoundsReader(JobHandle handle)
: System.Void
Registers a read dependency for lane bounds consumers; combines the provided handle with m_LaneReadDependencies. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
: System.Void
Compiler helper used during system codegen; ensures queries / builders are initialized for the generated code path. -
protected override void OnCreateForCompiler()
: System.Void
Compiler/init helper called by codegen to call __AssignQueries and to assign type handles via __TypeHandle.__AssignHandles.
Usage Example
// Typical usage from another system or mod code that needs to react to changed net bounds:
// Get reference to the UpdateCollectSystem instance (example using default world)
var updateCollect = World.DefaultGameObjectInjectionWorld
.GetExistingSystemManaged<Game.Net.UpdateCollectSystem>();
if (updateCollect != null && updateCollect.netsUpdated)
{
// Get the list and the job handle we must wait on
JobHandle writeDeps;
var updatedNetBounds = updateCollect.GetUpdatedNetBounds(out writeDeps);
// Ensure the writer jobs are finished before accessing the list
writeDeps.Complete();
// Iterate bounds
for (int i = 0; i < updatedNetBounds.Length; i++)
{
Bounds2 bounds = updatedNetBounds[i];
// react to bounds (e.g. update search trees, graphics, etc.)
}
// If you spawn any jobs that read these bounds, register your reader handle:
// JobHandle readerHandle = myJob.Schedule(...);
// updateCollect.AddNetBoundsReader(readerHandle);
}
Notes & tips: - Always complete the provided writer JobHandle (from GetUpdatedNetBounds/GetUpdatedLaneBounds) before reading the returned NativeList on the main thread. - If you schedule jobs that read the returned NativeList, call AddNetBoundsReader/AddLaneBoundsReader with the reader JobHandle so UpdateCollectSystem knows to wait and won't recycle the lists early. - This system is Burst-compiled and uses parallel IJobChunk scheduling; avoid accessing ECS component data sets directly while the system is running unless you properly synchronize using the provided JobHandles.