diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/map/map.cpp | 8 | ||||
-rw-r--r-- | src/resources/map/maplayer.cpp | 31 | ||||
-rw-r--r-- | src/resources/map/maplayer.h | 6 | ||||
-rw-r--r-- | src/resources/map/tileinfo.h | 38 |
4 files changed, 63 insertions, 20 deletions
diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index cc2d3487a..e206edef2 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -1405,7 +1405,7 @@ void Map::reduce() if (x >= layer->mWidth || y >= layer->mHeight) continue; - Image *const img = layer->mTiles[x + y * layer->mWidth]; + Image *const img = layer->mTiles[x + y * layer->mWidth].image; if (img) { if (img->hasAlphaChannel() && img->isAlphaCalculated()) @@ -1487,7 +1487,7 @@ void Map::reduce() continue; } - const Image *img = layer->mTiles[x + y * layer->mWidth]; + const Image *img = layer->mTiles[x + y * layer->mWidth].image; if (img && !img->isAlphaVisible()) { // removing all down tiles ++ ri; @@ -1496,10 +1496,10 @@ void Map::reduce() MapLayer *const layer2 = *ri; const size_t pos = static_cast<size_t>( x + y * layer2->mWidth); - img = layer2->mTiles[pos]; + img = layer2->mTiles[pos].image; if (img) { - layer2->mTiles[pos] = nullptr; + layer2->mTiles[pos].image = nullptr; cnt ++; } ++ ri; diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp index 97c2ba5f1..51691925b 100644 --- a/src/resources/map/maplayer.cpp +++ b/src/resources/map/maplayer.cpp @@ -52,7 +52,7 @@ MapLayer::MapLayer(const int x, const int y, mY(y), mWidth(width), mHeight(height), - mTiles(new Image*[mWidth * mHeight]), + mTiles(new TileInfo[mWidth * mHeight]), mDrawLayerFlags(MapType::NORMAL), mSpecialLayer(nullptr), mTempLayer(nullptr), @@ -63,7 +63,7 @@ MapLayer::MapLayer(const int x, const int y, mHighlightAttackRange(config.getBoolValue("highlightAttackRange")), mSpecialFlag(true) { - std::fill_n(mTiles, mWidth * mHeight, static_cast<Image*>(nullptr)); +// std::fill_n(mTiles, mWidth * mHeight, static_cast<Image*>(nullptr)); config.addListener("highlightAttackRange", this); } @@ -72,7 +72,10 @@ MapLayer::~MapLayer() { config.removeListener("highlightAttackRange", this); CHECKLISTENERS - delete [] mTiles; +// const int sz = mWidth * mHeight; +// for (int f = 0; f < sz; f ++) +// delete mTiles[f].image; + delete []mTiles; delete_all(mTempRows); mTempRows.clear(); } @@ -88,7 +91,7 @@ void MapLayer::optionChanged(const std::string &value) void MapLayer::setTile(const int x, const int y, Image *const img) { - mTiles[x + y * mWidth] = img; + mTiles[x + y * mWidth].image = img; } void MapLayer::draw(Graphics *const graphics, @@ -123,14 +126,14 @@ void MapLayer::draw(Graphics *const graphics, const int py0 = y32 + dy; - Image **tilePtr = mTiles + static_cast<size_t>(startX + yWidth); + TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)]; for (int x = startX; x < endX; x++, tilePtr++) { const int x32 = x * mapTileSize; int c = 0; - const Image *const img = *tilePtr; + const Image *const img = (*tilePtr).image; if (img) { const int px = x32 + dx; @@ -216,11 +219,11 @@ void MapLayer::updateSDL(const Graphics *const graphics, const int yWidth = y * mWidth; const int py0 = y * mapTileSize + dy; - Image **tilePtr = mTiles + static_cast<size_t>(startX + yWidth); + TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)]; for (int x = startX; x < endX; x++, tilePtr++) { - Image *const img = *tilePtr; + Image *const img = (*tilePtr).image; if (img) { const int px = x * mapTileSize + dx; @@ -279,10 +282,10 @@ void MapLayer::updateOGL(Graphics *const graphics, { const int yWidth = y * mWidth; const int py0 = y * mapTileSize + dy; - Image **tilePtr = mTiles + static_cast<size_t>(startX + yWidth); + TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)]; for (int x = startX; x < endX; x++, tilePtr++) { - Image *const img = *tilePtr; + Image *const img = (*tilePtr).image; if (img) { const int px = x * mapTileSize + dx; @@ -480,14 +483,14 @@ void MapLayer::drawFringe(Graphics *const graphics, const int py0 = y32 + dy; const int py1 = y32 - scrollY; - Image **tilePtr = mTiles + static_cast<size_t>(startX + yWidth); + TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)]; for (int x = startX; x < endX; x++, tilePtr++) { const int x32 = x * mapTileSize; const int px1 = x32 - scrollX; int c = 0; - const Image *const img = *tilePtr; + const Image *const img = (*tilePtr).image; if (img) { if (mSpecialFlag || img->mBounds.h <= mapTileSize) @@ -565,11 +568,11 @@ void MapLayer::drawFringe(Graphics *const graphics, const int py0 = y32 + dy; - Image **tilePtr = mTiles + static_cast<size_t>(startX + yWidth); + TileInfo *tilePtr = &mTiles[static_cast<size_t>(startX + yWidth)]; for (int x = startX; x < endX; x++, tilePtr++) { const int x32 = x * mapTileSize; - const Image *const img = *tilePtr; + const Image *const img = (*tilePtr).image; if (img) { const int px = x32 + dx; diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h index be17804d8..8c36fa771 100644 --- a/src/resources/map/maplayer.h +++ b/src/resources/map/maplayer.h @@ -29,6 +29,8 @@ #include "enums/resources/map/maptype.h" +#include "resources/map/tileinfo.h" + #include <vector> class Image; @@ -76,7 +78,7 @@ class MapLayer final: public ConfigListener * Set tile image with x + y * width already known. */ void setTile(const int index, Image *const img) - { mTiles[index] = img; } + { mTiles[index].image = img; } /** * Draws this layer to the given graphics context. The coordinates are @@ -157,7 +159,7 @@ class MapLayer final: public ConfigListener const int mY; const int mWidth; const int mHeight; - Image **const mTiles; + TileInfo *const mTiles; MapTypeT mDrawLayerFlags; const SpecialLayer *mSpecialLayer; const SpecialLayer *mTempLayer; diff --git a/src/resources/map/tileinfo.h b/src/resources/map/tileinfo.h new file mode 100644 index 000000000..4edd6d2b9 --- /dev/null +++ b/src/resources/map/tileinfo.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_MAP_TILEINFO_H +#define RESOURCES_MAP_TILEINFO_H + +#include "localconsts.h" + +class Image; + +struct TileInfo final +{ + TileInfo() : + image(nullptr) + { + } + + Image *image; +}; + +#endif // RESOURCES_MAP_TILEINFO_H |