Fix 3d7ab09: stopped trains not updating viewport hash when reversed for a second time #9165
+9
−3
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.
Motivation / Problem
peter1138 found a problem while investigating a pathfinder issue, which is that stopped/stuck trains do not correctly update their viewport hash and thus partial sprite problems occur. Example image attached.
Description
The viewport hash calculation is set up to use the sprite cache from before the most recent bounding box update. This was done to fix a specific problem:
This fix corrects the problem by only using the "old" position in the one case it is actually needed, when it contains an invalid coordinate.
Limitations
I've run my usual series of checks - against the game demonstrating the issue, against some Timberwolf's Trains games from the original PR, against the abuse.grf size-changing train, and against ships doing traversing through rotations of >180 degrees on the spot.
No regressions observed, although these are only visual checks against currently known scenarios.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.