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/waypoint_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/waypoint_cmd.cpp')
-rw-r--r-- | src/waypoint_cmd.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 70a6fea83..d55b1b459 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -39,8 +39,13 @@ void Waypoint::UpdateVirtCoord() { Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE); + if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index)); + SetDParam(0, this->index); this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT); + + _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index)); + /* Recenter viewport */ InvalidateWindowData(WC_WAYPOINT_VIEW, this->index); } @@ -53,11 +58,7 @@ void Waypoint::MoveSign(TileIndex new_xy) { if (this->xy == new_xy) return; - _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index)); - this->BaseStation::MoveSign(new_xy); - - _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index)); } /** @@ -239,15 +240,11 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint } if (flags & DC_EXEC) { - bool need_sign_update = false; if (wp == nullptr) { wp = new Waypoint(start_tile); - need_sign_update = true; } else if (!wp->IsInUse()) { /* Move existing (recently deleted) waypoint to the new location */ - _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); wp->xy = start_tile; - need_sign_update = true; } wp->owner = GetTileOwner(start_tile); @@ -262,7 +259,6 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint if (wp->town == nullptr) MakeDefaultName(wp); wp->UpdateVirtCoord(); - if (need_sign_update) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index); byte *layout_ptr = AllocaM(byte, count); @@ -329,7 +325,6 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 wp = new Waypoint(tile); } else { /* Move existing (recently deleted) buoy to the new location */ - _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); wp->xy = tile; InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index); } @@ -349,7 +344,6 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 MarkTileDirtyByTile(tile); wp->UpdateVirtCoord(); - _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index)); InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index); } |