add bounds to map render to prevent doing extra work when rendering only pieces of the map (eg, connections)

This commit is contained in:
garak 2023-01-06 16:17:42 -05:00 committed by t
parent 37fcfba829
commit 07caad3fce
2 changed files with 10 additions and 7 deletions

View file

@ -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);

View file

@ -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);
}