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

Fix: prevent useless pathfinder run for blocked vehicles #8568

Merged
merged 1 commit into from Jan 14, 2021

Conversation

@glx22
Copy link
Contributor

@glx22 glx22 commented Jan 14, 2021

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.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
Copy link
Member

@LordAro LordAro left a comment

Fine by me

uint32 r = VehicleEnterTile(v, v->tile, x, y);
if (HasBit(r, VETS_CANNOT_ENTER)) {
Comment on lines 1403 to 1404

This comment has been minimized.

@SamuXarick

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.

@glx22 glx22 merged commit 86818e5 into OpenTTD:master Jan 14, 2021
7 checks passed
7 checks passed
Emscripten
Details
Commit checker
Details
Linux (clang, clang++)
Details
Linux (gcc, g++)
Details
Mac OS (x64, x86_64)
Details
Windows (x86)
Details
Windows (x64)
Details
@glx22 glx22 deleted the glx22:fix_7670 branch Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants