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.
This commit is contained in:

committed by
GitHub

parent
f91c701ffe
commit
9900af38f5
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user