diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-01 22:22:33 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-03 20:29:10 +0100 |
commit | 66850d2dbc9798619159688dcba0cc912247ac02 (patch) | |
tree | 84f3e15620bf0f60725c10495deeaefbe1824d10 | |
parent | 024088d76569ef07be7f166f22f3f5e22592a586 (diff) | |
download | mana-66850d2dbc9798619159688dcba0cc912247ac02.tar.gz mana-66850d2dbc9798619159688dcba0cc912247ac02.tar.bz2 mana-66850d2dbc9798619159688dcba0cc912247ac02.tar.xz mana-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
-rw-r--r-- | src/map.cpp | 2 | ||||
-rw-r--r-- | src/map.h | 2 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 21 | ||||
-rw-r--r-- | src/tileset.h | 7 | ||||
-rw-r--r-- | src/utils/xml.cpp | 2 |
5 files changed, 23 insertions, 11 deletions
diff --git a/src/map.cpp b/src/map.cpp index c8ca82bb..b91c15ec 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -549,7 +549,7 @@ void Map::drawAmbientLayers(Graphics *graphics, LayerType type, } } -Tileset *Map::getTilesetWithGid(int gid) const +Tileset *Map::getTilesetWithGid(unsigned gid) const { Tileset *s = NULL; for (Tilesets::const_iterator it = mTilesets.begin(), @@ -221,7 +221,7 @@ class Map : public Properties /** * Finds the tile set that a tile with the given global id is part of. */ - Tileset *getTilesetWithGid(int gid) const; + Tileset *getTilesetWithGid(unsigned gid) const; /** * Get tile reference. 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; diff --git a/src/tileset.h b/src/tileset.h index 9e0bf936..4ba9f016 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -30,7 +30,8 @@ class Tileset : public ImageSet { public: - Tileset(Image *img, int w, int h, int firstGid, int margin, int spacing): + Tileset(Image *img, int w, int h, unsigned firstGid, + int margin, int spacing): ImageSet(img, w, h, margin, spacing), mFirstGid(firstGid) { @@ -39,13 +40,13 @@ class Tileset : public ImageSet /** * Returns the first gid. */ - int getFirstGid() const + unsigned getFirstGid() const { return mFirstGid; } private: - int mFirstGid; + unsigned mFirstGid; }; #endif // TILESET_H diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index a965e0d7..839479d7 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -99,7 +99,7 @@ namespace XML xmlChar *prop = xmlGetProp(node, BAD_CAST name); if (prop) { - ret = atoi((char*)prop); + ret = atol((char*)prop); xmlFree(prop); } |