-
-
Notifications
You must be signed in to change notification settings - Fork 27
Pathfinder
The Pathfinder is the workhorse. You built it in the factory, gave it a brain (Configuration), and now you use this interface to tell it where to go.
It is thread-safe (mostly), non-blocking (if you listened to us and enabled async), and ready to run.
The main event.
-
findPath(start, target)Calculates the path. If you configured async, this returns immediately and computes in the background. -
findPath(start, target, context)The Overload. Use this if your NavigationPointProvider needs runtime data (like "Which team is this unit on?" or "Is the door locked for this specific player?").
// Fire and forget
PathfindingSearch search = pathfinder.findPath(start, target, myContext);
search.ifPresent(result -> {
// This runs when the math is done.
moveEntity(result.getPath());
}).orElse(result -> printFailure(result)); // A path has not been found.How to use this class without hurting yourself:
-
Build it: Get an instance from the PathfinderFactory. Keep this instance; don't create a new one for every path.
-
Fire it: Call findPath(...).
-
Wait for it: Handle the PathfinderResult in the callback.