diff options
author | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-12-01 23:17:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-01 23:17:33 +0100 |
commit | 9900af38f58c84a90bd1a3830b9acd08438c46c5 (patch) | |
tree | de630b1f7e806d1b4c1639031111151292863951 /src/station_cmd.cpp | |
parent | f91c701ffebe098f05b237642dd37002181f1a7f (diff) | |
download | openttd-9900af38f58c84a90bd1a3830b9acd08438c46c5.tar.xz |
Fix #7847: Use ViewportSign coordinates for sign Kdtree coordinates (#7849)
Ensure the same coordinates are used for station/town/player signs regardless of how the landscape changes below it after the coordinates were first determined.
By keeping track of whether each ViewportSign is valid for Kdtree use (and only ever registering the viewport sign when the object is valid) a lot of code can be simplified and become more robust at the same time.
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r-- | src/station_cmd.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index cb64873b6..78a0896ea 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -420,10 +420,14 @@ void Station::UpdateVirtCoord() pt.y -= 32 * ZOOM_LVL_BASE; if ((this->facilities & FACIL_AIRPORT) && this->airport.type == AT_OILRIG) pt.y -= 16 * ZOOM_LVL_BASE; + if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index)); + SetDParam(0, this->index); SetDParam(1, this->facilities); this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION); + _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index)); + SetWindowDirty(WC_STATION_VIEW, this->index); } @@ -435,13 +439,11 @@ void Station::MoveSign(TileIndex new_xy) { if (this->xy == new_xy) return; - _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index)); _station_kdtree.Remove(this->index); this->BaseStation::MoveSign(new_xy); _station_kdtree.Insert(this->index); - _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index)); } /** Update the virtual coords needed to draw the station sign for all stations. */ @@ -692,7 +694,6 @@ static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reus if (flags & DC_EXEC) { *st = new Station(area.tile); _station_kdtree.Insert((*st)->index); - _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation((*st)->index)); (*st)->town = ClosestTownFromTile(area.tile, UINT_MAX); (*st)->string_id = GenerateStationName(*st, area.tile, name_class); @@ -4157,7 +4158,6 @@ void BuildOilRig(TileIndex tile) st->rect.BeforeAddTile(tile, StationRect::ADD_FORCE); st->UpdateVirtCoord(); - _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(st->index)); st->RecomputeCatchment(); UpdateStationAcceptance(st, false); } |