Index: src/tunnelbridge_cmd.cpp
===================================================================
--- src/tunnelbridge_cmd.cpp (revision 27156)
+++ src/tunnelbridge_cmd.cpp (working copy)
@@ -52,6 +52,33 @@
/** Z position of the bridge sprites relative to bridge height (downwards) */
static const int BRIDGE_Z_START = 3;
+
+/**
+ * Mark bridge tiles dirty.
+ * Note: The bridge does not need to exist, everything is passed via parameters.
+ * @param begin Start tile.
+ * @param end End tile.
+ * @param direction Direction from \a begin to \a end.
+ * @param bridge_height Bridge height level.
+ */
+void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
+{
+ TileIndexDiff delta = TileOffsByDiagDir(direction);
+ for (TileIndex t = begin; t != end; t += delta) {
+ MarkTileDirtyByTile(t, bridge_height - TileHeight(t));
+ }
+ MarkTileDirtyByTile(end);
+}
+
+/**
+ * Mark bridge tiles dirty.
+ * @param tile Bridge head.
+ */
+void MarkBridgeDirty(TileIndex tile)
+{
+ MarkBridgeDirty(tile, GetOtherTunnelBridgeEnd(tile), GetTunnelBridgeDirection(tile), GetBridgeHeight(tile));
+}
+
/** Reset the data been eventually changed by the grf loaded. */
void ResetBridges()
{
@@ -506,10 +533,7 @@
}
/* Mark all tiles dirty */
- TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
- for (TileIndex tile = tile_start; tile <= tile_end; tile += delta) {
- MarkTileDirtyByTile(tile);
- }
+ MarkBridgeDirty(tile_start, tile_end, AxisToDiagDir(direction), z_start);
DirtyCompanyInfrastructureWindows(owner);
}
@@ -926,7 +950,7 @@
if (height < minz) SetRoadside(c, ROADSIDE_PAVED);
}
ClearBridgeMiddle(c);
- MarkTileDirtyByTile(c);
+ MarkTileDirtyByTile(c, height - TileHeight(c));
}
if (rail) {
Index: src/rail_cmd.cpp
===================================================================
--- src/rail_cmd.cpp (revision 27156)
+++ src/rail_cmd.cpp (working copy)
@@ -1688,13 +1688,11 @@
YapfNotifyTrackLayoutChange(tile, track);
YapfNotifyTrackLayoutChange(endtile, track);
- MarkTileDirtyByTile(tile);
- MarkTileDirtyByTile(endtile);
-
if (IsBridge(tile)) {
- TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
- TileIndex t = tile + delta;
- for (; t != endtile; t += delta) MarkTileDirtyByTile(t); // TODO encapsulate this into a function
+ MarkBridgeDirty(tile);
+ } else {
+ MarkTileDirtyByTile(tile);
+ MarkTileDirtyByTile(endtile);
}
}
Index: src/road_cmd.cpp
===================================================================
--- src/road_cmd.cpp (revision 27156)
+++ src/road_cmd.cpp (working copy)
@@ -246,12 +246,11 @@
}
/* Mark tiles dirty that have been repaved */
- MarkTileDirtyByTile(tile);
- MarkTileDirtyByTile(other_end);
if (IsBridge(tile)) {
- TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
-
- for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
+ MarkBridgeDirty(tile);
+ } else {
+ MarkTileDirtyByTile(tile);
+ MarkTileDirtyByTile(other_end);
}
}
} else {
@@ -747,12 +746,11 @@
SetRoadOwner(tile, rt, company);
/* Mark tiles dirty that have been repaved */
- MarkTileDirtyByTile(other_end);
- MarkTileDirtyByTile(tile);
if (IsBridge(tile)) {
- TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
-
- for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
+ MarkBridgeDirty(tile);
+ } else {
+ MarkTileDirtyByTile(other_end);
+ MarkTileDirtyByTile(tile);
}
break;
}
Index: src/viewport_func.h
===================================================================
--- src/viewport_func.h (revision 27156)
+++ src/viewport_func.h (working copy)
@@ -77,7 +77,7 @@
extern Point _tile_fract_coords;
-void MarkTileDirtyByTile(TileIndex tile);
+void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0);
int GetRowAtTile(int viewport_y, Point tile, bool bridge_correct);
void MarkTileDirtyByTileOutsideMap(int x, int y);
Index: src/tunnelbridge.h
===================================================================
--- src/tunnelbridge.h (revision 27156)
+++ src/tunnelbridge.h (working copy)
@@ -14,6 +14,9 @@
#include "map_func.h"
+void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height);
+void MarkBridgeDirty(TileIndex tile);
+
/**
* Calculates the length of a tunnel or a bridge (without end tiles)
* @param begin The begin of the tunnel or bridge.
Index: src/viewport.cpp
===================================================================
--- src/viewport.cpp (revision 27156)
+++ src/viewport.cpp (working copy)
@@ -2232,14 +2232,15 @@
/**
* Mark a tile given by its index dirty for repaint.
* @param tile The tile to mark dirty.
+ * @param bridge_level_offset Height of bridge on tile to also mark dirty. (Height level relative to north corner.)
* @ingroup dirty
*/
-void MarkTileDirtyByTile(TileIndex tile)
+void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
{
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, TilePixelHeight(tile));
MarkAllViewportsDirty(
pt.x - MAX_TILE_EXTENT_LEFT,
- pt.y - MAX_TILE_EXTENT_TOP,
+ pt.y - MAX_TILE_EXTENT_TOP - ZOOM_LVL_BASE * TILE_HEIGHT * bridge_level_offset,
pt.x + MAX_TILE_EXTENT_RIGHT,
pt.y + MAX_TILE_EXTENT_BOTTOM);
}