Fix: prevent useless pathfinder run for blocked vehicles #8568
Conversation
Fine by me |
uint32 r = VehicleEnterTile(v, v->tile, x, y); | ||
if (HasBit(r, VETS_CANNOT_ENTER)) { |
Comment on lines
1403
to
1404
SamuXarick
Jan 14, 2021
•
Contributor
I wondered if the pathfinder prevention checks should be also added to VETS_CANNOT_ENTER, but I wasn't able find a situation where HasBit(r, VETS_CANNOT_ENTER)
is true for testing that.
I wondered if the pathfinder prevention checks should be also added to VETS_CANNOT_ENTER, but I wasn't able find a situation where HasBit(r, VETS_CANNOT_ENTER)
is true for testing that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix #7670 and supersede #7822.
Motivation / Problem
As found in #7670, a road vehicle blocked by another vehicle may enter in an "loop" of intensive pathfinder calls.
This happens because starting tile for path search is not cached and as the vehicle did not move since previous call, the cached path is discarded and a new one has to be determined.
Description
This solution is similar to the one in #7822, but a lot less invasive and does not require a savegame bump.
When a road vehicle is blocked by another one, just push its current location and the direction to follow found by pathfinder on top of the existing cache.
That way on next run it will just retrieve the heading instead of recalculating it.
While in the area I noticed the speed of the blocked vehicle was not updated, so I fixed it.
Limitations
I only tested using the save from #7670 (comment) but I don't see how it could cause issues.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.