Class AStarPathfinder
java.lang.Object
de.bsommerfeld.pathetic.engine.pathfinder.AbstractPathfinder<de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchState>
de.bsommerfeld.pathetic.engine.pathfinder.AStarPathfinder
- All Implemented Interfaces:
Pathfinder
public final class AStarPathfinder
extends AbstractPathfinder<de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchState>
An A* pathfinding algorithm that uses a heuristic to guide the search toward the target. It
balances the actual cost from the start (G-cost) with the estimated cost to the target (H-cost).
This implementation uses:
- A quaternary primitive min-heap for the open set (priority queue), keyed by dense node ids so decrease-key position tracking is a plain array access.
- A single per-search hash map from packed position keys to dense ids; open-set nodes, the
closed set, and recorded G-costs are all id-indexed arrays (
AStarSearchState).
Thread-safety: each pathfinding operation gets its own AStarSearchState, created as a
stack local in the base loop and passed explicitly into the template methods. Concurrent requests
on a single pathfinder are therefore isolated by the call stack; no per-search state is stored on
the pathfinder itself.
Exploration radius: node keys are packed relative to the search start (see RegionKey), so absolute world coordinates are unconstrained. A single search can expand
positions up to roughly two million blocks (X/Z) and half a million blocks (Y) away from its
start; positions beyond that radius are treated as non-navigable.
-
Field Summary
Fields inherited from class de.bsommerfeld.pathetic.engine.pathfinder.AbstractPathfinder
costProcessors, EMPTY_PATH_POSITIONS, executorService, hasCustomProcessors, navigationPointProvider, neighborStrategy, pathfinderConfiguration, validationProcessors -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchStatecreateSearchState(PathPosition start, int expectedNodes) Creates the per-search state holding this algorithm's open and closed sets.protected voidprocessSuccessors(PathPosition start, PathPosition target, Node currentNode, de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchState state, SearchContext searchContext) Processes the successors of the current node, checking if they're in the open or closed set, calculating costs, validating traversability, and updating the open set as needed.Methods inherited from class de.bsommerfeld.pathetic.engine.pathfinder.AbstractPathfinder
createStartNode, findPath, reconstructPath, registerPathfindingHookMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.bsommerfeld.pathetic.api.pathing.Pathfinder
findPath
-
Constructor Details
-
AStarPathfinder
-
-
Method Details
-
createSearchState
protected de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchState createSearchState(PathPosition start, int expectedNodes) Description copied from class:AbstractPathfinderCreates the per-search state holding this algorithm's open and closed sets. Called once at the start of every request; the returned instance lives as a stack local and is passed back intoAbstractPathfinder.processSuccessors(de.bsommerfeld.pathetic.api.wrapper.PathPosition, de.bsommerfeld.pathetic.api.wrapper.PathPosition, de.bsommerfeld.pathetic.engine.Node, S, de.bsommerfeld.pathetic.api.pathing.processing.context.SearchContext), so it never needs to be stored on the pathfinder.- Specified by:
createSearchStatein classAbstractPathfinder<de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchState>- Parameters:
start- The effective (floored) start position of the request; implementations that key their per-search state relative to the search origin derive that origin from it.expectedNodes- Estimated number of nodes the search will touch; implementations should size their per-search structures from it so small requests pay small setup costs.- Returns:
- a fresh, empty search state for this request.
-
processSuccessors
protected void processSuccessors(PathPosition start, PathPosition target, Node currentNode, de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchState state, SearchContext searchContext) Processes the successors of the current node, checking if they're in the open or closed set, calculating costs, validating traversability, and updating the open set as needed.- Specified by:
processSuccessorsin classAbstractPathfinder<de.bsommerfeld.pathetic.engine.pathfinder.AStarSearchState>- Parameters:
start- The starting position of the pathfinding request.target- The target position of the pathfinding request.currentNode- The node being expanded.state- The per-search state holding the open and closed sets.searchContext- The context for the current search.
-