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

refactor: make route() take a predicate for path_avoid #74301

Merged
merged 9 commits into from
Jun 18, 2024

Conversation

nornagon
Copy link
Contributor

@nornagon nornagon commented Jun 4, 2024

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" set
containing 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

@github-actions 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 NetSysFire added Code: Performance Performance boosting code (CPU, memory, etc.) Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Jun 4, 2024
src/map.h Outdated Show resolved Hide resolved
src/map.h Outdated Show resolved Hide resolved
@github-actions 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
@Maleclypse
Copy link
Member

Conflict needs resolving

@nornagon
Copy link
Contributor Author

test failure seems unrelated.

@Maleclypse Maleclypse merged commit d2d761f into CleverRaven:master Jun 18, 2024
24 of 26 checks passed
@CLIDragon CLIDragon mentioned this pull request Aug 25, 2024
10 tasks
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants