summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-01 22:38:50 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-03 20:21:38 +0100
commit48d44a13e525375ef289ef577e5fc6abf1735e19 (patch)
treefe40f14217fa23dcec40e27218ff8aa786be7e8d
parent1e562bdd132c4166ca4de2bdb3f241adaa9a7149 (diff)
downloadmanaserv-48d44a13e525375ef289ef577e5fc6abf1735e19.tar.gz
manaserv-48d44a13e525375ef289ef577e5fc6abf1735e19.tar.xz
manaserv-48d44a13e525375ef289ef577e5fc6abf1735e19.zip
Clear the gid flags before processing them
Also read the gids as unsigned integers since that's how Tiled writes them to prevent the number going negative when the highest flag is used. Reviewed-by: Yohann Ferreira
-rw-r--r--src/game-server/mapreader.cpp31
-rw-r--r--src/game-server/mapreader.h2
-rw-r--r--src/utils/xml.cpp2
3 files changed, 22 insertions, 13 deletions
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 87101a6..ca1b5cf 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -31,7 +31,7 @@
#include <cstring>
-static std::vector< int > tilesetFirstGids;
+static std::vector<unsigned> tilesetFirstGids;
Map *MapReader::readMap(const std::string &filename)
{
@@ -230,10 +230,10 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
for (int i = 0; i < binLen - 3; i += 4)
{
- int gid = binData[i] |
- (binData[i + 1] << 8) |
- (binData[i + 2] << 16) |
- (binData[i + 3] << 24);
+ unsigned gid = binData[i] |
+ (binData[i + 1] << 8) |
+ (binData[i + 2] << 16) |
+ (binData[i + 3] << 24);
setTileWithGid(map, x, y, gid);
@@ -262,8 +262,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());
setTileWithGid(map, x, y, gid);
x++;
@@ -290,7 +289,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
{
if (xmlStrEqual(node->name, BAD_CAST "tile") && y < h)
{
- int gid = XML::getProperty(node, "gid", -1);
+ unsigned gid = XML::getProperty(node, "gid", 0);
setTileWithGid(map, x, y, gid);
if (++x == w)
@@ -333,11 +332,21 @@ int MapReader::getObjectProperty(xmlNodePtr node, int def)
return val;
}
-void MapReader::setTileWithGid(Map *map, int x, int y, int gid)
+void MapReader::setTileWithGid(Map *map, 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 flipping flags, they are not relevant
+ gid &= ~(FlippedHorizontallyFlag |
+ FlippedVerticallyFlag |
+ FlippedAntiDiagonallyFlag);
+
// Find the tileset with the highest firstGid below/eq to gid
- int set = gid;
- for (std::vector< int >::const_iterator i = ::tilesetFirstGids.begin(),
+ unsigned set = gid;
+ for (std::vector<unsigned>::const_iterator i = ::tilesetFirstGids.begin(),
i_end = ::tilesetFirstGids.end(); i != i_end; ++i)
{
if (gid < *i)
diff --git a/src/game-server/mapreader.h b/src/game-server/mapreader.h
index 725737f..802f6b0 100644
--- a/src/game-server/mapreader.h
+++ b/src/game-server/mapreader.h
@@ -65,7 +65,7 @@ class MapReader
*/
static int getObjectProperty(xmlNodePtr node, int def);
- static void setTileWithGid(Map *map, int x, int y, int gid);
+ static void setTileWithGid(Map *map, int x, int y, unsigned gid);
};
#endif
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 5d579dd..91ebb44 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -97,7 +97,7 @@ namespace XML
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
- ret = atoi((char*) prop);
+ ret = atol((char*) prop);
xmlFree(prop);
}