From 76291862ce0e26040f251bc4764539d8ff6634a0 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 27 Aug 2007 20:47:31 +0000 Subject: Made client search for both compressed and non-compressed map files. --- src/engine.cpp | 12 ++++++++++-- src/resources/mapreader.cpp | 25 ++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/engine.cpp b/src/engine.cpp index fb6b6048..4a0f2f1f 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -72,7 +72,16 @@ void Engine::changeMap(const std::string &mapPath) particleEngine->clear(); // Store full map path in global var - map_path = "maps/" + mapPath.substr(0, mapPath.rfind(".")) + ".tmx.gz"; + const std::string base = "maps/" + mapPath.substr(0, mapPath.rfind(".")); + ResourceManager *resman = ResourceManager::getInstance(); + if (resman->exists(base + ".tmx")) + { + map_path = base + ".tmx"; + } + else + { + map_path = base + ".tmx.gz"; + } // Attempt to load the new map Map *newMap = MapReader::readMap(map_path); @@ -85,7 +94,6 @@ void Engine::changeMap(const std::string &mapPath) Image *mapImage = NULL; if (newMap->hasProperty("minimap")) { - ResourceManager *resman = ResourceManager::getInstance(); mapImage = resman->getImage(newMap->getProperty("minimap")); } minimap->setMapImage(mapImage); diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 2230cb6a..260d5aa9 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -160,16 +160,27 @@ MapReader::readMap(const std::string &filename) return NULL; } - // Inflate the gzipped map data unsigned char *inflated; - unsigned int inflatedSize = inflateMemory((unsigned char*) buffer, - fileSize, inflated); - free(buffer); + unsigned int inflatedSize; - if (inflated == NULL) + if (filename.find(".gz", filename.length() - 3) != std::string::npos) { - logger->log("Could not decompress map file (%s)\n", filename.c_str()); - return NULL; + // Inflate the gzipped map data + inflatedSize = + inflateMemory((unsigned char*) buffer, fileSize, inflated); + free(buffer); + + if (inflated == NULL) + { + logger->log("Could not decompress map file (%s)", + filename.c_str()); + return NULL; + } + } + else + { + inflated = (unsigned char*) buffer; + inflatedSize = fileSize; } xmlDocPtr doc = xmlParseMemory((char*) inflated, inflatedSize); -- cgit v1.2.3-70-g09d2