From 07caad3fce523c06389a14c0edafb6f99ca94371 Mon Sep 17 00:00:00 2001 From: garak Date: Fri, 6 Jan 2023 16:17:42 -0500 Subject: [PATCH] add bounds to map render to prevent doing extra work when rendering only pieces of the map (eg, connections) --- include/core/map.h | 2 +- src/core/map.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/core/map.h b/include/core/map.h index c2e3b0d0..50eea778 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -76,7 +76,7 @@ public: int getHeight(); int getBorderWidth(); int getBorderHeight(); - QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr); + QPixmap render(bool ignoreCache, MapLayout *fromLayout = nullptr, QRect bounds = QRect(0, 0, -1, -1)); QPixmap renderCollision(qreal opacity, bool ignoreCache); bool mapBlockChanged(int i, const Blockdata &cache); bool borderBlockChanged(int i, const Blockdata &cache); diff --git a/src/core/map.cpp b/src/core/map.cpp index c0ee4d77..48f95b50 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -139,7 +139,7 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) { return collision_pixmap; } -QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) { +QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout, QRect bounds) { bool changed_any = false; int width_ = getWidth(); int height_ = getHeight(); @@ -158,6 +158,12 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) { continue; } changed_any = true; + int map_y = width_ ? i / width_ : 0; + int map_x = width_ ? i % width_ : 0; + if (bounds.isValid() && !bounds.contains(map_x, map_y)) { + continue; + } + QPoint metatile_origin = QPoint(map_x * 16, map_y * 16); Block block = layout->blockdata.at(i); QImage metatile_image = getMetatileImage( block.metatileId, @@ -166,9 +172,6 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) { metatileLayerOrder, metatileLayerOpacity ); - int map_y = width_ ? i / width_ : 0; - int map_x = width_ ? i % width_ : 0; - QPoint metatile_origin = QPoint(map_x * 16, map_y * 16); painter.drawImage(metatile_origin, metatile_image); } painter.end(); @@ -219,7 +222,6 @@ QPixmap Map::renderBorder(bool ignoreCache) { } QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) { - render(true, fromLayout); int x, y, w, h; if (connection.direction == "up") { x = 0; @@ -248,8 +250,9 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) w = getWidth(); h = getHeight(); } + + render(true, fromLayout, QRect(x, y, w, h)); QImage connection_image = image.copy(x * 16, y * 16, w * 16, h * 16); - //connection_image = connection_image.convertToFormat(QImage::Format_Grayscale8); return QPixmap::fromImage(connection_image); }