libgdx / gdx-ai

Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Apache License 2.0
1.18k stars 241 forks source link

Add stop condition to IndexedAStarPathFinder #105

Closed niemandkun closed 2 years ago

niemandkun commented 5 years ago

Related to issues https://github.com/libgdx/gdx-ai/issues/67 and https://github.com/libgdx/gdx-ai/issues/99 (pathfinding uses identity to determine when destination reached).

This PR replaces identity check during indexed A* search with StopCondition. With this interface users will be able to define custom criteria to interrupt the search.

There is already a PR opened on these issues (https://github.com/libgdx/gdx-ai/pull/96), but solution introduced in my PR is more general and maintains backward compatibility: simple replacing == with .equals may break some projects, where difference between two checks is crucial for correct work.

Ktar5 commented 5 years ago

Any update on this @maintainers?

leanlauri commented 4 years ago

Thank you @niemandkun! While waiting for an official build, I created a local subclass of IndexedAStarPathFinder based on your code and it works like a charm.

tommyettinger commented 2 years ago

I like this solution; it allows keeping the current behavior for users who want that, and switching to .equals() as in #96 for users who want that. Just as importantly, it allows arbitrary custom behavior, which seems to be needed very often in game development. With the inlining that HotSpot performs, I would suspect the overhead for the method call is low, and if inlined to just a == b, it would probably be faster than a call to a.equals(b) each time. Probably not a terribly significant amount of overhead, anyway. I'll merge this and run benchmarks; in the unlikely case that it has a severe performance penalty, I could roll back, but I feel like there should really be some solution to the node equality problem.