diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-14 23:02:01 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-14 23:02:01 +0300 |
commit | e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28 (patch) | |
tree | 15f26b5db3ce8717bfc74b268dfe8db0a9742cdb /src | |
parent | 99592ffb7aa9774bd8e2f475f65c63846e01abdc (diff) | |
download | plus-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.gz plus-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.bz2 plus-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.xz plus-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.zip |
refactor a bit adding animated tiles.
Diffstat (limited to 'src')
-rw-r--r-- | src/map.h | 3 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 43 |
2 files changed, 22 insertions, 24 deletions
@@ -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) |