summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/map.cpp2
-rw-r--r--src/map.h2
-rw-r--r--src/resources/mapreader.cpp21
-rw-r--r--src/tileset.h7
-rw-r--r--src/utils/xml.cpp2
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(),
diff --git a/src/map.h b/src/map.h
index 0bec3ef4..7f75afea 100644
--- a/src/map.h
+++ b/src/map.h
@@ -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);
}