diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-12-29 21:09:41 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-12-29 22:01:14 +0300 |
commit | 0c06037af71273481958ba8587bbb4082d1ed822 (patch) | |
tree | d20ac88eb7654dab57975d6f02f22ad0d9314872 /src/resources/map/maplayer.cpp | |
parent | e8b2a5596f569e72e0e7482e8f41aaf7e710d8ec (diff) | |
download | plus-0c06037af71273481958ba8587bbb4082d1ed822.tar.gz plus-0c06037af71273481958ba8587bbb4082d1ed822.tar.bz2 plus-0c06037af71273481958ba8587bbb4082d1ed822.tar.xz plus-0c06037af71273481958ba8587bbb4082d1ed822.zip |
Improve drawing tiles.
Remove check for existing tile image in each tile.
From now tiles without image hidden.
Diffstat (limited to 'src/resources/map/maplayer.cpp')
-rw-r--r-- | src/resources/map/maplayer.cpp | 182 |
1 files changed, 92 insertions, 90 deletions
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp index 57a32ea8f..84ee5d63b 100644 --- a/src/resources/map/maplayer.cpp +++ b/src/resources/map/maplayer.cpp @@ -145,26 +145,23 @@ void MapLayer::draw(Graphics *const graphics, int c = 0; const Image *const img = tilePtr->image; - if (img) + const int px = x32 + dx; + const int py = py0 - img->mBounds.h; + if (mSpecialFlag || + img->mBounds.h <= mapTileSize) { - const int px = x32 + dx; - const int py = py0 - img->mBounds.h; - if (mSpecialFlag || - img->mBounds.h <= mapTileSize) - { - int width = 0; - // here need not draw over player position - c = getTileDrawWidth(tilePtr, endX - x, width); + int width = 0; + // here need not draw over player position + c = getTileDrawWidth(tilePtr, endX - x, width); - if (!c) - { - graphics->drawImage(img, px, py); - } - else - { - graphics->drawPattern(img, px, py, - width, img->mBounds.h); - } + if (!c) + { + graphics->drawImage(img, px, py); + } + else + { + graphics->drawPattern(img, px, py, + width, img->mBounds.h); } } @@ -242,22 +239,19 @@ void MapLayer::updateSDL(const Graphics *const graphics, if (!tilePtr->isEnabled) continue; Image *const img = (*tilePtr).image; - if (img) + const int px = x * mapTileSize + dx; + const int py = py0 - img->mBounds.h; + if (mSpecialFlag || + img->mBounds.h <= mapTileSize) { - const int px = x * mapTileSize + dx; - const int py = py0 - img->mBounds.h; - if (mSpecialFlag || - img->mBounds.h <= mapTileSize) + if (lastImage != img) { - if (lastImage != img) - { - imgVert = new ImageVertexes(); - imgVert->image = img; - row->images.push_back(imgVert); - lastImage = img; - } - graphics->calcTileSDL(imgVert, px, py); + imgVert = new ImageVertexes(); + imgVert->image = img; + row->images.push_back(imgVert); + lastImage = img; } + graphics->calcTileSDL(imgVert, px, py); } } } @@ -310,39 +304,36 @@ void MapLayer::updateOGL(Graphics *const graphics, if (!tilePtr->isEnabled) continue; Image *const img = (*tilePtr).image; - if (img) + const int px = x * mapTileSize + dx; + const int py = py0 - img->mBounds.h; + const GLuint imgGlImage = img->mGLImage; + if (mSpecialFlag || + img->mBounds.h <= mapTileSize) { - const int px = x * mapTileSize + dx; - const int py = py0 - img->mBounds.h; - const GLuint imgGlImage = img->mGLImage; - if (mSpecialFlag || - img->mBounds.h <= mapTileSize) + if (!lastImage || + lastImage->mGLImage != imgGlImage) { - if (!lastImage || - lastImage->mGLImage != imgGlImage) - { - if (img->mBounds.w > mapTileSize) - imgSet.clear(); + if (img->mBounds.w > mapTileSize) + imgSet.clear(); - if (imgSet.find(imgGlImage) != imgSet.end()) - { - imgVert = imgSet[imgGlImage]; - } - else - { - if (lastImage) - imgSet[lastImage->mGLImage] = imgVert; - imgVert = new ImageVertexes(); - imgVert->ogl.init(); - imgVert->image = img; - row->images.push_back(imgVert); - } + if (imgSet.find(imgGlImage) != imgSet.end()) + { + imgVert = imgSet[imgGlImage]; } - lastImage = img; + else + { + if (lastImage) + imgSet[lastImage->mGLImage] = imgVert; + imgVert = new ImageVertexes(); + imgVert->ogl.init(); + imgVert->image = img; + row->images.push_back(imgVert); + } + } + lastImage = img; // if (imgVert->image->mGLImage != lastImage->mGLImage) // logger->log("wrong image draw"); - graphics->calcTileVertexes(imgVert, lastImage, px, py); - } + graphics->calcTileVertexes(imgVert, lastImage, px, py); } } } @@ -512,15 +503,11 @@ void MapLayer::drawFringe(Graphics *const graphics, TileInfo *tilePtr = &mTiles[CAST_SIZE(startX + yWidth)]; for (int x = startX; x < endX; x++, tilePtr++) { - if (!tilePtr->isEnabled) - continue; const int x32 = x * mapTileSize; - - const int px1 = x32 - scrollX; int c = 0; - const Image *const img = tilePtr->image; - if (img) + if (tilePtr->isEnabled) { + const Image *const img = tilePtr->image; if (mSpecialFlag || img->mBounds.h <= mapTileSize) { @@ -549,6 +536,7 @@ void MapLayer::drawFringe(Graphics *const graphics, c1 = specialWidth - x - 1; if (c1 < 0) c1 = 0; + const int px1 = x32 - scrollX; const int ptr = y * specialWidth + x; @@ -605,30 +593,27 @@ void MapLayer::drawFringe(Graphics *const graphics, continue; const int x32 = x * mapTileSize; const Image *const img = tilePtr->image; - if (img) + const int px = x32 + dx; + const int py = py0 - img->mBounds.h; + if (mSpecialFlag || + img->mBounds.h <= mapTileSize) { - const int px = x32 + dx; - const int py = py0 - img->mBounds.h; - if (mSpecialFlag || - img->mBounds.h <= mapTileSize) - { - int width = 0; - // here need not draw over player position - const int c = getTileDrawWidth(tilePtr, - endX - x, - width); + int width = 0; + // here need not draw over player position + const int c = getTileDrawWidth(tilePtr, + endX - x, + width); - if (!c) - { - graphics->drawImage(img, px, py); - } - else - { - graphics->drawPattern(img, px, py, - width, img->mBounds.h); - x += c; - tilePtr += c; - } + if (!c) + { + graphics->drawImage(img, px, py); + } + else + { + graphics->drawPattern(img, px, py, + width, img->mBounds.h); + x += c; + tilePtr += c; } } } @@ -701,8 +686,7 @@ int MapLayer::getTileDrawWidth(const TileInfo *restrict tilePtr, if (img != img1 || !tilePtr->isEnabled) break; c ++; - if (img) - width += img->mBounds.w; + width += img->mBounds.w; } BLOCK_END("MapLayer::getTileDrawWidth") return c; @@ -729,9 +713,10 @@ void MapLayer::updateConditionTiles(MetaTile *const metaTiles, TileInfo *tilePtr = mTiles + y * mWidth; for (int x = mX; x < width1; x ++, metaPtr ++, tilePtr ++) { - if (metaPtr->blockmask & mTileCondition || + if (tilePtr->image != nullptr && + (metaPtr->blockmask & mTileCondition || (metaPtr->blockmask == 0 && - mTileCondition == BlockMask::GROUND)) + mTileCondition == BlockMask::GROUND))) { tilePtr->isEnabled = true; } @@ -743,6 +728,23 @@ void MapLayer::updateConditionTiles(MetaTile *const metaTiles, } } +void MapLayer::updateCache(const int width, + const int height) restrict +{ + const int width1 = width < mWidth ? width : mWidth; + const int height1 = height < mHeight ? height : mHeight; + + for (int y = mY; y < height1; y ++) + { + TileInfo *tilePtr = mTiles + y * mWidth; + for (int x = mX; x < width1; x ++, tilePtr ++) + { + if (tilePtr->image == nullptr) + tilePtr->isEnabled = false; + } + } +} + int MapLayer::calcMemoryLocal() const { return static_cast<int>(sizeof(MapLayer) + |