add bounds to map render to prevent doing extra work when rendering only pieces of the map (eg, connections)
This commit is contained in:
parent
37fcfba829
commit
07caad3fce
2 changed files with 10 additions and 7 deletions
|
@ -76,7 +76,7 @@ public:
|
||||||
int getHeight();
|
int getHeight();
|
||||||
int getBorderWidth();
|
int getBorderWidth();
|
||||||
int getBorderHeight();
|
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);
|
QPixmap renderCollision(qreal opacity, bool ignoreCache);
|
||||||
bool mapBlockChanged(int i, const Blockdata &cache);
|
bool mapBlockChanged(int i, const Blockdata &cache);
|
||||||
bool borderBlockChanged(int i, const Blockdata &cache);
|
bool borderBlockChanged(int i, const Blockdata &cache);
|
||||||
|
|
|
@ -139,7 +139,7 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
|
||||||
return collision_pixmap;
|
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;
|
bool changed_any = false;
|
||||||
int width_ = getWidth();
|
int width_ = getWidth();
|
||||||
int height_ = getHeight();
|
int height_ = getHeight();
|
||||||
|
@ -158,6 +158,12 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
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);
|
Block block = layout->blockdata.at(i);
|
||||||
QImage metatile_image = getMetatileImage(
|
QImage metatile_image = getMetatileImage(
|
||||||
block.metatileId,
|
block.metatileId,
|
||||||
|
@ -166,9 +172,6 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) {
|
||||||
metatileLayerOrder,
|
metatileLayerOrder,
|
||||||
metatileLayerOpacity
|
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.drawImage(metatile_origin, metatile_image);
|
||||||
}
|
}
|
||||||
painter.end();
|
painter.end();
|
||||||
|
@ -219,7 +222,6 @@ QPixmap Map::renderBorder(bool ignoreCache) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) {
|
QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout) {
|
||||||
render(true, fromLayout);
|
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
if (connection.direction == "up") {
|
if (connection.direction == "up") {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -248,8 +250,9 @@ QPixmap Map::renderConnection(MapConnection connection, MapLayout * fromLayout)
|
||||||
w = getWidth();
|
w = getWidth();
|
||||||
h = getHeight();
|
h = getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render(true, fromLayout, QRect(x, y, w, h));
|
||||||
QImage connection_image = image.copy(x * 16, y * 16, w * 16, h * 16);
|
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);
|
return QPixmap::fromImage(connection_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue