diff options
author | rubidium <rubidium@openttd.org> | 2014-02-06 21:01:50 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2014-02-06 21:01:50 +0000 |
commit | d05ff6e77b401c87b69bdc68ce2d6652f431b667 (patch) | |
tree | 7f0b82aa75741c3de083c4cec011e7ffe01d733f /src | |
parent | fcb122124b042d343f38abe547e83f78ef848359 (diff) | |
download | openttd-d05ff6e77b401c87b69bdc68ce2d6652f431b667.tar.xz |
(svn r26311) -Codechange: use a different method for finding whether there is a nearby town when the map has thousands of towns (MJP)
Diffstat (limited to 'src')
-rw-r--r-- | src/town_cmd.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 13616a2cc..09ca7cee9 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -340,6 +340,24 @@ static void AnimateTile_Town(TileIndex tile) */ static bool IsCloseToTown(TileIndex tile, uint dist) { + /* On a large map with many towns, it may be faster to check the surroundings of the tile. + * An iteration in TILE_AREA_LOOP() is generally 2 times faster than one in FOR_ALL_TOWNS(). */ + if (Town::GetNumItems() > (size_t) (dist * dist * 2)) { + const int tx = TileX(tile); + const int ty = TileY(tile); + TileArea tile_area = TileArea( + TileXY(max(0, tx - (int) dist), max(0, ty - (int) dist)), + TileXY(min(MapMaxX(), tx + (int) dist), min(MapMaxY(), ty + (int) dist)) + ); + TILE_AREA_LOOP(atile, tile_area) { + if (GetTileType(atile) == MP_HOUSE) { + Town *t = Town::GetByTile(atile); + if (DistanceManhattan(tile, t->xy) < dist) return true; + } + } + return false; + } + const Town *t; FOR_ALL_TOWNS(t) { |