Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AStarGrid2D Maximum Traversals #136

Closed
wants to merge 4 commits into from

Conversation

Veradictus
Copy link
Contributor

@Veradictus Veradictus commented Oct 3, 2024

Adds the ability to control the maximum amount of traversals the pathfinder will make before exhausting itself. This is particularly useful when dealing with large open-world 2D tile-maps where you do not want to search the whole world if the player clicks on a tile that is no accessible. Doing so will cause lag spikes due to the pathfinder attempting to search everything.

By default 0 means that there is no limit imposed on traversals.

@CoreTaxxe
Copy link

Just a nit pick but how about a slider for the distance going from 0 - max value?

... PROPERTY_HINT_RANGE, "0, max, ..."

@Veradictus
Copy link
Contributor Author

Just a nit pick but how about a slider for the distance going from 0 - max value?

... PROPERTY_HINT_RANGE, "0, max, ..."

Yea, if I'm doing that I should probably handle the edge case of negative numbers, so instead of

max_traversals != 0

I think it'd be better to

max_traversals > 0

I'll push some fixes later today.

@cheetoray
Copy link

cheetoray commented Oct 4, 2024

Pretty useful but also in this scenario what you want to do is to bias the solver towards closer cells, not cheaper routes. This usually results in suboptimal routes within 10% of perfect routes, but is anywhere between 2x and 20x faster to execute.

You should be able to do this by simply assigning sub-unit path costs, like 0.5 - this is the same as having 2x pathfinder bias.

EDIT: also, "unlimited" should be just INT_MAX or something. It's marginally less code to run resulting in very slightly faster pathfinding, and it accomplishes even better results even though it's technically not unlimited (if you have over 2 billion cells to traverse you're already lagging out of existence anyway, but it'll break the execution at least, not run forever).

@Kaetram Kaetram closed this by deleting the head repository Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants