summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-10-11 20:05:29 +0300
committerAndrei Karas <akaras@inbox.ru>2015-10-11 20:05:29 +0300
commit2c302cc6cb54881fbe354cc9d5a9997788f63e56 (patch)
tree9cef7d73dca25c523038ddb2ce13d49349596b27
parent3bbfd3d36990113d7e91724625f4a347412dd883 (diff)
downloadmanaplus-2c302cc6cb54881fbe354cc9d5a9997788f63e56.tar.gz
manaplus-2c302cc6cb54881fbe354cc9d5a9997788f63e56.tar.bz2
manaplus-2c302cc6cb54881fbe354cc9d5a9997788f63e56.tar.xz
manaplus-2c302cc6cb54881fbe354cc9d5a9997788f63e56.zip
Add structure for tile object.
Now it contains only image pointer.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/resources/map/map.cpp8
-rw-r--r--src/resources/map/maplayer.cpp31
-rw-r--r--src/resources/map/maplayer.h6
-rw-r--r--src/resources/map/tileinfo.h38
6 files changed, 65 insertions, 20 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4079bafca..03692af24 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1136,6 +1136,7 @@ SET(SRCS
textmanager.h
particle/textparticle.cpp
particle/textparticle.h
+ resources/map/tileinfo.h
resources/map/tileset.h
touchactions.cpp
touchactions.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 1da5d60d1..1e21f80fd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1143,6 +1143,7 @@ manaplus_SOURCES += main.cpp \
resources/map/speciallayer.h \
resources/map/tileanimation.cpp \
resources/map/tileanimation.h \
+ resources/map/tileinfo.h \
resources/map/tileset.h \
resources/map/walklayer.cpp \
resources/map/walklayer.h \
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