From 24ad8759db655eb02db47f22a67c9e1f1c0783c7 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 17 Jun 2021 17:27:03 +0100 Subject: [PATCH] Viewport map: Improve handling of sloped tile rendering --- src/viewport.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/viewport.cpp b/src/viewport.cpp index 7c02aadffa..e5b49206e0 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2912,16 +2912,21 @@ uint32 ViewportMapGetColour(const Viewport * const vp, uint x, uint y, const uin /* Very approximative but fast way to get the tile when taking Z into account. */ const TileIndex tile_tmp = TileVirtXY(x, y); const uint z = TileHeight(tile_tmp) * 4; + if (x + z >= MapSizeX() << 4) { + /* Wrapping of tile X coordinate causes a graphic glitch below south west border. */ + return 0; + } TileIndex tile = TileVirtXY(x + z, y + z); if (tile >= MapSize()) return 0; - if (_settings_game.construction.freeform_edges) { - /* tile_tmp and tile must be from the same side, - * otherwise it's an approximation erroneous case - * that leads to a graphic glitch below south west border. - */ - if (TileX(tile_tmp) > (MapSizeX() - (MapSizeX() / 8))) - if ((TileX(tile_tmp) < (MapSizeX() / 2)) != (TileX(tile) < (MapSizeX() / 2))) - return 0; + const uint z2 = TileHeight(tile) * 4; + if (unlikely(z2 != z)) { + const uint approx_z = (z + z2) / 2; + if (x + approx_z >= MapSizeX() << 4) { + /* Wrapping of tile X coordinate causes a graphic glitch below south west border. */ + return 0; + } + tile = TileVirtXY(x + approx_z, y + approx_z); + if (tile >= MapSize()) return 0; } TileType tile_type = MP_VOID; tile = ViewportMapGetMostSignificantTileType(vp, tile, &tile_type);