summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/map.cpp14
-rw-r--r--src/map.h12
-rw-r--r--src/mapheights.cpp41
-rw-r--r--src/mapheights.h45
-rw-r--r--src/resources/mapreader.cpp34
-rw-r--r--src/resources/mapreader.h3
8 files changed, 144 insertions, 9 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 507c52062..6524d0e0c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -665,6 +665,8 @@ SET(SRCS
main.h
map.cpp
map.h
+ mapheights.cpp
+ mapheights.h
maplayer.cpp
maplayer.h
mgl.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index ce4d8ad64..08b3c2796 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -678,6 +678,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
main.h \
map.cpp \
map.h \
+ mapheights.cpp \
+ mapheights.h \
maplayer.cpp \
maplayer.h \
mgl.cpp \
diff --git a/src/map.cpp b/src/map.cpp
index 21c527f2c..86d2171e9 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -25,6 +25,7 @@
#include "client.h"
#include "configuration.h"
#include "render/graphics.h"
+#include "mapheights.h"
#include "maplayer.h"
#include "notifications.h"
#include "notifymanager.h"
@@ -171,10 +172,11 @@ Map::Map(const int width, const int height,
mDrawY(-1),
mDrawScrollX(-1),
mDrawScrollY(-1),
+ mAtlas(nullptr),
+ mHeights(nullptr),
mRedrawMap(true),
mBeingOpacity(false),
- mCustom(false),
- mAtlas(nullptr)
+ mCustom(false)
{
const int size = mWidth * mHeight;
for (int i = 0; i < NB_BLOCKTYPES; i++)
@@ -225,6 +227,8 @@ Map::~Map()
mAtlas->decRef();
mAtlas = nullptr;
}
+ delete mHeights;
+ mHeights = nullptr;
}
void Map::optionChanged(const std::string &value)
@@ -1575,3 +1579,9 @@ void Map::redrawMap()
{
mRedrawMap = true;
}
+
+void Map::addHeights(MapHeights *const heights)
+{
+ delete mHeights;
+ mHeights = heights;
+}
diff --git a/src/map.h b/src/map.h
index cd539de04..a6eef01bf 100644
--- a/src/map.h
+++ b/src/map.h
@@ -37,14 +37,15 @@
class Animation;
class AmbientLayer;
class Image;
+class MapHeights;
+class MapItem;
class MapLayer;
+class ObjectsLayer;
class Particle;
class Resource;
class SimpleAnimation;
-class Tileset;
class SpecialLayer;
-class MapItem;
-class ObjectsLayer;
+class Tileset;
class WalkLayer;
typedef std::vector<Tileset*> Tilesets;
@@ -421,6 +422,8 @@ class Map final : public Properties, public ConfigListener
void setWalkLayer(WalkLayer *const layer)
{ mWalkLayer = layer; }
+ void addHeights(MapHeights *const heights);
+
protected:
friend class Actor;
friend class Minimap;
@@ -536,10 +539,11 @@ class Map final : public Properties, public ConfigListener
int mDrawY;
int mDrawScrollX;
int mDrawScrollY;
+ Resource *mAtlas;
+ MapHeights *mHeights;
bool mRedrawMap;
bool mBeingOpacity;
bool mCustom;
- Resource *mAtlas;
};
#endif // MAP_H
diff --git a/src/mapheights.cpp b/src/mapheights.cpp
new file mode 100644
index 000000000..31662d85e
--- /dev/null
+++ b/src/mapheights.cpp
@@ -0,0 +1,41 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 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/>.
+ */
+
+#include "mapheights.h"
+
+#include "debug.h"
+
+MapHeights::MapHeights(const int width, const int height) :
+ mWidth(width),
+ mHeight(height),
+ mTiles(new uint8_t[mWidth * mHeight])
+{
+ memset(mTiles, 0, mWidth * mHeight);
+}
+
+MapHeights::~MapHeights()
+{
+ delete [] mTiles;
+}
+
+void MapHeights::setHeight(const int x, const int y, const uint8_t height)
+{
+ mTiles[x + y * mWidth] = height;
+}
diff --git a/src/mapheights.h b/src/mapheights.h
new file mode 100644
index 000000000..51ea885c9
--- /dev/null
+++ b/src/mapheights.h
@@ -0,0 +1,45 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 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 MAPHEIGHTS_H
+#define MAPHEIGHTS_H
+
+#include "localconsts.h"
+
+class MapHeights final
+{
+ public:
+ friend class Map;
+
+ MapHeights(const int width, const int height);
+
+ A_DELETE_COPY(MapHeights)
+
+ ~MapHeights();
+
+ void setHeight(const int x, const int y, const uint8_t height);
+
+ private:
+ int mWidth;
+ int mHeight;
+ uint8_t *mTiles;
+};
+
+#endif // MAPHEIGHTS_H
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 3ab6c49fe..2b2edb3de 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -419,6 +419,7 @@ void MapReader::readProperties(const XmlNodePtr node, Properties *const props)
inline static void setTile(Map *const map, MapLayer *const layer,
const MapLayer::Type &layerType,
+ MapHeights *const heights,
const int x, const int y, const int gid)
{
const Tileset * const set = map->getTilesetWithGid(gid);
@@ -469,7 +470,21 @@ inline static void setTile(Map *const map, MapLayer *const layer,
}
case MapLayer::HEIGHTS:
+ {
+ if (!set)
+ break;
+ if (map->getVersion() >= 2)
+ {
+ heights->setHeight(x, y, gid - set->getFirstGid() + 1);
+ }
+ else
+ {
+ Image *const img = set ? set->get(gid - set->getFirstGid())
+ : nullptr;
+ layer->setTile(x, y, img);
+ }
break;
+ }
default:
break;
@@ -477,7 +492,7 @@ inline static void setTile(Map *const map, MapLayer *const layer,
}
#define addTile() \
- setTile(map, layer, layerType, x, y, gid); \
+ setTile(map, layer, layerType, heights, x, y, gid); \
if (hasAnimations) \
{ \
TileAnimationMapCIter it = tileAnimations.find(gid); \
@@ -492,6 +507,7 @@ inline static void setTile(Map *const map, MapLayer *const layer,
bool MapReader::readBase64Layer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
const MapLayer::Type &layerType,
+ MapHeights *const heights,
const std::string &compression,
int &x, int &y, const int w, const int h)
{
@@ -592,6 +608,7 @@ bool MapReader::readBase64Layer(const XmlNodePtr childNode, Map *const map,
bool MapReader::readCsvLayer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
const MapLayer::Type &layerType,
+ MapHeights *const heights,
int &x, int &y, const int w, const int h)
{
XmlNodePtr dataChild = childNode->xmlChildrenNode;
@@ -658,6 +675,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
map->indexTilesets();
MapLayer *layer = nullptr;
+ MapHeights *heights = nullptr;
logger->log("- Loading layer \"%s\"", name.c_str());
int x = 0;
@@ -692,6 +710,11 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
layer = new MapLayer(offsetX, offsetY, w, h, isFringeLayer);
map->addLayer(layer);
}
+ else if (layerType == MapLayer::HEIGHTS)
+ {
+ heights = new MapHeights(w, h);
+ map->addHeights(heights);
+ }
const std::string encoding =
XML::getProperty(childNode, "encoding", "");
@@ -701,7 +724,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
if (encoding == "base64")
{
if (readBase64Layer(childNode, map, layer, layerType,
- compression, x, y, w, h))
+ heights, compression, x, y, w, h))
{
continue;
}
@@ -712,10 +735,15 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
}
else if (encoding == "csv")
{
- if (readCsvLayer(childNode, map, layer, layerType, x, y, w, h))
+ if (readCsvLayer(childNode, map, layer, layerType,
+ heights, x, y, w, h))
+ {
continue;
+ }
else
+ {
return;
+ }
}
else
{
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index d03021790..343dd9958 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -25,6 +25,7 @@
#include "utils/xml.h"
+#include "mapheights.h"
#include "maplayer.h"
#include <string>
@@ -76,12 +77,14 @@ class MapReader final
static bool readBase64Layer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
const MapLayer::Type &layerType,
+ MapHeights *const heights,
const std::string &compression,
int &x, int &y, const int w, const int h);
static bool readCsvLayer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
const MapLayer::Type &layerType,
+ MapHeights *const heights,
int &x, int &y, const int w, const int h);
/**