Fix border block cache usage
This commit is contained in:
parent
2792869e45
commit
5cf0e35ffc
2 changed files with 23 additions and 5 deletions
|
@ -59,7 +59,8 @@ public:
|
||||||
int getHeight();
|
int getHeight();
|
||||||
QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr);
|
QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr);
|
||||||
QPixmap renderCollision(qreal opacity, bool ignoreCache);
|
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 cacheBlockdata();
|
||||||
void cacheCollision();
|
void cacheCollision();
|
||||||
Block *getBlock(int x, int y);
|
Block *getBlock(int x, int y);
|
||||||
|
|
|
@ -59,7 +59,7 @@ int Map::getHeight() {
|
||||||
return layout->height.toInt(nullptr, 0);
|
return layout->height.toInt(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::blockChanged(int i, Blockdata *cache) {
|
bool Map::mapBlockChanged(int i, Blockdata * cache) {
|
||||||
if (!cache)
|
if (!cache)
|
||||||
return true;
|
return true;
|
||||||
if (!layout->blockdata)
|
if (!layout->blockdata)
|
||||||
|
@ -76,6 +76,23 @@ bool Map::blockChanged(int i, Blockdata *cache) {
|
||||||
return layout->blockdata->blocks->value(i) != cache->blocks->value(i);
|
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() {
|
void Map::cacheBorder() {
|
||||||
if (layout->cached_border) delete layout->cached_border;
|
if (layout->cached_border) delete layout->cached_border;
|
||||||
layout->cached_border = new Blockdata;
|
layout->cached_border = new Blockdata;
|
||||||
|
@ -127,7 +144,7 @@ QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
|
||||||
}
|
}
|
||||||
QPainter painter(&collision_image);
|
QPainter painter(&collision_image);
|
||||||
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
|
@ -171,7 +188,7 @@ QPixmap Map::render(bool ignoreCache = false, MapLayout * fromLayout) {
|
||||||
|
|
||||||
QPainter painter(&image);
|
QPainter painter(&image);
|
||||||
for (int i = 0; i < layout->blockdata->blocks->length(); i++) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
|
@ -209,7 +226,7 @@ QPixmap Map::renderBorder() {
|
||||||
}
|
}
|
||||||
QPainter painter(&layout->border_image);
|
QPainter painter(&layout->border_image);
|
||||||
for (int i = 0; i < layout->border->blocks->length(); i++) {
|
for (int i = 0; i < layout->border->blocks->length(); i++) {
|
||||||
if (!blockChanged(i, layout->cached_border)) {
|
if (!borderBlockChanged(i, layout->cached_border)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
|
|
Loading…
Reference in a new issue