Game.Pathfind.IPathfindTargetBuffer
Assembly: Assembly-CSharp
Namespace: Game.Pathfind
Type: interface
Base: (none)
Summary:
IPathfindTargetBuffer is a small interface used by the pathfinding system to accept (buffer) pathfinding targets. Implementations of this interface provide a storage/queue mechanism for PathTarget entries that will be consumed later by pathfinding jobs or processing code. The interface exposes a single operation, Enqueue, to add a PathTarget to the buffer.
Fields
- This interface declares no fields. Implementations typically hold internal storage (e.g., queues, lists, or job-friendly buffers) to accumulate PathTarget items until the pathfinder consumes them.
Properties
- This interface declares no properties. Implementations may expose properties as needed (count, capacity, etc.), but they are not part of the interface contract.
Constructors
- Interfaces do not define constructors. Concrete implementations must provide their own constructors and initialization.
Methods
void Enqueue(PathTarget pathTarget)
Adds a PathTarget to the buffer. Intended usage is to submit targets (nodes, building positions, vehicle targets, etc.) that the pathfinding system will process. Implementations should consider thread-safety and allocation behavior depending on how and where Enqueue is called (main thread vs worker threads).
Behavior notes and recommendations:
- Parameter:
- PathTarget pathTarget
— a struct or type representing a single pathfinding target. The exact fields of PathTarget are defined elsewhere; treat it as the unit of work consumed by the pathfinder.
- Thread-safety:
- If Enqueue is called from multiple threads (for example, from job threads), the implementation must be thread-safe (use concurrent data structures or synchronization).
- If called only from the main thread, a simple Queue or List with no locking is acceptable.
- Performance:
- Avoid per-call allocations. Prefer pooled buffers or preallocated arrays when high throughput is expected.
- If the pathfinder processes items in bulk, consider storing PathTarget entries in contiguous arrays or NativeContainers (Unity) to improve cache locality and to integrate with jobified code.
- Lifetime:
- Document ownership: whether the buffer owns the PathTarget instances (for reference types) or copies are made (for structs). For structs, Enqueue typically copies the value.
Usage Example
// Simple thread-safe implementation using a lock.
// For high-performance or jobified pathfinding you would
// replace this with a concurrent or Native container.
using System.Collections.Generic;
public struct PathTarget
{
// Example fields -- actual definition lives elsewhere.
public int nodeId;
public float3 position;
}
public class PathfindTargetBuffer : Game.Pathfind.IPathfindTargetBuffer
{
private readonly Queue<PathTarget> _queue = new Queue<PathTarget>();
private readonly object _lock = new object();
public void Enqueue(PathTarget pathTarget)
{
lock (_lock)
{
_queue.Enqueue(pathTarget);
}
}
// Example consumer method:
public void DrainAndProcess()
{
Queue<PathTarget> copy;
lock (_lock)
{
if (_queue.Count == 0) return;
copy = new Queue<PathTarget>(_queue);
_queue.Clear();
}
while (copy.Count > 0)
{
var target = copy.Dequeue();
// Process target (submit to pathfinder, create jobs, etc.)
}
}
}
Notes:
- For integration with Unity.Jobs or DOTS-style processing, consider using NativeQueue