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 | |
parent | ee41cd5a5a37e4d41df49cd92c61868fe2ce1a51 (diff) | |
download | manaverse-4c8e7ad74f2709125659deaf1b4ddd10623740dc.tar.gz manaverse-4c8e7ad74f2709125659deaf1b4ddd10623740dc.tar.bz2 manaverse-4c8e7ad74f2709125659deaf1b4ddd10623740dc.tar.xz manaverse-4c8e7ad74f2709125659deaf1b4ddd10623740dc.zip |
Add support for load pseudo atlas, where atlas and each image in it will not use any images.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-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 |
5 files changed, 74 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c169bd4c..5f3cd1dff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -724,6 +724,8 @@ SET(SRCS resources/resource.h resources/loaders/atlasloader.cpp resources/loaders/atlasloader.h + resources/loaders/emptyatlasloader.cpp + resources/loaders/emptyatlasloader.h resources/loaders/imageloader.cpp resources/loaders/imageloader.h resources/loaders/imagesetloader.cpp @@ -1439,6 +1441,8 @@ SET(DYE_CMD_SRCS resources/resource.h resources/loaders/atlasloader.cpp resources/loaders/atlasloader.h + resources/loaders/emptyatlasloader.cpp + resources/loaders/emptyatlasloader.h resources/loaders/imageloader.cpp resources/loaders/imageloader.h resources/loaders/imagesetloader.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 771e348f8..17ee559b0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -397,6 +397,8 @@ SRC += events/actionevent.h \ resources/resource.h \ resources/loaders/atlasloader.cpp \ resources/loaders/atlasloader.h \ + resources/loaders/emptyatlasloader.cpp \ + resources/loaders/emptyatlasloader.h \ resources/loaders/imageloader.cpp \ resources/loaders/imageloader.h \ resources/loaders/imagesetloader.cpp \ 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); } |