diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-12-31 22:53:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-12-31 22:53:42 +0300 |
commit | 896d41e4b073046c59933ea8829474bd82b9c506 (patch) | |
tree | 737bbfa3381f9d0ddd8629faf29dd6dce0ca4be3 /src/resources/map/speciallayer.cpp | |
parent | 1962d62c1e209af7d61e85a4ed3675f0a16e5924 (diff) | |
download | manaplus-896d41e4b073046c59933ea8829474bd82b9c506.tar.gz manaplus-896d41e4b073046c59933ea8829474bd82b9c506.tar.bz2 manaplus-896d41e4b073046c59933ea8829474bd82b9c506.tar.xz manaplus-896d41e4b073046c59933ea8829474bd82b9c506.zip |
Improve special layers draw speed in same way like fringe layer.
Diffstat (limited to 'src/resources/map/speciallayer.cpp')
-rw-r--r-- | src/resources/map/speciallayer.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/resources/map/speciallayer.cpp b/src/resources/map/speciallayer.cpp index c1ca865d0..b19e665f1 100644 --- a/src/resources/map/speciallayer.cpp +++ b/src/resources/map/speciallayer.cpp @@ -36,6 +36,7 @@ SpecialLayer::SpecialLayer(const std::string &name, MemoryCounter(), mName(name), mTiles(new MapItem*[width * height]), + mCache(new int[width * height]), mWidth(width), mHeight(height) { @@ -47,6 +48,7 @@ SpecialLayer::~SpecialLayer() for (int f = 0; f < mWidth * mHeight; f ++) delete2(mTiles[f]) delete [] mTiles; + delete [] mCache; } MapItem* SpecialLayer::getTile(const int x, const int y) const @@ -107,9 +109,10 @@ void SpecialLayer::addRoad(const Path &road) else item->setType(MapItemType::ROAD); } + updateCache(); } -void SpecialLayer::clean() const +void SpecialLayer::clean() { if (!mTiles) return; @@ -120,6 +123,7 @@ void SpecialLayer::clean() const if (item) item->setType(MapItemType::EMPTY); } + updateCache(); } void SpecialLayer::draw(Graphics *const graphics, int startX, int startY, @@ -158,3 +162,26 @@ int SpecialLayer::calcMemoryLocal() const return static_cast<int>(sizeof(SpecialLayer) + sizeof(MapItem) * mWidth * mHeight); } + +void SpecialLayer::updateCache() +{ + for (int y = 0; y < mHeight; y ++) + { + const int y2 = y * mWidth; + for (int x = 0; x < mWidth; x ++) + { + int c = 10000; + for (int f = x + 1; f < mWidth; f ++) + { + MapItem *const item = mTiles[f + y2]; + if (item != nullptr && + item->mType != MapItemType::EMPTY) + { + c = f - x - 1; + break; + } + } + mCache[x + y2] = c; + } + } +} |