summaryrefslogtreecommitdiff
path: root/src/resources/map/maplayer.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-12-31 05:04:16 +0300
committerAndrei Karas <akaras@inbox.ru>2016-12-31 17:30:48 +0300
commit537085e221d25f710ed7162e1fc8add8ffe4a72f (patch)
treed1abf9cdb898005099eb741a1f6ed79417b331fb /src/resources/map/maplayer.cpp
parent496e74aa95984380e4a36fe8d55d0839002d6f8f (diff)
downloadmv-537085e221d25f710ed7162e1fc8add8ffe4a72f.tar.gz
mv-537085e221d25f710ed7162e1fc8add8ffe4a72f.tar.bz2
mv-537085e221d25f710ed7162e1fc8add8ffe4a72f.tar.xz
mv-537085e221d25f710ed7162e1fc8add8ffe4a72f.zip
Improve fringe map layers drawing.
Pre cache next tile position with image.
Diffstat (limited to 'src/resources/map/maplayer.cpp')
-rw-r--r--src/resources/map/maplayer.cpp55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp
index b795db243..ad9fc69e6 100644
--- a/src/resources/map/maplayer.cpp
+++ b/src/resources/map/maplayer.cpp
@@ -562,7 +562,7 @@ void MapLayer::drawFringe(Graphics *const graphics,
img->mBounds.h);
}
}
-// logger->log("ok tiles3: (%d,%d) to %d, +%d", x, y, endX, tilePtr->count);
+// logger->log("ok tiles3: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
}
else
{
@@ -570,7 +570,7 @@ void MapLayer::drawFringe(Graphics *const graphics,
// 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);
+// logger->log("error tiles3: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
c = tilePtr->count;
x += c;
tilePtr += c;
@@ -612,8 +612,9 @@ void MapLayer::drawFringe(Graphics *const graphics,
}
}
}
- x += c;
- tilePtr += c;
+ const int nextTile = tilePtr->nextTile;
+ x += nextTile;
+ tilePtr += nextTile;
}
}
@@ -652,13 +653,13 @@ void MapLayer::drawFringe(Graphics *const graphics,
{
if (x + tilePtr->count + 1 >= endX)
break;
-// logger->log("error tiles4: (%d,%d) to %d, +%d", x, y, endX, tilePtr->count);
+// logger->log("error tiles4: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
const int c = tilePtr->count;
x += c;
tilePtr += c;
continue;
}
-// logger->log("ok tiles4: (%d,%d) to %d, +%d", x, y, endX, tilePtr->count);
+// logger->log("ok tiles4: (%d,%d) to %d, +%d, %d", x, y, endX, tilePtr->count, tilePtr->nextTile);
const int x32 = x * mapTileSize;
const Image *const img = tilePtr->image;
const int px = x32 + dx;
@@ -679,10 +680,11 @@ void MapLayer::drawFringe(Graphics *const graphics,
py,
tilePtr->width,
img->mBounds.h);
- x += c;
- tilePtr += c;
}
}
+ const int nextTile = tilePtr->nextTile;
+ x += nextTile;
+ tilePtr += nextTile;
}
}
} // !flag
@@ -734,7 +736,8 @@ void MapLayer::drawFringe(Graphics *const graphics,
int MapLayer::getTileDrawWidth(const TileInfo *restrict tilePtr,
const int endX,
- int &width)
+ int &restrict width,
+ int &restrict nextTile)
{
BLOCK_START("MapLayer::getTileDrawWidth")
const Image *const img1 = tilePtr->image;
@@ -744,17 +747,37 @@ int MapLayer::getTileDrawWidth(const TileInfo *restrict tilePtr,
{
tilePtr ++;
const Image *const img = tilePtr->image;
- if (img != img1 || !tilePtr->isEnabled)
+ if (img == nullptr || !tilePtr->isEnabled)
+ {
break;
+ }
+ if (img != img1)
+ {
+ nextTile = c;
+ BLOCK_END("MapLayer::getTileDrawWidth")
+ return c;
+ }
c ++;
width += img->mBounds.w;
}
+ int c2 = c;
+ for (int x2 = c2 + 1; x2 < endX; x2++)
+ {
+ if (tilePtr->image != nullptr)
+ {
+ break;
+ }
+ c2 ++;
+ tilePtr ++;
+ }
+ nextTile = c2;
BLOCK_END("MapLayer::getTileDrawWidth")
return c;
}
int MapLayer::getEmptyTileDrawWidth(const TileInfo *restrict tilePtr,
- const int endX)
+ const int endX,
+ int &restrict nextTile)
{
BLOCK_START("MapLayer::getEmptyTileDrawWidth")
int c = 0;
@@ -767,6 +790,8 @@ int MapLayer::getEmptyTileDrawWidth(const TileInfo *restrict tilePtr,
c ++;
}
BLOCK_END("MapLayer::getEmptyTileDrawWidth")
+
+ nextTile = c;
return c;
}
@@ -817,20 +842,24 @@ void MapLayer::updateCache(const int width,
TileInfo *tilePtr = mTiles + y * mWidth;
for (int x = mX; x < width1; x ++, tilePtr ++)
{
+ int nextTile = 0;
if (tilePtr->image == nullptr)
{
tilePtr->isEnabled = false;
tilePtr->count = getEmptyTileDrawWidth(tilePtr,
- width1 - x);
+ width1 - x,
+ nextTile);
}
else
{
int tileWidth = 0;
tilePtr->count = getTileDrawWidth(tilePtr,
width1 - x,
- tileWidth);
+ tileWidth,
+ nextTile);
tilePtr->width = tileWidth;
}
+ tilePtr->nextTile = nextTile;
}
}
}