Game.Pathfind.PathfindResultSystem
Assembly: Game (inferred)
Namespace: Game.Pathfind
Type: class
Base: GameSystemBase, IPreDeserialize
Summary:
PathfindResultSystem collects and processes completed pathfinding, coverage and availability queries produced by PathfindQueueSystem. It aggregates results into NativeLists, schedules jobs to write those results back into ECS components/buffers, emits events (PathUpdated, CoverageUpdated) via an EndFrameBarrier command buffer when requested, and accumulates basic per-system/query statistics (queries, successes, graph traversal, efficiency). The system also tracks pending request counts and the earliest simulation frame still awaiting results.
Fields
-
private PathfindQueueSystem m_PathfindQueueSystem
Reference to the PathfindQueueSystem that holds queued pathfinding/coverage/availability actions. -
private PathfindSetupSystem m_PathfindSetupSystem
Reference to the PathfindSetupSystem used to get the current pendingSimulationFrame and pending request counts. -
private EndFrameBarrier m_EndFrameBarrier
Used to create an EntityCommandBuffer to emit ECS events at end of frame. -
private EntityCommandBuffer m_CommandBuffer
Command buffer created from the EndFrameBarrier when events need to be produced. -
private EntityArchetype m_PathEventArchetype
Archetype used to create PathUpdated event entities. -
private EntityArchetype m_CoverageEventArchetype
Archetype used to create CoverageUpdated event entities. -
private uint m_PendingSimulationFrameIndex
Tracks the minimum simulation frame index among pending requests. -
private int m_PendingRequestCount
Number of requests currently pending completion. -
private Dictionary<Entity, int> m_ResultListIndex
Maps owner Entity to an index into the NativeList result buffers (to coalesce multiple results for the same owner). -
private Dictionary<ResultKey, ResultValue> m_QueryStats
Aggregates statistics keyed by ResultKey (system, query type, origin/destination types). -
private NativeList<PathfindJobs.ResultItem> m_PathfindResultBuffer
NativeList used to collect completed Pathfind results for job processing. -
private NativeList<CoverageJobs.ResultItem> m_CoverageResultBuffer
NativeList used to collect completed Coverage results for job processing. -
private NativeList<AvailabilityJobs.ResultItem> m_AvailabilityResultBuffer
NativeList used to collect completed Availability results for job processing. -
private TypeHandle __TypeHandle
Holds component and buffer lookups (ComponentLookup/BufferLookup) used by scheduled jobs.
Properties
-
public uint pendingSimulationFrame { get; }
Returns the min between this system's tracked pending frame and the PathfindSetupSystem's pendingSimulationFrame (i.e., earliest waiting simulation frame index). Useful to know whether queries are still pending for a specific simulation frame. -
public int pendingRequestCount { get; }
Total pending request count = this system's pending requests + PathfindSetupSystem.pendingRequestCount. -
public Dictionary<ResultKey, ResultValue> queryStats { get; }
Exposes the aggregated query statistics dictionary for external inspection or telemetry.
Constructors
public PathfindResultSystem()
Default constructor. Initialization logic is in OnCreate; this ctor does not allocate native resources.
Methods
-
protected override void OnCreate()
Initializes references to the queue/setup systems and the EndFrameBarrier, creates event archetypes, allocates dictionaries and persistent NativeLists used to buffer job inputs. Called once when the system is created. -
protected override void OnDestroy()
Disposes the persistent NativeLists and forwards to base.OnDestroy(). Ensures native memory is freed when the system is destroyed. -
public void PreDeserialize(Context context)
IPreDeserialize implementation to reset m_PendingSimulationFrameIndex, m_PendingRequestCount and clear query statistics before deserialization. -
protected override void OnUpdate()
Main per-frame update. Resets state, collects and processes completed and pending actions from PathfindQueueSystem by calling the various ProcessResults overloads, schedules jobs to apply results into ECS (combining JobHandles) and sets base.Dependency to the combined handle. -
private void AddQueryStats(object system, QueryType queryType, SetupTargetType originType, SetupTargetType destinationType, int resultLength, int graphTraversal)
Updates or inserts an entry in m_QueryStats aggregating query count, success count, normalized graph traversal, and efficiency (resultLength / graphTraversal). Called when processing completed actions. -
private void ProcessResults(PathfindQueueSystem.ActionList<PathfindAction> list, ref JobHandle outputDeps, JobHandle inputDeps)
Processes pathfinding actions: - Iterates list items, collects completed PathfindAction results into m_PathfindResultBuffer (coalescing per owner via m_ResultListIndex),
- Logs pathfinding errors,
- Adds query stats for Pathfind queries,
- If the action requested an event, creates a PathUpdated event entity using the EndFrameBarrier command buffer,
- For completed results schedules PathfindJobs.ProcessResultsJob with required component/buffer lookups and combines the resulting JobHandle into outputDeps,
- Tracks pending simulation frames and pending request count for in-flight actions,
-
Removes disposed/non-pending items from the action list.
-
private void ProcessResults(PathfindQueueSystem.ActionList<CoverageAction> list, ref JobHandle outputDeps, JobHandle inputDeps)
Processes coverage actions similarly: - Collects completed coverage results into m_CoverageResultBuffer,
- Adds query stats for Coverage queries,
- Creates CoverageUpdated events when requested,
- Schedules CoverageJobs.ProcessResultsJob to write coverage elements back into ECS,
-
Updates pending counters and prunes the list.
-
private void ProcessResults(PathfindQueueSystem.ActionList<AvailabilityAction> list, ref JobHandle outputDeps, JobHandle inputDeps)
Processes availability actions similarly: - Collects results into m_AvailabilityResultBuffer,
- Adds query stats for Availability queries,
- Schedules AvailabilityJobs.ProcessResultsJob to write availability elements into ECS,
-
Updates pending counters and prunes the list.
-
private void ProcessResults<T>(PathfindQueueSystem.ActionList<T> list) where T : struct, IDisposable
Generic cleanup for other action lists (create, update, delete, density, time, flow): - Iterates items and if not pending and dependencies completed, completes the dependencies, disposes the item, and removes it from the list.
-
Otherwise retains the item for next frame.
-
private void __AssignQueries(ref SystemState state)
Compiler helper used by generated/fixer code. Currently builds an empty EntityQueryBuilder (no runtime effect here). -
protected override void OnCreateForCompiler()
Compiler-time helper that calls __AssignQueries and assigns the TypeHandle component/buffer lookups via __TypeHandle.__AssignHandles. -
Nested/note: TypeHandle.__AssignHandles(ref SystemState state)
Initializes ComponentLookup and BufferLookup fields inside the TypeHandle; used when scheduling jobs to obtain correct lookups with respect to the system state.
Nested types
-
public enum QueryType { Pathfind, Coverage, Availability }
Identifies the type of query used for statistics and logging. -
public struct ResultKey : IEquatable<ResultKey>
Key used for m_QueryStats; composed of system object, QueryType, origin and destination SetupTargetType. Implements Equals and GetHashCode. -
public struct ResultValue
Value stored in m_QueryStats containing aggregated counters: - m_QueryCount (int)
- m_SuccessCount (int; number of queries that returned at least one result)
- m_GraphTraversal (float; normalized by graph size)
-
m_Efficiency (float; resultLength / graphTraversal)
-
private struct TypeHandle
Contains ComponentLookup and BufferLookup fields used by scheduled jobs and the __AssignHandles method to initialize them from a SystemState.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The system sets up required references, archetypes and persistent buffers:
// - acquires references to PathfindQueueSystem and PathfindSetupSystem
// - creates EndFrameBarrier command buffer and event archetypes
// - allocates NativeList buffers for Pathfind/Coverage/Availability results
}
Additional notes: - This system is tightly coupled with PathfindQueueSystem, PathfindSetupSystem, and job types PathfindJobs/CoverageJobs/AvailabilityJobs. It expects those jobs to produce specific ResultItem structs that it collects and forwards to ProcessResultsJob job types. - Event emission uses EndFrameBarrier.CreateCommandBuffer(), which ensures events are executed at the end of the frame. If many events are produced, the command buffer is lazily created only when needed. - The system keeps persistent NativeLists; OnDestroy must be allowed to run to avoid leaks.