diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-04-20 22:58:11 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-04-20 22:58:11 +0300 |
commit | ea82328250b5b134da350f5bacbd7ee57730ba6b (patch) | |
tree | 2d02eec7524ce69bc12f5bede7f409f3d29cb209 /src | |
parent | e7f9514cab45863edf6a613ef8563bb15ff66e96 (diff) | |
download | plus-ea82328250b5b134da350f5bacbd7ee57730ba6b.tar.gz plus-ea82328250b5b134da350f5bacbd7ee57730ba6b.tar.bz2 plus-ea82328250b5b134da350f5bacbd7ee57730ba6b.tar.xz plus-ea82328250b5b134da350f5bacbd7ee57730ba6b.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/db/mapdb.cpp | 17 | ||||
-rw-r--r-- | src/resources/db/mapdb.h | 2 | ||||
-rw-r--r-- | src/resources/map/tileset.h | 13 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 22 |
4 files changed, 45 insertions, 9 deletions
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<std::string> 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<std::string, std::string> 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<std::string, std::string> 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()) |