From ea82328250b5b134da350f5bacbd7ee57730ba6b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 20 Apr 2018 22:58:11 +0300 Subject: Dont put on maps tiles from empty atlases. Before in wrong maps and OpenGL enabled modes, manaplus may show artifacts, because tiles from empty atlases really is not loaded and drawed. --- src/resources/db/mapdb.cpp | 17 ++++++++++++++++- src/resources/db/mapdb.h | 2 ++ src/resources/map/tileset.h | 13 ++++++++++--- src/resources/mapreader.cpp | 22 +++++++++++++++++----- 4 files changed, 45 insertions(+), 9 deletions(-) (limited to 'src/resources') diff --git a/src/resources/db/mapdb.cpp b/src/resources/db/mapdb.cpp index 0ca328dcf..971fa4578 100644 --- a/src/resources/db/mapdb.cpp +++ b/src/resources/db/mapdb.cpp @@ -34,6 +34,7 @@ namespace MapDB::Maps mMaps; MapDB::MapInfos mInfos; MapDB::Atlases mAtlases; + std::set mEmptyTilesets; } // namespace namespace MapDB @@ -137,7 +138,16 @@ void MapDB::readAtlas(XmlNodePtrConst node) mAtlases[atlas].push_back(file); } } - if (atlas != "all" && atlas != paths.getStringValue("emptyAtlasName")) + if (atlas == paths.getStringValue("emptyAtlasName")) + { + const StringVect *files = &mAtlases[atlas]; + FOR_EACHP (StringVectCIter, it, files) + { + mEmptyTilesets.insert(*it); + logger->log("empty tileset: " + *it); + } + } + else if (atlas != "all") { const AtlasCIter &allAtlas = mAtlases.find("all"); if (allAtlas != mAtlases.end()) @@ -223,3 +233,8 @@ const MapInfo *MapDB::getAtlas(const std::string &name) info->files = &(*it).second; return info; } + +bool MapDB::isEmptyTileset(const std::string &name) +{ + return mEmptyTilesets.find(name) != mEmptyTilesets.end(); +} diff --git a/src/resources/db/mapdb.h b/src/resources/db/mapdb.h index 97a8f0cb1..e7ccf972c 100644 --- a/src/resources/db/mapdb.h +++ b/src/resources/db/mapdb.h @@ -57,6 +57,8 @@ namespace MapDB const MapInfo *getAtlas(const std::string &name) A_WARN_UNUSED; + bool isEmptyTileset(const std::string &name); + // Maps DB typedef std::map Maps; typedef Maps::iterator MapIterator; diff --git a/src/resources/map/tileset.h b/src/resources/map/tileset.h index 6acf52c41..50eb112e3 100644 --- a/src/resources/map/tileset.h +++ b/src/resources/map/tileset.h @@ -43,8 +43,9 @@ class Tileset final : public ImageSet const int margin, const int spacing) : ImageSet(img, w, h, margin, spacing), + mProperties(), mFirstGid(firstGid), - mProperties() + mIsEmpty(false) { } @@ -92,10 +93,16 @@ class Tileset final : public ImageSet return sz; } - private: - int mFirstGid; + void setEmpty(const bool b) + { mIsEmpty = b; } + + bool isEmpty() const + { return mIsEmpty; } + private: std::map mProperties; + int mFirstGid; + bool mIsEmpty; }; #endif // RESOURCES_MAP_TILESET_H diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index e5e7374fe..9393e781b 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -565,10 +565,18 @@ inline static void setTile(Map *const map, { case MapLayerType::TILES: { - Image *const img = set != nullptr ? - set->get(gid - set->getFirstGid()) : nullptr; - if (layer != nullptr) + if (layer == nullptr) + break; + if (set != nullptr && + !set->isEmpty()) + { + Image *const img = set->get(gid - set->getFirstGid()); layer->setTile(x, y, img); + } + else + { + layer->setTile(x, y, nullptr); + } break; } @@ -1112,10 +1120,12 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string source = XML::getProperty( childNode, "source", ""); + const std::string sourceResolved = resolveRelativePath(pathDir, + source); + if (!source.empty()) { - Image *const tilebmp = Loader::getImage( - resolveRelativePath(pathDir, source)); + Image *const tilebmp = Loader::getImage(sourceResolved); if (tilebmp != nullptr) { @@ -1126,6 +1136,8 @@ Tileset *MapReader::readTileset(XmlNodePtr node, spacing); tilebmp->decRef(); #ifdef USE_OPENGL + if (MapDB::isEmptyTileset(sourceResolved)) + set->setEmpty(true); if (tilebmp->getType() == ImageType::Image && map->haveAtlas() == true && graphicsManager.getUseAtlases()) -- cgit v1.2.3-70-g09d2