From 7e68459ebdb0f0db3c6c8f933b76bd38170ed722 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 2 Oct 2020 03:05:31 +0100 Subject: [PATCH] Fix plans/route line viewport mark dirty not being wide enough --- src/viewport.cpp | 61 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/viewport.cpp b/src/viewport.cpp index 2f5f7e5d6c..0249215b5e 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -3703,36 +3703,41 @@ void MarkTileLineDirty(const TileIndex from_tile, const TileIndex to_tile, Viewp const Point from_pt = RemapCoords2(TileX(from_tile) * TILE_SIZE + TILE_SIZE / 2, TileY(from_tile) * TILE_SIZE + TILE_SIZE / 2); const Point to_pt = RemapCoords2(TileX(to_tile) * TILE_SIZE + TILE_SIZE / 2, TileY(to_tile) * TILE_SIZE + TILE_SIZE / 2); - const int block_radius = 20; + for (Viewport * const vp : _viewport_window_cache) { + if (flags & VMDF_NOT_MAP_MODE && vp->zoom >= ZOOM_LVL_DRAW_MAP) continue; - int x1 = from_pt.x / block_radius; - int y1 = from_pt.y / block_radius; - const int x2 = to_pt.x / block_radius; - const int y2 = to_pt.y / block_radius; + const int block_shift = 2 + vp->zoom; - /* http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Simplification */ - const int dx = abs(x2 - x1); - const int dy = abs(y2 - y1); - const int sx = (x1 < x2) ? 1 : -1; - const int sy = (y1 < y2) ? 1 : -1; - int err = dx - dy; - for (;;) { - MarkAllViewportsDirty( - (x1 - 1) * block_radius, - (y1 - 1) * block_radius, - (x1 + 1) * block_radius, - (y1 + 1) * block_radius, - flags - ); - if (x1 == x2 && y1 == y2) break; - const int e2 = 2 * err; - if (e2 > -dy) { - err -= dy; - x1 += sx; - } - if (e2 < dx) { - err += dx; - y1 += sy; + int x1 = from_pt.x >> block_shift; + int y1 = from_pt.y >> block_shift; + const int x2 = to_pt.x >> block_shift; + const int y2 = to_pt.y >> block_shift; + + /* http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Simplification */ + const int dx = abs(x2 - x1); + const int dy = abs(y2 - y1); + const int sx = (x1 < x2) ? 1 : -1; + const int sy = (y1 < y2) ? 1 : -1; + int err = dx - dy; + for (;;) { + MarkViewportDirty( + vp, + (x1 - 1) << block_shift, + (y1 - 1) << block_shift, + (x1 + 2) << block_shift, + (y1 + 2) << block_shift, + flags + ); + if (x1 == x2 && y1 == y2) break; + const int e2 = 2 * err; + if (e2 > -dy) { + err -= dy; + x1 += sx; + } + if (e2 < dx) { + err += dx; + y1 += sy; + } } } }