From 7d2c736d9b1e23e6cf46799199c44ae83778a0c0 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 7 Mar 2005 03:48:34 +0000 Subject: Switched base64 codec to the PHP one and finished support for base64 encoded binary layer data in tmx maps. --- src/resources/mapreader.cpp | 65 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 10 deletions(-) (limited to 'src/resources/mapreader.cpp') 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 @@ -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)); + } +} -- cgit v1.2.3-70-g09d2