diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-07-07 02:12:24 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-07-07 03:17:16 +0300 |
commit | 7d151c8fc05cd7feaf1e1cee33fd8289208fa18d (patch) | |
tree | cc246201d9aafb94087efbe85cd13b4b18eacaaf /src/map.cpp | |
parent | 95c8a3c0b4d2f0d39c81a6671452e1aa34a626f9 (diff) | |
download | plus-7d151c8fc05cd7feaf1e1cee33fd8289208fa18d.tar.gz plus-7d151c8fc05cd7feaf1e1cee33fd8289208fa18d.tar.bz2 plus-7d151c8fc05cd7feaf1e1cee33fd8289208fa18d.tar.xz plus-7d151c8fc05cd7feaf1e1cee33fd8289208fa18d.zip |
Add map reduce feature for software drawing.
Now invisible tiles will be removed if this mode enabled.
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/map.cpp b/src/map.cpp index 88eecf4e8..0d98628fd 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1652,6 +1652,119 @@ void Map::clearIndexedTilesets() mIndexedTilesetsSize = 0; } +void Map::reduce() +{ + if (!mFringeLayer || mOpenGL > 0 || + !config.getBoolValue("enableMapReduce")) + { + return; + } + + int cnt = 0; + for (int x = 0; x < mWidth; x ++) + { + for (int y = 0; y < mHeight; y ++) + { + Layers::const_iterator layeri = mLayers.begin(); + bool correct(true); + bool dontHaveAlpha(false); + + for (; layeri != mLayers.end(); ++ layeri) + { + MapLayer *layer = *layeri; + if (x >= layer->mWidth || y >= layer->mHeight) + continue; + + Image *img = layer->mTiles[x + y * layer->mWidth]; + if (img) + { + img->setAlphaVisible(true); + if (img->mBounds.w > 32 || img->mBounds.h > 32) + { + correct = false; + break; + } + else if (!img->isHasAlphaChannel()) + { + dontHaveAlpha = true; + img->setAlphaVisible(false); + } + else if (img->hasAlphaChannel()) + { + Uint8 *arr = img->SDLgetAlphaChannel(); + if (!arr) + continue; + bool bad(false); + bool stop(false); + int width; + SubImage *subImg = dynamic_cast<SubImage*>(img); + if (subImg) + width = subImg->mInternalBounds.w; + else + width = img->mBounds.w; + + for (int f = img->mBounds.x; + f < img->mBounds.x + img->mBounds.w; f ++) + { + for (int d = img->mBounds.y; + d < img->mBounds.y + img->mBounds.h; d ++) + { + Uint8 chan = arr[f + d * width]; + if (chan != 255) + { + bad = true; + stop = true; + break; + } + } + if (stop) + break; + } + if (!bad) + { + dontHaveAlpha = true; + img->setAlphaVisible(false); + } + else + { + img->setAlphaVisible(true); + } + } + } + } + if (!correct || !dontHaveAlpha) + continue; + + Layers::const_reverse_iterator ri = mLayers.rbegin(); + while (ri != mLayers.rend()) + { + MapLayer *layer = *ri; + if (x >= layer->mWidth || y >= layer->mHeight) + continue; + + Image *img = layer->mTiles[x + y * layer->mWidth]; + if (img && !img->isAlphaVisible()) + { // removing all down tiles + ++ ri; + while (ri != mLayers.rend()) + { + img = (*ri)->mTiles[x + y * (*ri)->mWidth]; + if (img) + { + (*ri)->mTiles[x + y * (*ri)->mWidth] = 0; + cnt ++; + } + ++ ri; + } + break; + } + ++ ri; + } + } + } + logger->log("tiles reduced: %d", cnt); +} + SpecialLayer::SpecialLayer(int width, int height, bool drawSprites): mWidth(width), mHeight(height) { |