From 4c8e7ad74f2709125659deaf1b4ddd10623740dc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 6 Jun 2016 23:35:09 +0300 Subject: Add support for load pseudo atlas, where atlas and each image in it will not use any images. --- src/resources/atlas/atlasmanager.cpp | 59 ++++++++++++++++++++++++++++++++++++ src/resources/atlas/atlasmanager.h | 7 +++++ src/resources/mapreader.cpp | 3 +- 3 files changed, 68 insertions(+), 1 deletion(-) (limited to 'src/resources') 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 atlases; + std::vector 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::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 &images) { @@ -151,6 +183,33 @@ void AtlasManager::loadImages(const StringVect &files, BLOCK_END("AtlasManager::loadImages") } +void AtlasManager::loadEmptyImages(const StringVect &files, + std::vector &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 &restrict atlases, const std::vector &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 &images); + static void loadEmptyImages(const StringVect &files, + std::vector &images); + static void simpleSort(const std::string &restrict name, std::vector &restrict atlases, const std::vector &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); } -- cgit v1.2.3-70-g09d2