summaryrefslogtreecommitdiff
path: root/src/resources/mapreader.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-01 22:22:33 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-03 20:29:10 +0100
commit66850d2dbc9798619159688dcba0cc912247ac02 (patch)
tree84f3e15620bf0f60725c10495deeaefbe1824d10 /src/resources/mapreader.cpp
parent024088d76569ef07be7f166f22f3f5e22592a586 (diff)
downloadmana-client-66850d2dbc9798619159688dcba0cc912247ac02.tar.gz
mana-client-66850d2dbc9798619159688dcba0cc912247ac02.tar.bz2
mana-client-66850d2dbc9798619159688dcba0cc912247ac02.tar.xz
mana-client-66850d2dbc9798619159688dcba0cc912247ac02.zip
Clear tile flags from the gid before further processing
Better to show non-rotated/flipped tiles than no tile at all. This also fixes interpretation of collision tiles that happen to be flipped. Also interpret the gid as an unsigned number, since that's how they are written in the TMX file since the introduction of these flags. Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r--src/resources/mapreader.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 82d0e0b4..b2642ae8 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -220,8 +220,19 @@ void MapReader::readProperties(xmlNodePtr node, Properties *props)
}
}
-static void setTile(Map *map, MapLayer *layer, int x, int y, int gid)
+static void setTile(Map *map, MapLayer *layer, int x, int y, unsigned gid)
{
+ // Bits on the far end of the 32-bit global tile ID are used for tile flags
+ const int FlippedHorizontallyFlag = 0x80000000;
+ const int FlippedVerticallyFlag = 0x40000000;
+ const int FlippedAntiDiagonallyFlag = 0x20000000;
+
+ // Clear the flags
+ // TODO: It would be nice to properly support these flags later
+ gid &= ~(FlippedHorizontallyFlag |
+ FlippedVerticallyFlag |
+ FlippedAntiDiagonallyFlag);
+
const Tileset * const set = map->getTilesetWithGid(gid);
if (layer)
{
@@ -333,7 +344,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
for (int i = 0; i < binLen - 3; i += 4)
{
- const int gid = binData[i] |
+ const unsigned gid = binData[i] |
binData[i + 1] << 8 |
binData[i + 2] << 16 |
binData[i + 3] << 24;
@@ -375,7 +386,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
{
pos = csv.find_first_of(",", oldPos);
- const int gid = atoi(csv.substr(oldPos, pos - oldPos).c_str());
+ unsigned gid = atol(csv.substr(oldPos, pos - oldPos).c_str());
setTile(map, layer, x, y, gid);
@@ -400,7 +411,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
if (!xmlStrEqual(childNode2->name, BAD_CAST "tile"))
continue;
- const int gid = XML::getProperty(childNode2, "gid", -1);
+ unsigned gid = XML::getProperty(childNode2, "gid", 0);
setTile(map, layer, x, y, gid);
x++;
@@ -426,7 +437,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path,
Map *map)
{
- int firstGid = XML::getProperty(node, "firstgid", 0);
+ unsigned firstGid = XML::getProperty(node, "firstgid", 0);
int margin = XML::getProperty(node, "margin", 0);
int spacing = XML::getProperty(node, "spacing", 0);
XML::Document* doc = NULL;