Game.Pathfind.CoverageActionData
Assembly: Game (game assembly)
Namespace: Game.Pathfind
Type: struct
Base: System.ValueType
Summary:
CoverageActionData is a lightweight container used by the pathfinding/coverage subsystem to hold input sources, parameters, temporary results and the current action state for a single coverage calculation job. It uses Unity.Collections unsafe containers (UnsafeQueue and UnsafeList) that must be explicitly disposed to avoid memory leaks. The struct is typically allocated with a Unity Allocator and used within native/job contexts or performance-sensitive code paths in Cities: Skylines 2.
Fields
-
public UnsafeQueue<PathTarget> m_Sources
Holds the queue of PathTarget entries that act as source points for the coverage calculation. This is an UnsafeQueue and therefore not managed by the GC — it requires manual disposal and must be initialized with a valid Allocator before use. -
public UnsafeList<CoverageResult> m_Results
A dynamic list collecting CoverageResult entries produced by the coverage computation. In the provided constructor this list is created with an initial capacity of 100. As an UnsafeList it requires manual disposal. -
public CoverageParameters m_Parameters
Configuration parameters used to control how coverage is computed (range, filters, etc.). This field is default-initialized in the constructor; populate it before running the action. -
public PathfindActionState m_State
Tracks the current state of the action (for example Pending, Running, Completed). The constructor sets this to PathfindActionState.Pending by default.
Properties
This type does not expose C# properties; it exposes public fields. All stateful containers are raw unsafe collections that must be managed and disposed explicitly.
Constructors
public CoverageActionData(Allocator allocator)
Initializes the unsafe containers and default fields:- Creates m_Sources as a new UnsafeQueue
using the supplied allocator. - Creates m_Results as a new UnsafeList
with an initial capacity of 100 using the supplied allocator. - Sets m_Parameters to default(CoverageParameters).
- Sets m_State to PathfindActionState.Pending.
Be sure to choose an appropriate Allocator (e.g., Allocator.Persistent for long-lived instances, Allocator.TempJob for short-lived job-scoped instances).
Methods
public void Dispose()
Disposes both unsafe containers (m_Sources and m_Results). Call Dispose when the CoverageActionData is no longer needed to release native memory. Failing to call Dispose will leak native memory.
Notes and cautions: - Do not use disposed containers. - If these containers are shared across jobs/threads, ensure proper synchronization and ownership rules. - The struct itself is a value type; copying it copies the references to the underlying native containers — avoid accidental copies without clear ownership semantics.
Usage Example
// Example: creating, using and disposing a CoverageActionData instance
var actionData = new CoverageActionData(Allocator.Persistent);
// configure parameters (example)
actionData.m_Parameters = new CoverageParameters {
// set fields relevant to coverage (depends on CoverageParameters definition)
};
// enqueue source(s)
actionData.m_Sources.Enqueue(new PathTarget(/* ... */));
// run coverage computation here (pseudo-code)
// CoverageSystem.Run(actionData);
// read results from actionData.m_Results
// when done, dispose to free native memory
actionData.Dispose();
If you plan to use this struct inside jobs, prefer Allocator.TempJob and ensure Dispose or deallocation happens on the correct thread or via JobHandles (or use Native containers with owned handles) to avoid race conditions.