diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-06-06 23:35:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-06-06 23:48:59 +0300 |
commit | 4c8e7ad74f2709125659deaf1b4ddd10623740dc (patch) | |
tree | d05bd73bdc535e3d1a5777789f24ac5fd12b438c /src/resources | |
parent | ee41cd5a5a37e4d41df49cd92c61868fe2ce1a51 (diff) | |
download | mv-4c8e7ad74f2709125659deaf1b4ddd10623740dc.tar.gz mv-4c8e7ad74f2709125659deaf1b4ddd10623740dc.tar.bz2 mv-4c8e7ad74f2709125659deaf1b4ddd10623740dc.tar.xz mv-4c8e7ad74f2709125659deaf1b4ddd10623740dc.zip |
Add support for load pseudo atlas, where atlas and each image in it will not use any images.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/atlas/atlasmanager.cpp | 59 | ||||
-rw-r--r-- | src/resources/atlas/atlasmanager.h | 7 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 3 |
3 files changed, 68 insertions, 1 deletions
diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp index 4e1b0e96c..353818d68 100644 --- a/src/resources/atlas/atlasmanager.cpp +++ b/src/resources/atlas/atlasmanager.cpp @@ -103,6 +103,38 @@ AtlasResource *AtlasManager::loadTextureAtlas(const std::string &name, return resource; } +AtlasResource *AtlasManager::loadEmptyAtlas(const std::string &name, + const StringVect &files) +{ + std::vector<TextureAtlas*> atlases; + std::vector<Image*> images; + AtlasResource *resource = new AtlasResource; + + loadEmptyImages(files, images); + int maxSize = OpenGLImageHelper::getTextureSize(); + + // sorting images on atlases. + simpleSort(name, atlases, images, maxSize); + + FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases) + { + TextureAtlas *const atlas = *it; + if (!atlas) + continue; + + atlas->atlasImage = new Image(0, + 8192, 8192, + 8192, 8192); + // convert SDL images to OpenGL + convertAtlas(atlas); + + resource->atlases.push_back(atlas); + } + + BLOCK_END("AtlasManager::loadTextureAtlas") + return resource; +} + void AtlasManager::loadImages(const StringVect &files, std::vector<Image*> &images) { @@ -151,6 +183,33 @@ void AtlasManager::loadImages(const StringVect &files, BLOCK_END("AtlasManager::loadImages") } +void AtlasManager::loadEmptyImages(const StringVect &files, + std::vector<Image*> &images) +{ + BLOCK_START("AtlasManager::loadEmptyImages") + + FOR_EACH (StringVectCIter, it, files) + { + const std::string str = *it; + // check is image with same name already in cache + // and if yes, move it to deleted set + Resource *const res = resourceManager->getTempResource(str); + if (res) + { + // increase counter because in moveToDeleted it will be decreased. + res->incRef(); + resourceManager->moveToDeleted(res); + } + + Image *const image = new Image(0, + 2048, 2048, + 2048, 2048); + image->mIdPath = str; + images.push_back(image); + } + BLOCK_END("AtlasManager::loadEmptyImages") +} + void AtlasManager::simpleSort(const std::string &restrict name, std::vector<TextureAtlas*> &restrict atlases, const std::vector<Image*> &restrict images, diff --git a/src/resources/atlas/atlasmanager.h b/src/resources/atlas/atlasmanager.h index b824a3c9d..176e2f090 100644 --- a/src/resources/atlas/atlasmanager.h +++ b/src/resources/atlas/atlasmanager.h @@ -45,6 +45,10 @@ class AtlasManager final const StringVect &files) A_WARN_UNUSED; + static AtlasResource *loadEmptyAtlas(const std::string &name, + const StringVect &files) + A_WARN_UNUSED; + static void injectToResources(const AtlasResource *const resource); static void moveToDeleted(AtlasResource *const resource); @@ -53,6 +57,9 @@ class AtlasManager final static void loadImages(const StringVect &files, std::vector<Image*> &images); + static void loadEmptyImages(const StringVect &files, + std::vector<Image*> &images); + static void simpleSort(const std::string &restrict name, std::vector<TextureAtlas*> &restrict atlases, const std::vector<Image*> &restrict images, diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 8c45cfc3c..d8e695b7a 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -43,6 +43,7 @@ #ifdef USE_OPENGL #include "resources/db/mapdb.h" #include "resources/loaders/atlasloader.h" +#include "resources/loaders/emptyatlasloader.h" #endif #include "resources/map/tileanimation.h" @@ -1250,7 +1251,7 @@ void MapReader::loadEmptyAtlas() paths.getStringValue("emptyAtlasName")); if (info) { - mEmptyAtlas = Loader::getAtlas( + mEmptyAtlas = Loader::getEmptyAtlas( info->atlas, *info->files); } |