summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-14 23:02:01 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-14 23:02:01 +0300
commite0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28 (patch)
tree15f26b5db3ce8717bfc74b268dfe8db0a9742cdb
parent99592ffb7aa9774bd8e2f475f65c63846e01abdc (diff)
downloadmanaverse-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.gz
manaverse-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.bz2
manaverse-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.xz
manaverse-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.zip
refactor a bit adding animated tiles.
-rw-r--r--src/map.h3
-rw-r--r--src/resources/mapreader.cpp43
2 files changed, 22 insertions, 24 deletions
diff --git a/src/map.h b/src/map.h
index 0917deee2..cd539de04 100644
--- a/src/map.h
+++ b/src/map.h
@@ -405,7 +405,8 @@ class Map final : public Properties, public ConfigListener
bool isCustom() const A_WARN_UNUSED
{ return mCustom; }
- std::map<int, TileAnimation*> &getTileAnimations() A_WARN_UNUSED
+ const std::map<int, TileAnimation*> &getTileAnimations()
+ const A_WARN_UNUSED
{ return mTileAnimations; }
void setAtlas(Resource *const atlas)
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 4f39c80a3..59b90b396 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -467,6 +467,19 @@ inline static void setTile(Map *const map, MapLayer *const layer,
}
}
+#define addTile() \
+ setTile(map, layer, x, y, gid); \
+ if (hasAnimations) \
+ { \
+ TileAnimationMapCIter it = tileAnimations.find(gid); \
+ if (it != tileAnimations.end()) \
+ { \
+ TileAnimation *const ani = it->second; \
+ if (ani) \
+ ani->addAffectedTile(layer, x + y * w); \
+ } \
+ } \
+
bool MapReader::readBase64Layer(const XmlNodePtr childNode, Map *const map,
MapLayer *const layer,
const std::string &compression,
@@ -549,18 +562,8 @@ bool MapReader::readBase64Layer(const XmlNodePtr childNode, Map *const map,
binData[i + 2] << 16 |
binData[i + 3] << 24;
- setTile(map, layer, x, y, gid);
+ addTile();
- if (hasAnimations)
- {
- TileAnimationMapCIter it = tileAnimations.find(gid);
- if (it != tileAnimations.end())
- {
- TileAnimation *const ani = it->second;
- if (ani)
- ani->addAffectedTile(layer, x + y * w);
- }
- }
x++;
if (x == w)
{
@@ -603,17 +606,7 @@ bool MapReader::readCsvLayer(const XmlNodePtr childNode, Map *const map,
return false;
const int gid = atoi(csv.substr(oldPos, pos - oldPos).c_str());
- setTile(map, layer, x, y, gid);
- if (hasAnimations)
- {
- TileAnimationMapCIter it = tileAnimations.find(gid);
- if (it != tileAnimations.end())
- {
- TileAnimation *const ani = it->second;
- if (ani)
- ani->addAffectedTile(layer, x + y * w);
- }
- }
+ addTile();
x++;
if (x == w)
@@ -708,6 +701,10 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
}
else
{
+ const std::map<int, TileAnimation*> &tileAnimations
+ = map->getTileAnimations();
+ const bool hasAnimations = !tileAnimations.empty();
+
// Read plain XML map file
for_each_xml_child_node(childNode2, childNode)
{
@@ -715,7 +712,7 @@ void MapReader::readLayer(const XmlNodePtr node, Map *const map)
continue;
const int gid = XML::getProperty(childNode2, "gid", -1);
- setTile(map, layer, x, y, gid);
+ addTile();
x++;
if (x == w)