From 2817cd41f1b42a7d3901a92c6cda85a90765600a Mon Sep 17 00:00:00 2001 From: stormcone <48624099+stormcone@users.noreply.github.com> Date: Sun, 7 Jul 2019 19:44:08 +0200 Subject: [PATCH] Fix #7250: Viewport kdtree not being updated for waypoints when sign moved. Code based on the patch by JGRennison. JGRennison/OpenTTD-patches@ac84f34062ef1f3ffcdee49dc595d574e4efb4d5 --- src/waypoint_base.h | 2 ++ src/waypoint_cmd.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/waypoint_base.h b/src/waypoint_base.h index c11c2f2b2f..be1d0bd0df 100644 --- a/src/waypoint_base.h +++ b/src/waypoint_base.h @@ -27,6 +27,8 @@ struct Waypoint FINAL : SpecializedStation { void UpdateVirtCoord() override; + void MoveSign(TileIndex new_xy) override; + inline bool TileBelongsToRailStation(TileIndex tile) const override { return IsRailWaypointTile(tile) && GetStationIndex(tile) == this->index; diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 20e600b5ee..652173a947 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -47,6 +47,21 @@ void Waypoint::UpdateVirtCoord() InvalidateWindowData(WC_WAYPOINT_VIEW, this->index); } +/** + * Move the waypoint main coordinate somewhere else. + * @param new_xy new tile location of the sign + */ +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)); +} + /** * Find a deleted waypoint close to a tile. * @param tile to search from