From ee41cd5a5a37e4d41df49cd92c61868fe2ce1a51 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 6 Jun 2016 22:35:47 +0300 Subject: Load special tilesets in ignored atlas. Special tilesets for now is collision and levels. After can be other. --- src/defaults.cpp | 1 + src/game.cpp | 8 ++++++++ src/resources/db/mapdb.cpp | 12 ++++++++++++ src/resources/db/mapdb.h | 2 ++ src/resources/mapreader.cpp | 27 +++++++++++++++++++++++++++ src/resources/mapreader.h | 10 ++++++++++ 6 files changed, 60 insertions(+) diff --git a/src/defaults.cpp b/src/defaults.cpp index bb6d7412e..f235d919e 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -639,6 +639,7 @@ DefaultsData* getPathsDefaults() AddDEF("gmCommandSymbol", "@"); AddDEF("gmCharCommandSymbol", "#"); AddDEF("linkCommandSymbol", "="); + AddDEF("emptyAtlasName", "ignored"); AddDEF("palettesDir", ""); AddDEF("defaultPaletteFile", "palette.gpl"); diff --git a/src/game.cpp b/src/game.cpp index 9906b8cf1..e6da61255 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -419,6 +419,10 @@ Game::Game() : if (windowContainer) windowContainer->add(windowMenu); +#ifdef USE_OPENGL + MapReader::loadEmptyAtlas(); +#endif + initEngines(); chatWindow->postConnection(); @@ -450,6 +454,10 @@ Game::Game() : Game::~Game() { +#ifdef USE_OPENGL + MapReader::unloadEmptyAtlas(); +#endif + settings.disableLoggingInGame = false; touchManager.setInGame(false); config.write(); diff --git a/src/resources/db/mapdb.cpp b/src/resources/db/mapdb.cpp index 5e9f31cfc..48d234bb4 100644 --- a/src/resources/db/mapdb.cpp +++ b/src/resources/db/mapdb.cpp @@ -210,3 +210,15 @@ const MapInfo *MapDB::getMapAtlas(const std::string &name) info->files = &((*it2).second); return info; } + +const MapInfo *MapDB::getAtlas(const std::string &name) +{ + MapInfo *const info = new MapInfo; + + const AtlasCIter it = mAtlases.find(name); + if (it == mAtlases.end()) + return nullptr; + info->atlas = name; + info->files = &(*it).second; + return info; +} diff --git a/src/resources/db/mapdb.h b/src/resources/db/mapdb.h index dfc0f1ca1..2a71de1ce 100644 --- a/src/resources/db/mapdb.h +++ b/src/resources/db/mapdb.h @@ -55,6 +55,8 @@ namespace MapDB const MapInfo *getMapAtlas(const std::string &name) A_WARN_UNUSED; + const MapInfo *getAtlas(const std::string &name) A_WARN_UNUSED; + // Maps DB typedef std::map Maps; typedef Maps::iterator MapIterator; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 67ce2f465..8c45cfc3c 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -64,6 +64,10 @@ typedef std::map::iterator LayerInfoIterator; typedef std::set::iterator DocIterator; +#ifdef USE_OPENGL +Resource *MapReader::mEmptyAtlas = nullptr; +#endif // USE_OPENGL + namespace { std::map mKnownLayers; @@ -1235,3 +1239,26 @@ void MapReader::updateMusic(Map *const map) if (PhysFs::exists(paths.getStringValue("music").append(name).c_str())) map->setProperty("music", name); } + +#ifdef USE_OPENGL +void MapReader::loadEmptyAtlas() +{ + if (!graphicsManager.getUseAtlases()) + return; + + const MapInfo *const info = MapDB::getAtlas( + paths.getStringValue("emptyAtlasName")); + if (info) + { + mEmptyAtlas = Loader::getAtlas( + info->atlas, + *info->files); + } +} + +void MapReader::unloadEmptyAtlas() +{ + if (mEmptyAtlas) + mEmptyAtlas->decRef(); +} +#endif // USE_OPENGL diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index 37b511d03..48a9edd0c 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -30,6 +30,7 @@ class Map; class MapHeights; class Properties; +class Resource; class Tileset; /** @@ -62,6 +63,11 @@ class MapReader final static void readLayer(const XmlNodePtr node, Map *const map) A_NONNULL(2); +#ifdef USE_OPENGL + static void loadEmptyAtlas(); + static void unloadEmptyAtlas(); +#endif // USE_OPENGL + private: /** * Reads the properties element. @@ -105,6 +111,10 @@ class MapReader final static void loadLayers(const std::string &path); static void unloadTempLayers(); + +#ifdef USE_OPENGL + static Resource *mEmptyAtlas; +#endif // USE_OPENGL }; #endif // RESOURCES_MAPREADER_H -- cgit v1.2.3-70-g09d2