summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-02-06 13:19:46 +0000
committeralberth <alberth@openttd.org>2010-02-06 13:19:46 +0000
commita6e8c747c9cc04ef800427ac852840d0de2b2c94 (patch)
treecc0c6320cedf311e6cd20924aa2b77259e40dba4
parent21589daea9d55878d029b641374caff10561fff3 (diff)
downloadopenttd-a6e8c747c9cc04ef800427ac852840d0de2b2c94.tar.xz
(svn r19041) -Codechange: Improve selection of tile to draw in zoomed-out smallmaps.
-rw-r--r--src/smallmap_gui.cpp71
-rw-r--r--src/tilearea.cpp10
-rw-r--r--src/tilearea_type.h2
3 files changed, 71 insertions, 12 deletions
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 259169073..573752138 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -256,6 +256,22 @@ static const AndOr _smallmap_vehicles_andor[] = {
typedef uint32 GetSmallMapPixels(TileIndex tile); ///< Typedef callthrough function
+/** Mapping of tile type to importance of the tile (higher number means more interesting to show). */
+static const byte _tiletype_importance[] = {
+ 2, // MP_CLEAR
+ 8, // MP_RAILWAY
+ 7, // MP_ROAD
+ 5, // MP_HOUSE
+ 2, // MP_TREES
+ 9, // MP_STATION
+ 2, // MP_WATER
+ 1, // MP_VOID
+ 6, // MP_INDUSTRY
+ 8, // MP_TUNNELBRIDGE
+ 2, // MP_UNMOVABLE
+ 0,
+};
+
static inline TileType GetEffectiveTileType(TileIndex tile)
{
@@ -564,6 +580,26 @@ class SmallMapWindow : public Window {
}
/**
+ * Decide which tile to show to the user from a group of tiles.
+ * @param ta Tile area to investigate.
+ * @return Most interesting tile. May be #INVALID_TILE if off-map.
+ */
+ inline TileIndex GetMostImportantTileFromGroup(const TileArea &ta) const
+ {
+ int importance = 0;
+ TileIndex tile = INVALID_TILE;
+
+ TILE_AREA_LOOP(ti, ta) {
+ TileType ttype = GetEffectiveTileType(ti);
+ if (_tiletype_importance[ttype] > importance) {
+ importance = _tiletype_importance[ttype];
+ tile = ti;
+ }
+ }
+ return tile;
+ }
+
+ /**
* Draws one column of tiles of the small map in a certain mode onto the screen buffer, skipping the shifted rows in between.
*
* @param dst Pointer to a part of the screen buffer to write to.
@@ -585,18 +621,29 @@ class SmallMapWindow : public Window {
do {
/* Check if the tile (xc,yc) is within the map range */
- if (IsInsideMM(xc, min_xy, MapMaxX()) && IsInsideMM(yc, min_xy, MapMaxY())) {
- /* Check if the dst pointer points to a pixel inside the screen buffer */
- if (dst < _screen.dst_ptr) continue;
- if (dst >= dst_ptr_abs_end) continue;
-
- uint32 val = proc(TileXY(xc, yc));
- uint8 *val8 = (uint8 *)&val;
- int idx = max(0, -start_pos);
- for (int pos = max(0, start_pos); pos < end_pos; pos++) {
- blitter->SetPixel(dst, idx, 0, val8[idx]);
- idx++;
- }
+ if (xc >= MapMaxX() || yc >= MapMaxY()) continue;
+
+ /* Check if the dst pointer points to a pixel inside the screen buffer */
+ if (dst < _screen.dst_ptr) continue;
+ if (dst >= dst_ptr_abs_end) continue;
+
+ /* Construct tilearea covered by (xc, yc, xc + this->zoom, yc + this->zoom) such that it is within min_xy limits. */
+ TileArea ta;
+ if (min_xy == 1 && (xc == 0 || yc == 0)) {
+ if (this->zoom == 1) continue; // The tile area is empty, don't draw anything.
+
+ ta = TileArea(TileXY(max(min_xy, xc), max(min_xy, yc)), this->zoom - (xc == 0), this->zoom - (yc == 0));
+ } else {
+ ta = TileArea(TileXY(xc, yc), this->zoom, this->zoom);
+ }
+ ta.ClampToMap(); // Clamp to map boundaries (may contain MP_VOID tiles!).
+
+ uint32 val = proc(this->GetMostImportantTileFromGroup(ta));
+ uint8 *val8 = (uint8 *)&val;
+ int idx = max(0, -start_pos);
+ for (int pos = max(0, start_pos); pos < end_pos; pos++) {
+ blitter->SetPixel(dst, idx, 0, val8[idx]);
+ idx++;
}
/* Switch to next tile in the column */
} while (xc += this->zoom, yc += this->zoom, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
diff --git a/src/tilearea.cpp b/src/tilearea.cpp
index 81efe96be..fb3e11394 100644
--- a/src/tilearea.cpp
+++ b/src/tilearea.cpp
@@ -95,3 +95,13 @@ bool TileArea::Intersects(const TileArea &ta) const
);
}
+/**
+ * Clamp the tile area to map borders.
+ */
+void TileArea::ClampToMap()
+{
+ assert(this->tile < MapSize());
+ this->w = min(this->w, MapSizeX() - TileX(this->tile));
+ this->h = min(this->h, MapSizeY() - TileY(this->tile));
+}
+
diff --git a/src/tilearea_type.h b/src/tilearea_type.h
index 15045cb11..4eeaf1e48 100644
--- a/src/tilearea_type.h
+++ b/src/tilearea_type.h
@@ -47,6 +47,8 @@ struct TileArea {
}
bool Intersects(const TileArea &ta) const;
+
+ void ClampToMap();
};
#endif /* TILEAREA_TYPE_H */