-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
refactor: make route() take a predicate for path_avoid #74301
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
NPC / Factions
NPCs, AI, Speech, Factions, Ownership
[C++]
Changes (can be) made in C++. Previously named `Code`
Monsters
Monsters both friendly and unfriendly.
astyled
astyled PR, label is assigned by github actions
json-styled
JSON lint passed, label assigned by github actions
labels
Jun 4, 2024
NetSysFire
added
Code: Performance
Performance boosting code (CPU, memory, etc.)
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
labels
Jun 4, 2024
irwiss
reviewed
Jun 4, 2024
github-actions
bot
added
Vehicles
Vehicles, parts, mechanics & interactions
Code: Tests
Measurement, self-control, statistics, balancing.
BasicBuildPassed
This PR builds correctly, label assigned by github actions
labels
Jun 7, 2024
Conflict needs resolving |
test failure seems unrelated. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
astyled
astyled PR, label is assigned by github actions
BasicBuildPassed
This PR builds correctly, label assigned by github actions
[C++]
Changes (can be) made in C++. Previously named `Code`
Code: Infrastructure / Style / Static Analysis
Code internal infrastructure and style
Code: Performance
Performance boosting code (CPU, memory, etc.)
Code: Tests
Measurement, self-control, statistics, balancing.
json-styled
JSON lint passed, label assigned by github actions
Monsters
Monsters both friendly and unfriendly.
NPC / Factions
NPCs, AI, Speech, Factions, Ownership
Vehicles
Vehicles, parts, mechanics & interactions
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
None
Purpose of change
Refactor map::route for a minor performance win and to support future
simplifications and bugfixes.
Describe the solution
Before
map::route
takes a set of points to "preclose", i.e. never to path through.Whenever calling
map::route
, callers assemble the full "preclosed" setcontaining every point to avoid.
After
map::route
takes a predicate that returns whether a point should be avoided.This allows callers to avoid the overhead of assembling the full "preclosed"
set. In cases where paths are short, this may improve performance by not
considering points outside a very small radius. In cases where paths are long,
it should still improve performance in most cases as the predicate is called
only once per point that the pathfinding algorithm considers, which may be
smaller than the full set of points to avoid. Additionally, callers no longer
have to choose a radius in which to compute points to be avoided.
In some cases this might be slower than the previous approach, specifically
because the "avoid" calculation isn't cached, and may be called up to 8 times
per tile in pathological cases (one for each direction from which the pather
could enter the tile).
This change should have no observable effect on behavior. However, in future,
I'd like to refactor again to change the predicate into a function returning a
weight, which would allow expressing the concept "avoid this point if possible,
but if it's the only way to reach the destination, it's fine".
See #71532.
Describe alternatives you've considered
Testing
Additional context