Save point used when adding station to viewport kd tree, use for removal
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include "command_type.h"
|
#include "command_type.h"
|
||||||
#include "viewport_type.h"
|
#include "viewport_type.h"
|
||||||
#include "station_map.h"
|
#include "station_map.h"
|
||||||
|
#include "core/geometry_type.hpp"
|
||||||
|
|
||||||
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
||||||
extern StationPool _station_pool;
|
extern StationPool _station_pool;
|
||||||
@@ -76,6 +77,8 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
|||||||
TileArea train_station; ///< Tile area the train 'station' part covers
|
TileArea train_station; ///< Tile area the train 'station' part covers
|
||||||
StationRect rect; ///< NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions
|
StationRect rect; ///< NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions
|
||||||
|
|
||||||
|
Point viewport_sign_kdtree_pt; ///< NOSAVE: Viewport sign kd tree: saved point (for tree removals)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the base station.
|
* Initialize the base station.
|
||||||
* @param tile The location of the station sign
|
* @param tile The location of the station sign
|
||||||
|
@@ -168,7 +168,7 @@ Station::~Station()
|
|||||||
CargoPacket::InvalidateAllFrom(this->index);
|
CargoPacket::InvalidateAllFrom(this->index);
|
||||||
|
|
||||||
_station_kdtree.Remove(this->index);
|
_station_kdtree.Remove(this->index);
|
||||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
|
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index, this->viewport_sign_kdtree_pt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -439,7 +439,7 @@ void Station::MoveSign(TileIndex new_xy)
|
|||||||
{
|
{
|
||||||
if (this->xy == new_xy) return;
|
if (this->xy == new_xy) return;
|
||||||
|
|
||||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
|
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index, this->viewport_sign_kdtree_pt));
|
||||||
_station_kdtree.Remove(this->index);
|
_station_kdtree.Remove(this->index);
|
||||||
|
|
||||||
this->BaseStation::MoveSign(new_xy);
|
this->BaseStation::MoveSign(new_xy);
|
||||||
|
@@ -3266,12 +3266,14 @@ ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeStation(StationID id)
|
|||||||
item.type = VKI_STATION;
|
item.type = VKI_STATION;
|
||||||
item.id.station = id;
|
item.id.station = id;
|
||||||
|
|
||||||
const Station *st = Station::Get(id);
|
Station *st = Station::Get(id);
|
||||||
Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
|
Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
|
||||||
|
|
||||||
pt.y -= 32 * ZOOM_LVL_BASE;
|
pt.y -= 32 * ZOOM_LVL_BASE;
|
||||||
if ((st->facilities & FACIL_AIRPORT) && st->airport.type == AT_OILRIG) pt.y -= 16 * ZOOM_LVL_BASE;
|
if ((st->facilities & FACIL_AIRPORT) && st->airport.type == AT_OILRIG) pt.y -= 16 * ZOOM_LVL_BASE;
|
||||||
|
|
||||||
|
st->viewport_sign_kdtree_pt = pt;
|
||||||
|
|
||||||
item.center = pt.x;
|
item.center = pt.x;
|
||||||
item.top = pt.y;
|
item.top = pt.y;
|
||||||
|
|
||||||
@@ -3281,17 +3283,29 @@ ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeStation(StationID id)
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeStation(StationID id, Point pt)
|
||||||
|
{
|
||||||
|
ViewportSignKdtreeItem item;
|
||||||
|
item.type = VKI_STATION;
|
||||||
|
item.id.station = id;
|
||||||
|
item.center = pt.x;
|
||||||
|
item.top = pt.y;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeWaypoint(StationID id)
|
ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeWaypoint(StationID id)
|
||||||
{
|
{
|
||||||
ViewportSignKdtreeItem item;
|
ViewportSignKdtreeItem item;
|
||||||
item.type = VKI_WAYPOINT;
|
item.type = VKI_WAYPOINT;
|
||||||
item.id.station = id;
|
item.id.station = id;
|
||||||
|
|
||||||
const Waypoint *st = Waypoint::Get(id);
|
Waypoint *st = Waypoint::Get(id);
|
||||||
Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
|
Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
|
||||||
|
|
||||||
pt.y -= 32 * ZOOM_LVL_BASE;
|
pt.y -= 32 * ZOOM_LVL_BASE;
|
||||||
|
|
||||||
|
st->viewport_sign_kdtree_pt = pt;
|
||||||
|
|
||||||
item.center = pt.x;
|
item.center = pt.x;
|
||||||
item.top = pt.y;
|
item.top = pt.y;
|
||||||
|
|
||||||
@@ -3301,6 +3315,16 @@ ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeWaypoint(StationID id)
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeWaypoint(StationID id, Point pt)
|
||||||
|
{
|
||||||
|
ViewportSignKdtreeItem item;
|
||||||
|
item.type = VKI_WAYPOINT;
|
||||||
|
item.id.station = id;
|
||||||
|
item.center = pt.x;
|
||||||
|
item.top = pt.y;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeTown(TownID id)
|
ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeTown(TownID id)
|
||||||
{
|
{
|
||||||
ViewportSignKdtreeItem item;
|
ViewportSignKdtreeItem item;
|
||||||
|
@@ -65,7 +65,9 @@ struct ViewportSignKdtreeItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ViewportSignKdtreeItem MakeStation(StationID id);
|
static ViewportSignKdtreeItem MakeStation(StationID id);
|
||||||
|
static ViewportSignKdtreeItem MakeStation(StationID id, Point pt);
|
||||||
static ViewportSignKdtreeItem MakeWaypoint(StationID id);
|
static ViewportSignKdtreeItem MakeWaypoint(StationID id);
|
||||||
|
static ViewportSignKdtreeItem MakeWaypoint(StationID id, Point pt);
|
||||||
static ViewportSignKdtreeItem MakeTown(TownID id);
|
static ViewportSignKdtreeItem MakeTown(TownID id);
|
||||||
static ViewportSignKdtreeItem MakeSign(SignID id);
|
static ViewportSignKdtreeItem MakeSign(SignID id);
|
||||||
};
|
};
|
||||||
|
@@ -56,6 +56,6 @@ Waypoint::~Waypoint()
|
|||||||
if (CleaningPool()) return;
|
if (CleaningPool()) return;
|
||||||
DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
|
DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
|
||||||
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
|
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
|
||||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
|
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index, this->viewport_sign_kdtree_pt));
|
||||||
TraceRestrictRemoveDestinationID(TROCAF_WAYPOINT, this->index);
|
TraceRestrictRemoveDestinationID(TROCAF_WAYPOINT, this->index);
|
||||||
}
|
}
|
||||||
|
@@ -245,7 +245,7 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
|
|||||||
need_sign_update = true;
|
need_sign_update = true;
|
||||||
} else if (!wp->IsInUse()) {
|
} else if (!wp->IsInUse()) {
|
||||||
/* Move existing (recently deleted) waypoint to the new location */
|
/* Move existing (recently deleted) waypoint to the new location */
|
||||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
|
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index, wp->viewport_sign_kdtree_pt));
|
||||||
wp->xy = start_tile;
|
wp->xy = start_tile;
|
||||||
need_sign_update = true;
|
need_sign_update = true;
|
||||||
}
|
}
|
||||||
@@ -320,7 +320,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
wp = new Waypoint(tile);
|
wp = new Waypoint(tile);
|
||||||
} else {
|
} else {
|
||||||
/* Move existing (recently deleted) buoy to the new location */
|
/* Move existing (recently deleted) buoy to the new location */
|
||||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
|
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index, wp->viewport_sign_kdtree_pt));
|
||||||
wp->xy = tile;
|
wp->xy = tile;
|
||||||
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
|
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user