diff options
author | Matt Kimber <mattkimber@users.noreply.github.com> | 2021-05-01 18:14:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-01 18:14:50 +0100 |
commit | 520595ff87bc55042010a370ef1070f296ff07c0 (patch) | |
tree | afbb301ef256e502a9622c3669476e9e4c49f58e | |
parent | 05394d5216f89c9a7e14487b571515e510828657 (diff) | |
download | openttd-520595ff87bc55042010a370ef1070f296ff07c0.tar.xz |
Fix 3d7ab09: stopped trains not updating viewport hash when reversed for a second time (#9165)
-rw-r--r-- | src/vehicle.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index a9af24c55..90accdd80 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1639,13 +1639,19 @@ void Vehicle::UpdateBoundingBoxCoordinates(bool update_cache) const */ void Vehicle::UpdateViewport(bool dirty) { - Rect old_coord = this->sprite_cache.old_coord; + /* If the existing cache is invalid we should ignore it, as it will be set to the current coords by UpdateBoundingBoxCoordinates */ + bool ignore_cached_coords = this->sprite_cache.old_coord.left == INVALID_COORD; this->UpdateBoundingBoxCoordinates(true); - UpdateVehicleViewportHash(this, this->coord.left, this->coord.top, old_coord.left, old_coord.top); + + if (ignore_cached_coords) { + UpdateVehicleViewportHash(this, this->coord.left, this->coord.top, INVALID_COORD, INVALID_COORD); + } else { + UpdateVehicleViewportHash(this, this->coord.left, this->coord.top, this->sprite_cache.old_coord.left, this->sprite_cache.old_coord.top); + } if (dirty) { - if (old_coord.left == INVALID_COORD) { + if (ignore_cached_coords) { this->sprite_cache.is_viewport_candidate = this->MarkAllViewportsDirty(); } else { this->sprite_cache.is_viewport_candidate = ::MarkAllViewportsDirty( |