mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
(svn r23702) -Codechange: avoid using TileAddWrap() in FindStationsAroundTiles() by finding out where the border is in advance, speeding up the function with a factor 3 (you got to love random statistics which has no real meaning in the grand scheme of it all :D)
This commit is contained in:
parent
6f6035ce0b
commit
3b2ecfab01
@ -3392,19 +3392,37 @@ CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||
void FindStationsAroundTiles(const TileArea &location, StationList *stations)
|
||||
{
|
||||
/* area to search = producer plus station catchment radius */
|
||||
int max_rad = (_settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED);
|
||||
uint max_rad = (_settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED);
|
||||
|
||||
for (int dy = -max_rad; dy < location.h + max_rad; dy++) {
|
||||
for (int dx = -max_rad; dx < location.w + max_rad; dx++) {
|
||||
TileIndex cur_tile = TileAddWrap(location.tile, dx, dy);
|
||||
if (cur_tile == INVALID_TILE || !IsTileType(cur_tile, MP_STATION)) continue;
|
||||
uint x = TileX(location.tile);
|
||||
uint y = TileY(location.tile);
|
||||
|
||||
uint min_x = (x > max_rad) ? x - max_rad : 0;
|
||||
uint max_x = x + location.w + max_rad;
|
||||
uint min_y = (y > max_rad) ? y - max_rad : 0;
|
||||
uint max_y = y + location.h + max_rad;
|
||||
|
||||
if (min_x == 0 && _settings_game.construction.freeform_edges) min_x = 1;
|
||||
if (min_y == 0 && _settings_game.construction.freeform_edges) min_y = 1;
|
||||
if (max_x >= MapSizeX()) max_x = MapSizeX() - 1;
|
||||
if (max_y >= MapSizeY()) max_y = MapSizeY() - 1;
|
||||
|
||||
for (uint cy = min_y; cy < max_y; cy++) {
|
||||
for (uint cx = min_x; cx < max_x; cx++) {
|
||||
TileIndex cur_tile = TileXY(cx, cy);
|
||||
if (!IsTileType(cur_tile, MP_STATION)) continue;
|
||||
|
||||
Station *st = Station::GetByTile(cur_tile);
|
||||
/* st can be NULL in case of waypoints */
|
||||
if (st == NULL) continue;
|
||||
|
||||
if (_settings_game.station.modified_catchment) {
|
||||
int rad = st->GetCatchmentRadius();
|
||||
if (dx < -rad || dx >= rad + location.w || dy < -rad || dy >= rad + location.h) continue;
|
||||
int rad_x = cx - x;
|
||||
int rad_y = cy - y;
|
||||
|
||||
if (rad_x < -rad || rad_x >= rad + location.w) continue;
|
||||
if (rad_y < -rad || rad_y >= rad + location.h) continue;
|
||||
}
|
||||
|
||||
/* Insert the station in the set. This will fail if it has
|
||||
|
Loading…
Reference in New Issue
Block a user