Fix plans/route line viewport mark dirty not being wide enough

This commit is contained in:
Jonathan G Rennison
2020-10-02 03:05:31 +01:00
parent b4ceb93406
commit 7e68459ebd

View File

@@ -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 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 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; const int block_shift = 2 + vp->zoom;
int y1 = from_pt.y / block_radius;
const int x2 = to_pt.x / block_radius;
const int y2 = to_pt.y / block_radius;
/* http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Simplification */ int x1 = from_pt.x >> block_shift;
const int dx = abs(x2 - x1); int y1 = from_pt.y >> block_shift;
const int dy = abs(y2 - y1); const int x2 = to_pt.x >> block_shift;
const int sx = (x1 < x2) ? 1 : -1; const int y2 = to_pt.y >> block_shift;
const int sy = (y1 < y2) ? 1 : -1;
int err = dx - dy; /* http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Simplification */
for (;;) { const int dx = abs(x2 - x1);
MarkAllViewportsDirty( const int dy = abs(y2 - y1);
(x1 - 1) * block_radius, const int sx = (x1 < x2) ? 1 : -1;
(y1 - 1) * block_radius, const int sy = (y1 < y2) ? 1 : -1;
(x1 + 1) * block_radius, int err = dx - dy;
(y1 + 1) * block_radius, for (;;) {
flags MarkViewportDirty(
); vp,
if (x1 == x2 && y1 == y2) break; (x1 - 1) << block_shift,
const int e2 = 2 * err; (y1 - 1) << block_shift,
if (e2 > -dy) { (x1 + 2) << block_shift,
err -= dy; (y1 + 2) << block_shift,
x1 += sx; flags
} );
if (e2 < dx) { if (x1 == x2 && y1 == y2) break;
err += dx; const int e2 = 2 * err;
y1 += sy; if (e2 > -dy) {
err -= dy;
x1 += sx;
}
if (e2 < dx) {
err += dx;
y1 += sy;
}
} }
} }
} }