summaryrefslogtreecommitdiff
path: root/src/resources/mapreader.cpp
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 /src/resources/mapreader.cpp
parent99592ffb7aa9774bd8e2f475f65c63846e01abdc (diff)
downloadmv-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.gz
mv-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.bz2
mv-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.tar.xz
mv-e0a6848d3c0d3097bfab3126da6c4cf9bd8e1f28.zip
refactor a bit adding animated tiles.
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r--src/resources/mapreader.cpp43
1 files changed, 20 insertions, 23 deletions
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)