Class PathCache
ENGINE: LRU cache for pathfinding results.
Caches computed paths to avoid redundant A* searches. Uses simple LRU eviction when cache is full.
Cache key: (start, goal) pair Cache invalidation: Manual clear or frame-based expiry
Thread safety: NOT thread-safe (single-threaded pathfinding assumed)
public class PathCache
- Inheritance
-
objectPathCache
Constructors
PathCache(int)
Create a path cache with specified maximum size.
public PathCache(int maxSize = 256)
Parameters
maxSizeintMaximum number of cached paths
Properties
Count
Number of cached paths
public int Count { get; }
Property Value
- int
HitCount
Cache hit count since last reset
public int HitCount { get; }
Property Value
- int
HitRate
Cache hit rate (0-1)
public float HitRate { get; }
Property Value
- float
MaxSize
Maximum cache size
public int MaxSize { get; }
Property Value
- int
MissCount
Cache miss count since last reset
public int MissCount { get; }
Property Value
- int
Methods
Add(ushort, ushort, List<ushort>, FixedPoint64)
Add a path to the cache.
public void Add(ushort start, ushort goal, List<ushort> path, FixedPoint64 cost)
Parameters
startushortgoalushortpathList<ushort>costFixedPoint64
Clear()
Clear all cached paths.
public void Clear()
GetStats()
Get cache statistics as string.
public string GetStats()
Returns
- string
InvalidateEndpoint(ushort)
Invalidate all paths for a specific start or goal province.
public void InvalidateEndpoint(ushort provinceId)
Parameters
provinceIdushort
InvalidateProvince(ushort)
Invalidate paths that pass through a specific province. Call when a province becomes blocked/unblocked.
public void InvalidateProvince(ushort provinceId)
Parameters
provinceIdushort
ResetStats()
Reset statistics.
public void ResetStats()
TryGet(ushort, ushort, out List<ushort>, out FixedPoint64)
Try to get a cached path.
public bool TryGet(ushort start, ushort goal, out List<ushort> path, out FixedPoint64 cost)
Parameters
startushortgoalushortpathList<ushort>costFixedPoint64
Returns
- bool