summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-12-31 23:14:35 +0300
committerAndrei Karas <akaras@inbox.ru>2017-01-03 01:35:16 +0300
commit47987b945116130195563ae2aca068973063bfe5 (patch)
tree107db7a48b9763ce0c21639d9147cbc034d5b8bd
parent896d41e4b073046c59933ea8829474bd82b9c506 (diff)
downloadmanaverse-47987b945116130195563ae2aca068973063bfe5.tar.gz
manaverse-47987b945116130195563ae2aca068973063bfe5.tar.bz2
manaverse-47987b945116130195563ae2aca068973063bfe5.tar.xz
manaverse-47987b945116130195563ae2aca068973063bfe5.zip
Fix drawing layers after previous commits.
Add unit tests for layer caching functions.
-rw-r--r--src/resources/map/maplayer.cpp121
-rw-r--r--src/resources/map/maplayer.h6
-rw-r--r--src/resources/map/maplayer_unittest.cc661
3 files changed, 755 insertions, 33 deletions
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp
index 249e67fdd..c17b93fe6 100644
--- a/src/resources/map/maplayer.cpp
+++ b/src/resources/map/maplayer.cpp
@@ -127,6 +127,24 @@ void MapLayer::draw(Graphics *const graphics,
const int dx = mPixelX - scrollX;
const int dy = mPixelY - scrollY;
+/*
+ logger->log("draw layer: %s", mName.c_str());
+
+ if (mName == "walllayer")
+ {
+ for (int y = startY; y < endY; y++)
+ {
+ for (int x = startX; x < endX; x++)
+ {
+ TileInfo *tilePtr = &mTiles[CAST_SIZE(y * mWidth + x)];
+ if (tilePtr->isEnabled == true && y == 11)
+ {
+ logger->log("visible %d,%d", x, y);
+ }
+ }
+ }
+ }
+*/
for (int y = startY; y < endY; y++)
{
@@ -137,26 +155,49 @@ void MapLayer::draw(Graphics *const graphics,
int x0 = startX;
TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
+// if (mName == "walllayer")
+// logger->log("test %d,%d", x0, y);
if (tilePtr->isEnabled == false)
{
- if (tilePtr->count == 0 || x0 + tilePtr->count >= endX)
+// if (mName == "walllayer")
+// logger->log("hidden 1");
+ if (x0 + tilePtr->nextTile >= endX)
+ {
+// if (mName == "walllayer")
+// logger->log("skip 1");
continue;
- x0 += tilePtr->count + 1;
+ }
+// if (mName == "walllayer")
+// logger->log("hidden 2");
+ x0 += tilePtr->nextTile + 1;
tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
+// if (mName == "walllayer")
+// logger->log("hidden jump to %d,%d", x0, y);
if (mTiles[x0 + yWidth].isEnabled == false)
+ {
+// if (mName == "walllayer")
+// logger->log("skip 2");
continue;
+ }
+// if (mName == "walllayer")
+// logger->log("hidden 3");
}
+// if (mName == "walllayer")
+// logger->log("for x in %d to %d", x0, endX);
for (int x = x0; x < endX; x++, tilePtr++)
{
if (!tilePtr->isEnabled)
{
if (x + tilePtr->count + 1 >= endX)
break;
+ logger->log("error tiles: %s (%d,%d) to %d, +%d, %d", mName.c_str(), x, y, endX, tilePtr->count, tilePtr->nextTile);
const int c = tilePtr->count;
x += c;
tilePtr += c;
continue;
}
+// if (mName == "walllayer")
+// logger->log("ok tiles: %s (%d,%d) to %d, +%d, %d", mName.c_str(), x, y, endX, tilePtr->count, tilePtr->nextTile);
const int x32 = x * mapTileSize;
int c = 0;
@@ -172,6 +213,8 @@ void MapLayer::draw(Graphics *const graphics,
if (c == 0)
{
graphics->drawImage(img, px, py);
+// if (mName == "walllayer")
+// logger->log("draw image %d,%d", x, y);
}
else
{
@@ -180,11 +223,14 @@ void MapLayer::draw(Graphics *const graphics,
py,
tilePtr->width,
img->mBounds.h);
+// if (mName == "walllayer")
+// logger->log("draw pattern %d,%d, width=%d", x, y, tilePtr->width);
}
}
- x += c;
- tilePtr += c;
+ const int nextTile = tilePtr->nextTile;
+ x += nextTile;
+ tilePtr += nextTile;
}
}
BLOCK_END("MapLayer::draw")
@@ -557,14 +603,14 @@ void MapLayer::drawFringe(Graphics *const graphics,
drawSpecialLayer(graphics,
y,
0,
- std::min(x0 + tilePtr->count, endX),
+ std::min(x0 + tilePtr->nextTile, endX),
scrollX,
scrollY);
- if (x0 + tilePtr->count >= endX)
+ if (x0 + tilePtr->nextTile >= endX)
{
continue;
}
- x0 += tilePtr->count + 1;
+ x0 += tilePtr->nextTile + 1;
tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
if (mTiles[x0 + yWidth].isEnabled == false)
continue;
@@ -602,7 +648,7 @@ void MapLayer::drawFringe(Graphics *const graphics,
{
if (x + tilePtr->count + 1 >= endX)
break;
- logger->log("error tiles3: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
+ logger->log("error tiles1: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
c = tilePtr->count;
x += c;
tilePtr += c;
@@ -647,9 +693,9 @@ void MapLayer::drawFringe(Graphics *const graphics,
TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
if (tilePtr->isEnabled == false)
{
- if (x0 + tilePtr->count >= endX)
+ if (x0 + tilePtr->nextTile >= endX)
continue;
- x0 += tilePtr->count + 1;
+ x0 += tilePtr->nextTile + 1;
tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)];
if (mTiles[x0 + yWidth].isEnabled == false)
continue;
@@ -660,7 +706,7 @@ void MapLayer::drawFringe(Graphics *const graphics,
{
if (x + tilePtr->count + 1 >= endX)
break;
- logger->log("error tiles4: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
+ logger->log("error tiles2: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
const int c = tilePtr->count;
x += c;
tilePtr += c;
@@ -754,7 +800,8 @@ int MapLayer::getTileDrawWidth(const TileInfo *restrict tilePtr,
{
tilePtr ++;
const Image *const img = tilePtr->image;
- if (img == nullptr || !tilePtr->isEnabled)
+ if (img == nullptr ||
+ tilePtr->isEnabled == false)
{
break;
}
@@ -770,7 +817,8 @@ int MapLayer::getTileDrawWidth(const TileInfo *restrict tilePtr,
int c2 = c;
for (int x2 = c2 + 1; x2 < endX; x2++)
{
- if (tilePtr->image != nullptr)
+ if (tilePtr->image != nullptr &&
+ tilePtr->isEnabled == true)
{
break;
}
@@ -792,7 +840,7 @@ int MapLayer::getEmptyTileDrawWidth(const TileInfo *restrict tilePtr,
{
tilePtr ++;
const Image *const img = tilePtr->image;
- if (img != nullptr || !tilePtr->isEnabled)
+ if (img != nullptr && tilePtr->isEnabled == true)
break;
c ++;
}
@@ -810,16 +858,18 @@ void MapLayer::setDrawLayerFlags(const MapTypeT &n) restrict
mDrawLayerFlags != MapType::SPECIAL4);
}
-void MapLayer::updateConditionTiles(MetaTile *const metaTiles,
+void MapLayer::updateConditionTiles(const MetaTile *const metaTiles,
const int width,
const int height) restrict
{
const int width1 = width < mWidth ? width : mWidth;
const int height1 = height < mHeight ? height : mHeight;
+// if (mName == "walllayer")
+// logger->log("MapLayer::updateConditionTiles start: %s, %d", mName.c_str(), mTileCondition);
for (int y = mY; y < height1; y ++)
{
- MetaTile *metaPtr = metaTiles + (y - mY) * width;
+ const MetaTile *metaPtr = metaTiles + (y - mY) * width;
TileInfo *tilePtr = mTiles + y * mWidth;
for (int x = mX; x < width1; x ++, metaPtr ++, tilePtr ++)
{
@@ -829,13 +879,28 @@ void MapLayer::updateConditionTiles(MetaTile *const metaTiles,
mTileCondition == BlockMask::GROUND)))
{
tilePtr->isEnabled = true;
+// if (mName == "walllayer")
+// logger->log("update1: %d,%d (%p,%d) %d", x, y, (void*)tilePtr->image, metaPtr->blockmask, tilePtr->isEnabled ? 1 : 0);
}
else
{
tilePtr->isEnabled = false;
+// if (mName == "walllayer")
+// logger->log("update2: %d,%d (%p,%d) %d", x, y, (void*)tilePtr->image, metaPtr->blockmask, tilePtr->isEnabled ? 1 : 0);
+ }
+/*
+ if (mName == "walllayer")
+ {
+ if (x == 18 && y == 11)
+ {
+// logger->log("update: %d,%d (%p,%d) %d", x, y, (void*)tilePtr->image, metaPtr->blockmask, tilePtr->isEnabled ? 1 : 0);
+ }
}
+*/
}
}
+// if (mName == "walllayer")
+// logger->log("MapLayer::updateConditionTiles end: %s", mName.c_str());
}
void MapLayer::updateCache(const int width,
@@ -844,18 +909,23 @@ void MapLayer::updateCache(const int width,
const int width1 = width < mWidth ? width : mWidth;
const int height1 = height < mHeight ? height : mHeight;
+// if (mName == "walllayer")
+// logger->log("MapLayer::updateCache start: %s", mName.c_str());
for (int y = mY; y < height1; y ++)
{
- TileInfo *tilePtr = mTiles + y * mWidth;
- for (int x = mX; x < width1; x ++, tilePtr ++)
+ for (int x = mX; x < width1; x ++)
{
+ TileInfo *tilePtr = mTiles + y * mWidth + x;
int nextTile = 0;
- if (tilePtr->image == nullptr)
+ if (tilePtr->image == nullptr || tilePtr->isEnabled == false)
{
tilePtr->isEnabled = false;
tilePtr->count = getEmptyTileDrawWidth(tilePtr,
width1 - x,
nextTile);
+ tilePtr->width = 0;
+// if (mName == "walllayer")
+// logger->log("set1 count/next to %d,%d = %d and %d", x, y, tilePtr->count, nextTile);
}
else
{
@@ -865,10 +935,23 @@ void MapLayer::updateCache(const int width,
tileWidth,
nextTile);
tilePtr->width = tileWidth;
+// if (mName == "walllayer")
+// logger->log("set2 count/next to %d,%d = %d and %d", x, y, tilePtr->count, nextTile);
}
tilePtr->nextTile = nextTile;
+/*
+ if (mName == "walllayer")
+ {
+ if (x == 18 && y == 11)
+ {
+// logger->log("set count/next to %d,%d = %d and %d", x, y, tilePtr->count, tilePtr->nextTile);
+ }
+ }
+*/
}
}
+// if (mName == "walllayer")
+// logger->log("MapLayer::updateCache end: %s", mName.c_str());
}
int MapLayer::calcMemoryLocal() const
diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h
index b80be7445..19abac17c 100644
--- a/src/resources/map/maplayer.h
+++ b/src/resources/map/maplayer.h
@@ -170,6 +170,10 @@ class MapLayer final: public MemoryCounter, public ConfigListener
return mTiles;
}
+ void setTileCondition(const int c)
+ {
+ mTileCondition = c;
+ }
#endif // UNITTESTS
#ifndef UNITTESTS
@@ -185,7 +189,7 @@ class MapLayer final: public MemoryCounter, public ConfigListener
int &restrict nextTile)
A_WARN_UNUSED A_NONNULL(1);
- void updateConditionTiles(MetaTile *restrict const metaTiles,
+ void updateConditionTiles(const MetaTile *restrict const metaTiles,
const int width,
const int height) restrict A_NONNULL(2);
diff --git a/src/resources/map/maplayer_unittest.cc b/src/resources/map/maplayer_unittest.cc
index 90f34ce0e..d78610024 100644
--- a/src/resources/map/maplayer_unittest.cc
+++ b/src/resources/map/maplayer_unittest.cc
@@ -22,8 +22,11 @@
#include "logger.h"
+#include "enums/resources/map/blockmask.h"
+
#include "resources/image/image.h"
+#include "resources/map/map.h"
#include "resources/map/maplayer.h"
#include "debug.h"
@@ -39,7 +42,7 @@ TEST_CASE("MapLayer getTileDrawWidth")
SECTION("simple 1")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
1, 1,
false,
@@ -57,7 +60,7 @@ TEST_CASE("MapLayer getTileDrawWidth")
SECTION("simple 2")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
2, 1,
false,
@@ -75,7 +78,7 @@ TEST_CASE("MapLayer getTileDrawWidth")
SECTION("simple 3")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
2, 1,
false,
@@ -101,7 +104,7 @@ TEST_CASE("MapLayer getTileDrawWidth")
SECTION("simple 4")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
2, 1,
false,
@@ -125,9 +128,9 @@ TEST_CASE("MapLayer getTileDrawWidth")
REQUIRE(nextTile == 0);
}
- SECTION("simple 4")
+ SECTION("simple 4.2")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
3, 1,
false,
@@ -153,7 +156,7 @@ TEST_CASE("MapLayer getTileDrawWidth")
SECTION("simple 5")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
3, 1,
false,
@@ -179,7 +182,7 @@ TEST_CASE("MapLayer getTileDrawWidth")
SECTION("simple 6")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
3, 1,
false,
@@ -211,9 +214,79 @@ TEST_CASE("MapLayer getTileDrawWidth")
REQUIRE(nextTile == 0);
}
+ SECTION("simple 7")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ layer->setTile(2, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ tiles[1].isEnabled = false;
+ REQUIRE(layer->getTileDrawWidth(tiles,
+ 3,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 1);
+
+// REQUIRE(layer->getTileDrawWidth(tiles + 1,
+// 2,
+// width,
+// nextTile) == 0);
+// REQUIRE(width == 32);
+// REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 2,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
+ SECTION("simple 8")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ layer->setTile(2, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ tiles[0].isEnabled = false;
+// REQUIRE(layer->getTileDrawWidth(tiles,
+// 3,
+// width,
+// nextTile) == 1);
+// REQUIRE(width == 0);
+// REQUIRE(nextTile == 1);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 1,
+ 2,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+
+ REQUIRE(layer->getTileDrawWidth(tiles + 2,
+ 1,
+ width,
+ nextTile) == 0);
+ REQUIRE(width == 32);
+ REQUIRE(nextTile == 0);
+ }
+
SECTION("normal 1")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
100, 100,
false,
@@ -333,7 +406,7 @@ TEST_CASE("MapLayer getEmptyTileDrawWidth")
SECTION("simple 2")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
2, 1,
false,
@@ -349,7 +422,7 @@ TEST_CASE("MapLayer getEmptyTileDrawWidth")
SECTION("simple 4")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
3, 1,
false,
@@ -366,7 +439,7 @@ TEST_CASE("MapLayer getEmptyTileDrawWidth")
SECTION("simple 5")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
3, 1,
false,
@@ -383,7 +456,7 @@ TEST_CASE("MapLayer getEmptyTileDrawWidth")
SECTION("normal 1")
{
- MapLayer *layer = new MapLayer("test",
+ layer = new MapLayer("test",
0, 0,
100, 100,
false,
@@ -449,3 +522,565 @@ TEST_CASE("MapLayer getEmptyTileDrawWidth")
delete img2;
delete img3;
}
+
+
+TEST_CASE("MapLayer updateCache")
+{
+ Image *const img1 = new Image(32, 32);
+ Image *const img2 = new Image(32, 32);
+ Image *const img3 = new Image(32, 32);
+ MapLayer *layer = nullptr;
+ int width;
+ int nextTile;
+
+ SECTION("simple 1")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 1, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(1, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ REQUIRE(tiles[0].width == 32);
+ REQUIRE(tiles[0].count == 0);
+ REQUIRE(tiles[0].nextTile == 0);
+ }
+
+ SECTION("simple 2")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 2, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(2, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ REQUIRE(tiles[0].width == 32);
+ REQUIRE(tiles[0].count == 0);
+ REQUIRE(tiles[0].nextTile == 1);
+ REQUIRE(tiles[1].isEnabled == false);
+ REQUIRE(tiles[1].width == 0);
+ REQUIRE(tiles[1].count == 0);
+ REQUIRE(tiles[1].nextTile == 0);
+ }
+
+ SECTION("simple 3")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 2, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(2, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ REQUIRE(tiles[0].width == 32);
+ REQUIRE(tiles[0].count == 0);
+ REQUIRE(tiles[0].nextTile == 0);
+ REQUIRE(tiles[1].isEnabled == true);
+ REQUIRE(tiles[1].width == 32);
+ REQUIRE(tiles[1].count == 0);
+ REQUIRE(tiles[1].nextTile == 0);
+ }
+
+ SECTION("simple 4")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 2, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(2, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ REQUIRE(tiles[0].width == 64);
+ REQUIRE(tiles[0].count == 1);
+ REQUIRE(tiles[0].nextTile == 1);
+ REQUIRE(tiles[1].isEnabled == true);
+ REQUIRE(tiles[1].width == 32);
+ REQUIRE(tiles[1].count == 0);
+ REQUIRE(tiles[1].nextTile == 0);
+ }
+
+ SECTION("simple 4.2")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(2, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(3, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ REQUIRE(tiles[0].width == 32);
+ REQUIRE(tiles[0].count == 0);
+ REQUIRE(tiles[0].nextTile == 1);
+ REQUIRE(tiles[1].isEnabled == false);
+ REQUIRE(tiles[1].width == 0);
+ REQUIRE(tiles[1].count == 0);
+ REQUIRE(tiles[1].nextTile == 0);
+ REQUIRE(tiles[2].isEnabled == true);
+ REQUIRE(tiles[2].width == 32);
+ REQUIRE(tiles[2].count == 0);
+ REQUIRE(tiles[2].nextTile == 0);
+ }
+
+ SECTION("simple 5")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(3, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ REQUIRE(tiles[0].width == 64);
+ REQUIRE(tiles[0].count == 1);
+ REQUIRE(tiles[0].nextTile == 2);
+ REQUIRE(tiles[1].isEnabled == true);
+ REQUIRE(tiles[1].width == 32);
+ REQUIRE(tiles[1].count == 0);
+ REQUIRE(tiles[1].nextTile == 1);
+ REQUIRE(tiles[2].isEnabled == false);
+ REQUIRE(tiles[2].width == 0);
+ REQUIRE(tiles[2].count == 0);
+ REQUIRE(tiles[2].nextTile == 0);
+ }
+
+ SECTION("simple 6")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ layer->setTile(2, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(3, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ REQUIRE(tiles[0].width == 64);
+ REQUIRE(tiles[0].count == 1);
+ REQUIRE(tiles[0].nextTile == 1);
+ REQUIRE(tiles[1].isEnabled == true);
+ REQUIRE(tiles[1].width == 32);
+ REQUIRE(tiles[1].count == 0);
+ REQUIRE(tiles[1].nextTile == 0);
+ REQUIRE(tiles[2].isEnabled == true);
+ REQUIRE(tiles[2].width == 32);
+ REQUIRE(tiles[2].count == 0);
+ REQUIRE(tiles[2].nextTile == 0);
+ }
+
+ SECTION("simple 7")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 3, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ layer->setTile(1, 0, img1);
+ layer->setTile(2, 0, img2);
+ TileInfo *const tiles = layer->getTiles();
+ tiles[0].isEnabled = false;
+ layer->updateCache(3, 1);
+ REQUIRE(tiles[0].isEnabled == false);
+ REQUIRE(tiles[0].width == 0);
+ REQUIRE(tiles[0].count == 0);
+ REQUIRE(tiles[0].nextTile == 0);
+ REQUIRE(tiles[1].isEnabled == true);
+ REQUIRE(tiles[1].width == 32);
+ REQUIRE(tiles[1].count == 0);
+ REQUIRE(tiles[1].nextTile == 0);
+ REQUIRE(tiles[2].isEnabled == true);
+ REQUIRE(tiles[2].width == 32);
+ REQUIRE(tiles[2].count == 0);
+ REQUIRE(tiles[2].nextTile == 0);
+ }
+
+ SECTION("normal 1")
+ {
+ layer = new MapLayer("test",
+ 0, 0,
+ 100, 100,
+ false,
+ 0,
+ 0);
+ layer->setTile(1, 10, img1);
+ layer->setTile(2, 10, img1);
+ layer->setTile(3, 10, img1);
+ layer->setTile(4, 10, img2);
+ layer->setTile(5, 10, nullptr);
+ layer->setTile(6, 10, img2);
+ layer->setTile(7, 10, nullptr);
+ layer->setTile(8, 10, nullptr);
+ layer->setTile(9, 10, img2);
+ layer->setTile(10, 10, img2);
+ layer->setTile(11, 10, img3);
+ layer->setTile(12, 10, nullptr);
+ layer->setTile(13, 10, nullptr);
+ layer->setTile(14, 10, nullptr);
+ layer->setTile(15, 10, img1);
+ layer->setTile(16, 10, img1);
+ layer->setTile(17, 10, img1);
+ TileInfo *const tiles = layer->getTiles();
+ layer->updateCache(100, 100);
+
+ REQUIRE(tiles[0 * 100 + 0].isEnabled == false);
+ REQUIRE(tiles[0 * 100 + 0].width == 0);
+ REQUIRE(tiles[0 * 100 + 0].count == 99);
+ REQUIRE(tiles[0 * 100 + 0].nextTile == 99);
+
+ REQUIRE(tiles[0 * 100 + 1].isEnabled == false);
+ REQUIRE(tiles[0 * 100 + 1].width == 0);
+ REQUIRE(tiles[0 * 100 + 1].count == 98);
+ REQUIRE(tiles[0 * 100 + 1].nextTile == 98);
+
+ REQUIRE(tiles[10 * 100 + 0].isEnabled == false);
+ REQUIRE(tiles[10 * 100 + 0].width == 0);
+ REQUIRE(tiles[10 * 100 + 0].count == 0);
+ REQUIRE(tiles[10 * 100 + 0].nextTile == 0);
+
+ REQUIRE(tiles[10 * 100 + 1].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 1].width == 96);
+ REQUIRE(tiles[10 * 100 + 1].count == 2);
+ REQUIRE(tiles[10 * 100 + 1].nextTile == 2);
+
+ REQUIRE(tiles[10 * 100 + 2].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 2].width == 64);
+ REQUIRE(tiles[10 * 100 + 2].count == 1);
+ REQUIRE(tiles[10 * 100 + 2].nextTile == 1);
+
+ REQUIRE(tiles[10 * 100 + 3].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 3].width == 32);
+ REQUIRE(tiles[10 * 100 + 3].count == 0);
+ REQUIRE(tiles[10 * 100 + 3].nextTile == 0);
+
+ REQUIRE(tiles[10 * 100 + 4].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 4].width == 32);
+ REQUIRE(tiles[10 * 100 + 4].count == 0);
+ REQUIRE(tiles[10 * 100 + 4].nextTile == 1);
+
+ REQUIRE(tiles[10 * 100 + 5].isEnabled == false);
+ REQUIRE(tiles[10 * 100 + 5].width == 0);
+ REQUIRE(tiles[10 * 100 + 5].count == 0);
+ REQUIRE(tiles[10 * 100 + 5].nextTile == 0);
+
+ REQUIRE(tiles[10 * 100 + 6].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 6].width == 32);
+ REQUIRE(tiles[10 * 100 + 6].count == 0);
+ REQUIRE(tiles[10 * 100 + 6].nextTile == 2);
+
+ REQUIRE(tiles[10 * 100 + 7].isEnabled == false);
+ REQUIRE(tiles[10 * 100 + 7].width == 0);
+ REQUIRE(tiles[10 * 100 + 7].count == 1);
+ REQUIRE(tiles[10 * 100 + 7].nextTile == 1);
+
+ REQUIRE(tiles[10 * 100 + 8].isEnabled == false);
+ REQUIRE(tiles[10 * 100 + 8].width == 0);
+ REQUIRE(tiles[10 * 100 + 8].count == 0);
+ REQUIRE(tiles[10 * 100 + 8].nextTile == 0);
+
+ REQUIRE(tiles[10 * 100 + 9].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 9].width == 64);
+ REQUIRE(tiles[10 * 100 + 9].count == 1);
+ REQUIRE(tiles[10 * 100 + 9].nextTile == 1);
+
+ REQUIRE(tiles[10 * 100 + 10].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 10].width == 32);
+ REQUIRE(tiles[10 * 100 + 10].count == 0);
+ REQUIRE(tiles[10 * 100 + 10].nextTile == 0);
+
+ REQUIRE(tiles[10 * 100 + 11].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 11].width == 32);
+ REQUIRE(tiles[10 * 100 + 11].count == 0);
+ REQUIRE(tiles[10 * 100 + 11].nextTile == 3);
+
+ REQUIRE(tiles[10 * 100 + 12].isEnabled == false);
+ REQUIRE(tiles[10 * 100 + 12].width == 0);
+ REQUIRE(tiles[10 * 100 + 12].count == 2);
+ REQUIRE(tiles[10 * 100 + 12].nextTile == 2);
+
+ REQUIRE(tiles[10 * 100 + 13].isEnabled == false);
+ REQUIRE(tiles[10 * 100 + 13].width == 0);
+ REQUIRE(tiles[10 * 100 + 13].count == 1);
+ REQUIRE(tiles[10 * 100 + 13].nextTile == 1);
+
+ REQUIRE(tiles[10 * 100 + 14].isEnabled == false);
+ REQUIRE(tiles[10 * 100 + 14].width == 0);
+ REQUIRE(tiles[10 * 100 + 14].count == 0);
+ REQUIRE(tiles[10 * 100 + 14].nextTile == 0);
+
+ REQUIRE(tiles[10 * 100 + 15].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 15].width == 96);
+ REQUIRE(tiles[10 * 100 + 15].count == 2);
+ REQUIRE(tiles[10 * 100 + 15].nextTile == 84);
+
+ REQUIRE(tiles[10 * 100 + 16].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 16].width == 64);
+ REQUIRE(tiles[10 * 100 + 16].count == 1);
+ REQUIRE(tiles[10 * 100 + 16].nextTile == 83);
+
+ REQUIRE(tiles[10 * 100 + 17].isEnabled == true);
+ REQUIRE(tiles[10 * 100 + 17].width == 32);
+ REQUIRE(tiles[10 * 100 + 17].count == 0);
+ REQUIRE(tiles[10 * 100 + 17].nextTile == 82);
+ }
+
+ SECTION("normal2")
+ {
+ const int maxX = 100;
+ const int maxY = 100;
+ layer = new MapLayer("test",
+ 0, 0,
+ maxX, maxY,
+ false,
+ 0,
+ 0);
+ TileInfo *const tiles = layer->getTiles();
+ for (int x = 0; x < maxX; x ++)
+ {
+ for (int y = 0; y < maxY; y ++)
+ {
+ layer->setTile(x, y, img1);
+ tiles[y * maxX + x].isEnabled = false;
+ }
+ }
+ tiles[10 * maxX + 41].isEnabled = true;
+ layer->updateCache(maxX, maxY);
+
+ REQUIRE(tiles[10 * maxX + 0].isEnabled == false);
+ REQUIRE(tiles[10 * maxX + 0].width == 0);
+ REQUIRE(tiles[10 * maxX + 0].count == 40);
+ REQUIRE(tiles[10 * maxX + 0].nextTile == 40);
+
+ REQUIRE(tiles[10 * maxX + 1].isEnabled == false);
+ REQUIRE(tiles[10 * maxX + 1].width == 0);
+ REQUIRE(tiles[10 * maxX + 1].count == 39);
+ REQUIRE(tiles[10 * maxX + 1].nextTile == 39);
+ }
+
+ delete layer;
+ delete img1;
+ delete img2;
+ delete img3;
+}
+
+TEST_CASE("MapLayer updateConditionTiles")
+{
+ Image *const img1 = new Image(32, 32);
+ Map *map = nullptr;
+ MapLayer *layer = nullptr;
+ int width;
+ int nextTile;
+
+ SECTION("simple 1")
+ {
+ map = new Map("map",
+ 1, 1,
+ 32, 32);
+ layer = new MapLayer("test",
+ 0, 0,
+ 1, 1,
+ false,
+ 0,
+ 0);
+ layer->setTile(0, 0, img1);
+ map->addLayer(layer);
+ layer->setTileCondition(BlockMask::WATER);
+ TileInfo *const tiles = layer->getTiles();
+
+ map->addBlockMask(0, 0, BlockType::NONE);
+ layer->updateConditionTiles(map->getMetaTiles(),
+ 1, 1);
+ REQUIRE(tiles[0].isEnabled == false);
+
+ map->addBlockMask(0, 0, BlockType::WATER);
+ layer->updateConditionTiles(map->getMetaTiles(),
+ 1, 1);
+ REQUIRE(tiles[0].isEnabled == true);
+ }
+
+ SECTION("normal 1")
+ {
+ map = new Map("map",
+ 100, 200,
+ 32, 32);
+ layer = new MapLayer("test",
+ 0, 0,
+ 100, 200,
+ false,
+ 0,
+ 0);
+ layer->setTile(10, 10, img1);
+ layer->setTile(10, 20, img1);
+ layer->setTile(10, 30, img1);
+ map->addLayer(layer);
+ layer->setTileCondition(BlockMask::WATER);
+ TileInfo *const tiles = layer->getTiles();
+
+ map->addBlockMask(10, 10, BlockType::NONE);
+ map->addBlockMask(10, 20, BlockType::NONE);
+ map->addBlockMask(20, 20, BlockType::NONE);
+ layer->updateConditionTiles(map->getMetaTiles(),
+ 100, 200);
+ for (int x = 0; x < 100; x ++)
+ {
+ for (int y = 0; y < 200; y ++)
+ {
+ REQUIRE(tiles[y * 100 + x].isEnabled == false);
+ }
+ }
+ }
+
+ SECTION("normal 2")
+ {
+ map = new Map("map",
+ 100, 200,
+ 32, 32);
+ layer = new MapLayer("test",
+ 0, 0,
+ 100, 200,
+ false,
+ 0,
+ 0);
+ layer->setTile(10, 10, img1);
+ layer->setTile(10, 20, img1);
+ layer->setTile(10, 30, img1);
+ map->addLayer(layer);
+ layer->setTileCondition(BlockMask::WATER);
+ TileInfo *const tiles = layer->getTiles();
+
+ map->addBlockMask(10, 10, BlockType::WATER);
+ map->addBlockMask(10, 20, BlockType::WATER);
+ map->addBlockMask(20, 20, BlockType::WATER);
+ layer->updateConditionTiles(map->getMetaTiles(),
+ 100, 200);
+ for (int x = 0; x < 100; x ++)
+ {
+ for (int y = 0; y < 200; y ++)
+ {
+ if ((x == 10 && y == 10) || (x == 10 && y == 20))
+ {
+ REQUIRE(tiles[y * 100 + x].isEnabled == true);
+ }
+ else
+ {
+ REQUIRE(tiles[y * 100 + x].isEnabled == false);
+ }
+ }
+ }
+ }
+
+ SECTION("normal 3")
+ {
+ map = new Map("map",
+ 100, 200,
+ 32, 32);
+ layer = new MapLayer("test",
+ 0, 0,
+ 100, 200,
+ false,
+ 0,
+ 0);
+ for (int x = 0; x < 100; x ++)
+ {
+ for (int y = 0; y < 200; y ++)
+ {
+ layer->setTile(x, y, img1);
+ }
+ }
+ map->addLayer(layer);
+ layer->setTileCondition(BlockMask::WATER);
+ TileInfo *const tiles = layer->getTiles();
+
+ map->addBlockMask(10, 10, BlockType::WATER);
+ map->addBlockMask(10, 20, BlockType::WATER);
+ layer->updateConditionTiles(map->getMetaTiles(),
+ 100, 200);
+ for (int x = 0; x < 100; x ++)
+ {
+ for (int y = 0; y < 200; y ++)
+ {
+ if ((x == 10 && y == 10) || (x == 10 && y == 20))
+ {
+ REQUIRE(tiles[y * 100 + x].isEnabled == true);
+ }
+ else
+ {
+ REQUIRE(tiles[y * 100 + x].isEnabled == false);
+ }
+ }
+ }
+ }
+
+ SECTION("normal 4")
+ {
+ map = new Map("map",
+ 100, 200,
+ 32, 32);
+ layer = new MapLayer("test",
+ 0, 0,
+ 100, 200,
+ false,
+ 0,
+ 0);
+ layer->setTile(10, 10, img1);
+ layer->setTile(10, 20, img1);
+ map->addLayer(layer);
+ layer->setTileCondition(BlockMask::WATER);
+ TileInfo *const tiles = layer->getTiles();
+
+ for (int x = 0; x < 100; x ++)
+ {
+ for (int y = 0; y < 200; y ++)
+ {
+ map->addBlockMask(x, y, BlockType::WATER);
+ }
+ }
+
+ layer->updateConditionTiles(map->getMetaTiles(),
+ 100, 200);
+ for (int x = 0; x < 100; x ++)
+ {
+ for (int y = 0; y < 200; y ++)
+ {
+ if ((x == 10 && y == 10) || (x == 10 && y == 20))
+ {
+ REQUIRE(tiles[y * 100 + x].isEnabled == true);
+ }
+ else
+ {
+ REQUIRE(tiles[y * 100 + x].isEnabled == false);
+ }
+ }
+ }
+ }
+
+ delete map;
+ delete img1;
+}