diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-12-30 22:07:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-12-30 22:07:25 +0300 |
commit | 496e74aa95984380e4a36fe8d55d0839002d6f8f (patch) | |
tree | ca11d46b7d553ea175ee76d15081f5a731b6c269 /src | |
parent | 728223b59f09d1460a092b5fd467c3191fcb46c9 (diff) | |
download | mv-496e74aa95984380e4a36fe8d55d0839002d6f8f.tar.gz mv-496e74aa95984380e4a36fe8d55d0839002d6f8f.tar.bz2 mv-496e74aa95984380e4a36fe8d55d0839002d6f8f.tar.xz mv-496e74aa95984380e4a36fe8d55d0839002d6f8f.zip |
Improve map layers drawing.
Skip same image or empty tiles.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/map/maplayer.cpp | 105 | ||||
-rw-r--r-- | src/resources/map/maplayer.h | 4 |
2 files changed, 95 insertions, 14 deletions
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp index 58d8a3a08..b795db243 100644 --- a/src/resources/map/maplayer.cpp +++ b/src/resources/map/maplayer.cpp @@ -135,12 +135,28 @@ void MapLayer::draw(Graphics *const graphics, const int py0 = y32 + dy; - TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)]; - - for (int x = startX; x < endX; x++, tilePtr++) + int x0 = startX; + TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)]; + if (tilePtr->isEnabled == false) + { + if (tilePtr->count == 0 || x0 + tilePtr->count >= endX) + continue; + x0 += tilePtr->count + 1; + tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)]; + if (mTiles[x0 + yWidth].isEnabled == false) + continue; + } + for (int x = x0; x < endX; x++, tilePtr++) { if (!tilePtr->isEnabled) + { + if (x + tilePtr->count + 1 >= endX) + break; + const int c = tilePtr->count; + x += c; + tilePtr += c; continue; + } const int x32 = x * mapTileSize; int c = 0; @@ -434,6 +450,7 @@ void MapLayer::drawFringe(Graphics *const graphics, } BLOCK_END("MapLayer::drawFringe drawmobs") + // remove this condition, because it always true if (y < specialHeight) { const int ptr = y * specialWidth; @@ -502,8 +519,23 @@ void MapLayer::drawFringe(Graphics *const graphics, const int py0 = y32 + dy; const int py1 = y32 - scrollY; - TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)]; - for (int x = startX; x < endX; x++, tilePtr++) + int x0 = startX; + TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)]; + if (tilePtr->isEnabled == false) + { + // here need draw special layers only and continue + // for now special layer can be not drawed, if skipped before for + //if (tilePtr->count == 0 || x0 + tilePtr->count >= endX) + if (x0 + tilePtr->count >= endX) + { + continue; + } + x0 += tilePtr->count + 1; + tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)]; + if (mTiles[x0 + yWidth].isEnabled == false) + continue; + } + for (int x = x0; x < endX; x++, tilePtr++) { const int x32 = x * mapTileSize; int c = 0; @@ -515,7 +547,6 @@ void MapLayer::drawFringe(Graphics *const graphics, { const int px = x32 + dx; const int py = py0 - img->mBounds.h; - // here need not draw over player position c = tilePtr->count; if (c == 0) @@ -531,8 +562,22 @@ void MapLayer::drawFringe(Graphics *const graphics, img->mBounds.h); } } +// logger->log("ok tiles3: (%d,%d) to %d, +%d", x, y, endX, tilePtr->count); + } + else + { + // here need draw special layers only and continue + // for now special layer can be not drawed + if (x + tilePtr->count + 1 >= endX) + break; +// logger->log("error tiles3: (%d,%d) to %d, +%d", x, y, endX, tilePtr->count); + c = tilePtr->count; + x += c; + tilePtr += c; + continue; } + // remove this condition, because it always true if (y < specialHeight) { int c1 = c; @@ -590,11 +635,30 @@ void MapLayer::drawFringe(Graphics *const graphics, const int py0 = y32 + dy; - TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)]; - for (int x = startX; x < endX; x++, tilePtr++) + int x0 = startX; + TileInfo *tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)]; + if (tilePtr->isEnabled == false) + { + if (x0 + tilePtr->count >= endX) + continue; + x0 += tilePtr->count + 1; + tilePtr = &mTiles[CAST_SIZE(x0 + yWidth)]; + if (mTiles[x0 + yWidth].isEnabled == false) + continue; + } + for (int x = x0; x < endX; x++, tilePtr++) { if (!tilePtr->isEnabled) + { + if (x + tilePtr->count + 1 >= endX) + break; +// logger->log("error tiles4: (%d,%d) to %d, +%d", x, y, endX, tilePtr->count); + const int c = tilePtr->count; + x += c; + tilePtr += c; continue; + } +// logger->log("ok tiles4: (%d,%d) to %d, +%d", x, y, endX, tilePtr->count); const int x32 = x * mapTileSize; const Image *const img = tilePtr->image; const int px = x32 + dx; @@ -675,12 +739,6 @@ int MapLayer::getTileDrawWidth(const TileInfo *restrict tilePtr, BLOCK_START("MapLayer::getTileDrawWidth") const Image *const img1 = tilePtr->image; int c = 0; - if (!img1) - { - width = 0; - BLOCK_END("MapLayer::getTileDrawWidth") - return c; - } width = img1->mBounds.w; for (int x = 1; x < endX; x++) { @@ -695,6 +753,23 @@ int MapLayer::getTileDrawWidth(const TileInfo *restrict tilePtr, return c; } +int MapLayer::getEmptyTileDrawWidth(const TileInfo *restrict tilePtr, + const int endX) +{ + BLOCK_START("MapLayer::getEmptyTileDrawWidth") + int c = 0; + for (int x = 1; x < endX; x++) + { + tilePtr ++; + const Image *const img = tilePtr->image; + if (img != nullptr || !tilePtr->isEnabled) + break; + c ++; + } + BLOCK_END("MapLayer::getEmptyTileDrawWidth") + return c; +} + void MapLayer::setDrawLayerFlags(const MapTypeT &n) restrict { mDrawLayerFlags = n; @@ -745,6 +820,8 @@ void MapLayer::updateCache(const int width, if (tilePtr->image == nullptr) { tilePtr->isEnabled = false; + tilePtr->count = getEmptyTileDrawWidth(tilePtr, + width1 - x); } else { diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h index 2ddbb6aca..19f213ecc 100644 --- a/src/resources/map/maplayer.h +++ b/src/resources/map/maplayer.h @@ -169,6 +169,10 @@ class MapLayer final: public MemoryCounter, public ConfigListener const int endX, int &width) A_WARN_UNUSED A_NONNULL(1); + static int getEmptyTileDrawWidth(const TileInfo *restrict img, + const int endX) + A_WARN_UNUSED A_NONNULL(1); + void updateConditionTiles(MetaTile *restrict const metaTiles, const int width, const int height) restrict A_NONNULL(2); |