License | BSD-3-Clause |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Swarm.Game.Step.Path.Cache
Description
Pathfinding cache invalidation logic
Overview
Each time the Path
command is invoked, the computed
shortest-path is placed in in a cache specific to the invoking robot.
If the Path
command is invoked again by that robot
with identical arguments and from the same position, or a position lying
on the previously computed path, then the shortest path shall
be retrieved from the cache instead of being recomputed.
If the Path
command is re-invoked with different arguments
or from a novel position, then the shortest-path shall be
recomputed and the cache overwritten with this new result.
Asynchronous to the event of invoking the Path
command,
there are a variety of events that may invalidate
a previously-computed shortest path between some
location and a destination, including adding or removing
particular entities at certain locations.
Certain events allow for partial re-use of the previously computed path.
Synopsis
- retrieveCachedPath :: forall (sig :: (Type -> Type) -> Type -> Type) m. HasRobotStepState sig m => WalkabilityContext -> PathfindingParameters (Cosmic Location) -> m (Either CacheRetreivalInapplicability [Location])
- revalidatePathCache :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State GameState) sig m => Cosmic Location -> CellModification Entity -> (RID, PathfindingCache) -> m ()
- recordCache :: forall (sig :: (Type -> Type) -> Type -> Type) m. HasRobotStepState sig m => PathfindingParameters SubworldName -> WalkabilityContext -> NonEmpty Location -> m ()
Documentation
retrieveCachedPath :: forall (sig :: (Type -> Type) -> Type -> Type) m. HasRobotStepState sig m => WalkabilityContext -> PathfindingParameters (Cosmic Location) -> m (Either CacheRetreivalInapplicability [Location]) Source #
Fetch the previously computed shortest path from the cache. Log success or the reason it failed.
revalidatePathCache :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State GameState) sig m => Cosmic Location -> CellModification Entity -> (RID, PathfindingCache) -> m () Source #
Given an event that entails the modification of some cell, check whether a shortest-path previously computed for a given robot is still valid or can be updated.
Arguments
:: forall (sig :: (Type -> Type) -> Type -> Type) m. HasRobotStepState sig m | |
=> PathfindingParameters SubworldName | |
-> WalkabilityContext | |
-> NonEmpty Location | includes robot starting position |
-> m () |
Store a newly computed shortest path in the cache.