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 | |
parent | e8b2a5596f569e72e0e7482e8f41aaf7e710d8ec (diff) | |
download | manaplus-0c06037af71273481958ba8587bbb4082d1ed822.tar.gz manaplus-0c06037af71273481958ba8587bbb4082d1ed822.tar.bz2 manaplus-0c06037af71273481958ba8587bbb4082d1ed822.tar.xz manaplus-0c06037af71273481958ba8587bbb4082d1ed822.zip |
Improve drawing tiles.
Remove check for existing tile image in each tile.
From now tiles without image hidden.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/map/map.cpp | 10 | ||||
-rw-r--r-- | src/resources/map/map.h | 2 | ||||
-rw-r--r-- | src/resources/map/maplayer.cpp | 182 | ||||
-rw-r--r-- | src/resources/map/maplayer.h | 3 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 1 |
5 files changed, 108 insertions, 90 deletions
diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index 327df358c..759951bcf 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -1716,6 +1716,16 @@ void Map::updateConditionLayers() restrict2 } } +void Map::preCacheLayers() restrict2 +{ + FOR_EACH (LayersCIter, it, mLayers) + { + MapLayer *restrict const layer = *it; + if (layer) + layer->updateCache(mWidth, mHeight); + } +} + int Map::calcMemoryLocal() const { return static_cast<int>(sizeof(Map) + diff --git a/src/resources/map/map.h b/src/resources/map/map.h index ef1a37afa..0225e5ce7 100644 --- a/src/resources/map/map.h +++ b/src/resources/map/map.h @@ -357,6 +357,8 @@ class Map final : public Properties, void updateConditionLayers() restrict2; + void preCacheLayers() restrict2; + int calcMemoryLocal() const override final; int calcMemoryChilds(const int level) const override final; 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) + diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h index 2bdd8d43c..2ddbb6aca 100644 --- a/src/resources/map/maplayer.h +++ b/src/resources/map/maplayer.h @@ -173,6 +173,9 @@ class MapLayer final: public MemoryCounter, public ConfigListener const int width, const int height) restrict A_NONNULL(2); + void updateCache(const int width, + const int height) restrict; + private: const int mX; const int mY; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 215d5c13e..a10c5cedd 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -291,6 +291,7 @@ Map *MapReader::readMap(const std::string &restrict filename, updateMusic(map); map->updateConditionLayers(); + map->preCacheLayers(); } BLOCK_END("MapReader::readMap str") |