Loading

Paste #p2iqizede

  1. Index: src/tunnelbridge_cmd.cpp
  2. ===================================================================
  3. --- src/tunnelbridge_cmd.cpp    (revision 27156)
  4. +++ src/tunnelbridge_cmd.cpp    (working copy)
  5. @@ -52,6 +52,33 @@
  6.  /** Z position of the bridge sprites relative to bridge height (downwards) */
  7.  static const int BRIDGE_Z_START = 3;
  8.  
  9. +
  10. +/**
  11. + * Mark bridge tiles dirty.
  12. + * Note: The bridge does not need to exist, everything is passed via parameters.
  13. + * @param begin Start tile.
  14. + * @param end End tile.
  15. + * @param direction Direction from \a begin to \a end.
  16. + * @param bridge_height Bridge height level.
  17. + */
  18. +void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
  19. +{
  20. +   TileIndexDiff delta = TileOffsByDiagDir(direction);
  21. +   for (TileIndex t = begin; t != end; t += delta) {
  22. +       MarkTileDirtyByTile(t, bridge_height - TileHeight(t));
  23. +   }
  24. +   MarkTileDirtyByTile(end);
  25. +}
  26. +
  27. +/**
  28. + * Mark bridge tiles dirty.
  29. + * @param tile Bridge head.
  30. + */
  31. +void MarkBridgeDirty(TileIndex tile)
  32. +{
  33. +   MarkBridgeDirty(tile, GetOtherTunnelBridgeEnd(tile), GetTunnelBridgeDirection(tile), GetBridgeHeight(tile));
  34. +}
  35. +
  36.  /** Reset the data been eventually changed by the grf loaded. */
  37.  void ResetBridges()
  38.  {
  39. @@ -506,10 +533,7 @@
  40.         }
  41.  
  42.         /* Mark all tiles dirty */
  43. -       TileIndexDiff delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
  44. -       for (TileIndex tile = tile_start; tile <= tile_end; tile += delta) {
  45. -           MarkTileDirtyByTile(tile);
  46. -       }
  47. +       MarkBridgeDirty(tile_start, tile_end, AxisToDiagDir(direction), z_start);
  48.         DirtyCompanyInfrastructureWindows(owner);
  49.     }
  50.  
  51. @@ -926,7 +950,7 @@
  52.                 if (height < minz) SetRoadside(c, ROADSIDE_PAVED);
  53.             }
  54.             ClearBridgeMiddle(c);
  55. -           MarkTileDirtyByTile(c);
  56. +           MarkTileDirtyByTile(c, height - TileHeight(c));
  57.         }
  58.  
  59.         if (rail) {
  60. Index: src/rail_cmd.cpp
  61. ===================================================================
  62. --- src/rail_cmd.cpp    (revision 27156)
  63. +++ src/rail_cmd.cpp    (working copy)
  64. @@ -1688,13 +1688,11 @@
  65.                     YapfNotifyTrackLayoutChange(tile, track);
  66.                     YapfNotifyTrackLayoutChange(endtile, track);
  67.  
  68. -                   MarkTileDirtyByTile(tile);
  69. -                   MarkTileDirtyByTile(endtile);
  70. -
  71.                     if (IsBridge(tile)) {
  72. -                       TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
  73. -                       TileIndex t = tile + delta;
  74. -                       for (; t != endtile; t += delta) MarkTileDirtyByTile(t); // TODO encapsulate this into a function
  75. +                       MarkBridgeDirty(tile);
  76. +                   } else {
  77. +                       MarkTileDirtyByTile(tile);
  78. +                       MarkTileDirtyByTile(endtile);
  79.                     }
  80.                 }
  81.  
  82. Index: src/road_cmd.cpp
  83. ===================================================================
  84. --- src/road_cmd.cpp    (revision 27156)
  85. +++ src/road_cmd.cpp    (working copy)
  86. @@ -246,12 +246,11 @@
  87.                 }
  88.  
  89.                 /* Mark tiles dirty that have been repaved */
  90. -               MarkTileDirtyByTile(tile);
  91. -               MarkTileDirtyByTile(other_end);
  92.                 if (IsBridge(tile)) {
  93. -                   TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
  94. -
  95. -                   for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
  96. +                   MarkBridgeDirty(tile);
  97. +               } else {
  98. +                   MarkTileDirtyByTile(tile);
  99. +                   MarkTileDirtyByTile(other_end);
  100.                 }
  101.             }
  102.         } else {
  103. @@ -747,12 +746,11 @@
  104.                 SetRoadOwner(tile, rt, company);
  105.  
  106.                 /* Mark tiles dirty that have been repaved */
  107. -               MarkTileDirtyByTile(other_end);
  108. -               MarkTileDirtyByTile(tile);
  109.                 if (IsBridge(tile)) {
  110. -                   TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
  111. -
  112. -                   for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
  113. +                   MarkBridgeDirty(tile);
  114. +               } else {
  115. +                   MarkTileDirtyByTile(other_end);
  116. +                   MarkTileDirtyByTile(tile);
  117.                 }
  118.                 break;
  119.             }
  120. Index: src/viewport_func.h
  121. ===================================================================
  122. --- src/viewport_func.h (revision 27156)
  123. +++ src/viewport_func.h (working copy)
  124. @@ -77,7 +77,7 @@
  125.  
  126.  extern Point _tile_fract_coords;
  127.  
  128. -void MarkTileDirtyByTile(TileIndex tile);
  129. +void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = 0);
  130.  
  131.  int GetRowAtTile(int viewport_y, Point tile, bool bridge_correct);
  132.  void MarkTileDirtyByTileOutsideMap(int x, int y);
  133. Index: src/tunnelbridge.h
  134. ===================================================================
  135. --- src/tunnelbridge.h  (revision 27156)
  136. +++ src/tunnelbridge.h  (working copy)
  137. @@ -14,6 +14,9 @@
  138.  
  139.  #include "map_func.h"
  140.  
  141. +void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height);
  142. +void MarkBridgeDirty(TileIndex tile);
  143. +
  144.  /**
  145.   * Calculates the length of a tunnel or a bridge (without end tiles)
  146.   * @param begin The begin of the tunnel or bridge.
  147. Index: src/viewport.cpp
  148. ===================================================================
  149. --- src/viewport.cpp    (revision 27156)
  150. +++ src/viewport.cpp    (working copy)
  151. @@ -2232,14 +2232,15 @@
  152.  /**
  153.   * Mark a tile given by its index dirty for repaint.
  154.   * @param tile The tile to mark dirty.
  155. + * @param bridge_level_offset Height of bridge on tile to also mark dirty. (Height level relative to north corner.)
  156.   * @ingroup dirty
  157.   */
  158. -void MarkTileDirtyByTile(TileIndex tile)
  159. +void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
  160.  {
  161.     Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, TilePixelHeight(tile));
  162.     MarkAllViewportsDirty(
  163.             pt.x - MAX_TILE_EXTENT_LEFT,
  164. -           pt.y - MAX_TILE_EXTENT_TOP,
  165. +           pt.y - MAX_TILE_EXTENT_TOP - ZOOM_LVL_BASE * TILE_HEIGHT * bridge_level_offset,
  166.             pt.x + MAX_TILE_EXTENT_RIGHT,
  167.             pt.y + MAX_TILE_EXTENT_BOTTOM);
  168.  }
  169.  

Comments