From 5cf0e35ffccb57f25d46266cfb51076457763383 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 13 Mar 2020 14:24:57 -0400 Subject: [PATCH] Fix border block cache usage --- include/core/map.h | 3 ++- src/core/map.cpp | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/core/map.h b/include/core/map.h index 8ecc0a9e..74ba4f20 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -59,7 +59,8 @@ public: int getHeight(); QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr); QPixmap renderCollision(qreal opacity, bool ignoreCache); - bool blockChanged(int, Blockdata*); + bool mapBlockChanged(int i, Blockdata * cache); + bool borderBlockChanged(int i, Blockdata * cache); void cacheBlockdata(); void cacheCollision(); Block *getBlock(int x, int y); diff --git a/src/core/map.cpp b/src/core/map.cpp index f9df72fd..c4dfee2d 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -59,7 +59,7 @@ int Map::getHeight() { return layout->height.toInt(nullptr, 0); } -bool Map::blockChanged(int i, Blockdata *cache) { +bool Map::mapBlockChanged(int i, Blockdata * cache) { if (!cache) return true; if (!layout->blockdata) @@ -76,6 +76,23 @@ bool Map::blockChanged(int i, Blockdata *cache) { return layout->blockdata->blocks->value(i) != cache->blocks->value(i); } +bool Map::borderBlockChanged(int i, Blockdata * cache) { + if (!cache) + return true; + if (!layout->border) + return true; + if (!cache->blocks) + return true; + if (!layout->border->blocks) + return true; + if (cache->blocks->length() <= i) + return true; + if (layout->border->blocks->length() <= i) + return true; + + return layout->border->blocks->value(i) != cache->blocks->value(i); +} + void Map::cacheBorder() { if (layout->cached_border) delete layout->cached_border; layout->cached_border = new Blockdata; @@ -127,7 +144,7 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) { } QPainter painter(&collision_image); for (int i = 0; i < layout->blockdata->blocks->length(); i++) { - if (!ignoreCache && layout->cached_collision && !blockChanged(i, layout->cached_collision)) { + if (!ignoreCache && layout->cached_collision && !mapBlockChanged(i, layout->cached_collision)) { continue; } changed_any = true; @@ -171,7 +188,7 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) { QPainter painter(&image); for (int i = 0; i < layout->blockdata->blocks->length(); i++) { - if (!ignoreCache && !blockChanged(i, layout->cached_blockdata)) { + if (!ignoreCache && !mapBlockChanged(i, layout->cached_blockdata)) { continue; } changed_any = true; @@ -209,7 +226,7 @@ QPixmap Map::renderBorder() { } QPainter painter(&layout->border_image); for (int i = 0; i < layout->border->blocks->length(); i++) { - if (!blockChanged(i, layout->cached_border)) { + if (!borderBlockChanged(i, layout->cached_border)) { continue; } changed_any = true;