summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-07 03:48:34 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-07 03:48:34 +0000
commit7d2c736d9b1e23e6cf46799199c44ae83778a0c0 (patch)
tree6e0b70ebb67c8d05615c4a91923e214d5077d4f2 /src/resources
parent174c91fc478d3ea2bf8b7e3be013864c6ffea09c (diff)
downloadMana-7d2c736d9b1e23e6cf46799199c44ae83778a0c0.tar.gz
Mana-7d2c736d9b1e23e6cf46799199c44ae83778a0c0.tar.bz2
Mana-7d2c736d9b1e23e6cf46799199c44ae83778a0c0.tar.xz
Mana-7d2c736d9b1e23e6cf46799199c44ae83778a0c0.zip
Switched base64 codec to the PHP one and finished support for base64 encoded
binary layer data in tmx maps.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/mapreader.cpp65
-rw-r--r--src/resources/mapreader.h7
2 files changed, 62 insertions, 10 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 20438c9d..c5f3b837 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -25,6 +25,7 @@
#include "../log.h"
#include "resourcemanager.h"
#include "../graphic/spriteset.h"
+#include "../base64.h"
#include <iostream>
@@ -165,7 +166,46 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
}
// Read base64 encoded map file
-
+ xmlNodePtr dataChild = node->xmlChildrenNode;
+ if (!dataChild) continue;
+
+ int len = strlen((const char*)dataChild->content) + 1;
+ unsigned char *charData = new unsigned char[len + 1];
+ const char *charStart = (const char*)dataChild->content;
+ unsigned char *charIndex = charData;
+
+ while (*charStart) {
+ if (*charStart != ' ' && *charStart != '\t' &&
+ *charStart != '\n')
+ {
+ *charIndex = *charStart;
+ charIndex++;
+ }
+ charStart++;
+ }
+ *charIndex = '\0';
+
+ int binLen;
+ unsigned char *binData =
+ php_base64_decode(charData, strlen((char*)charData),
+ &binLen);
+
+ delete[] charData;
+
+ if (binData) {
+ 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;
+
+ setTileWithGid(map, x, y, layer, gid);
+
+ x++;
+ if (x == w) {x = 0; y++;}
+ }
+ free(binData);
+ }
}
else {
// Read plain XML map file
@@ -176,15 +216,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
if (xmlStrEqual(n2->name, BAD_CAST "tile") && y < h)
{
int gid = getProperty(n2, "gid", -1);
- if (layer == 3)
- {
- Tileset *set = getTilesetWithGid(gid);
- map->setWalk(x, y,
- !set || (gid - set->getFirstGid() == 0));
- }
- else if (layer < 3) {
- map->setTile(x, y, layer, getTileWithGid(gid));
- }
+ setTileWithGid(map, x, y, layer, gid);
x++;
if (x == w) {x = 0; y++;}
@@ -296,3 +328,16 @@ Tileset *MapReader::getTilesetWithGid(int gid)
return NULL;
}
+
+void MapReader::setTileWithGid(Map *map, int x, int y, int layer, int gid)
+{
+ if (layer == 3)
+ {
+ Tileset *set = getTilesetWithGid(gid);
+ map->setWalk(x, y,
+ !set || (gid - set->getFirstGid() == 0));
+ }
+ else if (layer < 3) {
+ map->setTile(x, y, layer, getTileWithGid(gid));
+ }
+}
diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h
index 59270f25..241945f1 100644
--- a/src/resources/mapreader.h
+++ b/src/resources/mapreader.h
@@ -94,6 +94,13 @@ class MapReader
*/
static Tileset *MapReader::getTilesetWithGid(int gid);
+ /**
+ * Sets a tile using a global tile id. Used by the layer loading
+ * routine.
+ */
+ static void MapReader::setTileWithGid(
+ Map *map, int x, int y, int layer, int gid);
+
static std::vector<Tileset*> tilesets;
};