diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-15 01:47:55 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-15 01:47:55 +0300 |
commit | 60019d36cc08faa4d49f2ddb048f6a71cf87a683 (patch) | |
tree | e73f602ea61b8c935bc06a20194e954c1c382317 /src | |
parent | 23e39ef3eccab6b1297a00d3f8f199b54a7e9af9 (diff) | |
download | mv-60019d36cc08faa4d49f2ddb048f6a71cf87a683.tar.gz mv-60019d36cc08faa4d49f2ddb048f6a71cf87a683.tar.bz2 mv-60019d36cc08faa4d49f2ddb048f6a71cf87a683.tar.xz mv-60019d36cc08faa4d49f2ddb048f6a71cf87a683.zip |
improve atlasmanager.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/atlasmanager.cpp | 36 | ||||
-rw-r--r-- | src/resources/atlasmanager.h | 11 |
2 files changed, 22 insertions, 25 deletions
diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp index 27ab3053a..0f7565ecd 100644 --- a/src/resources/atlasmanager.cpp +++ b/src/resources/atlasmanager.cpp @@ -53,21 +53,19 @@ AtlasResource *AtlasManager::loadTextureAtlas(const std::string &name, AtlasResource *resource = new AtlasResource; loadImages(files, images); - int maxSize = OpenGLImageHelper::getTextureSize(); -// int maxSize = 1024; + const int maxSize = OpenGLImageHelper::getTextureSize(); // sorting images on atlases. simpleSort(name, atlases, images, maxSize); -// int k = 0; FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases) { - TextureAtlas *atlas = *it; + TextureAtlas *const atlas = *it; if (!atlas) continue; // create atlas base on sorted images - SDL_Surface *surface = createSDLAtlas(atlas); + SDL_Surface *const surface = createSDLAtlas(atlas); if (!surface) continue; @@ -116,10 +114,10 @@ void AtlasManager::loadImages(const StringVect &files, path = path.substr(0, p); } - SDL_RWops *rw = PHYSFSRWOPS_openRead(path.c_str()); + SDL_RWops *const rw = PHYSFSRWOPS_openRead(path.c_str()); if (rw) { - Image *image = d ? sdlImageHelper->load(rw, *d) + Image *const image = d ? sdlImageHelper->load(rw, *d) : sdlImageHelper->load(rw); if (image) @@ -144,7 +142,7 @@ void AtlasManager::simpleSort(const std::string &name, const std::vector<Image*>::const_iterator it_end = images.end(); for (it = images.begin(); it != it_end; ++ it) { - Image *img = *it; + const Image *const img = *it; if (img) { atlas->name = std::string("atlas_").append(name).append( @@ -155,10 +153,10 @@ void AtlasManager::simpleSort(const std::string &name, for (it = images.begin(); it != it_end; ++ it) { - Image *img = *it; + Image *const img = *it; if (img) { - AtlasItem *item = new AtlasItem(img); + AtlasItem *const item = new AtlasItem(img); item->name = img->getIdPath(); // start next line if (x + img->mBounds.w > size) @@ -182,8 +180,6 @@ void AtlasManager::simpleSort(const std::string &name, if (img->mBounds.h > tempHeight) tempHeight = img->mBounds.h; -// logger->log("image draw position: %d,%d (%d,%d)", -// x, y, img->mBounds.w, img->mBounds.h); item->x = x; item->y = y; atlas->items.push_back(item); @@ -202,7 +198,7 @@ void AtlasManager::simpleSort(const std::string &name, delete atlas; } -SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *atlas) +SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *const atlas) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN const int rmask = 0xff000000; @@ -225,21 +221,21 @@ SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *atlas) atlas->height = powerOfTwo(atlas->height); // temp SDL surface for atlas - SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, + SDL_Surface *const surface = SDL_CreateRGBSurface(SDL_SWSURFACE, atlas->width, atlas->height, 32, rmask, gmask, bmask, amask); if (!surface) return nullptr; - Graphics *graphics = new Graphics(); + Graphics *const graphics = new Graphics(); graphics->setTarget(surface); graphics->_beginDraw(); // drawing SDL images to surface FOR_EACH (std::vector<AtlasItem*>::iterator, it, atlas->items) { - AtlasItem *item = *it; - Image *image = item->image; + AtlasItem *const item = *it; + Image *const image = item->image; if (image) { @@ -253,7 +249,7 @@ SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *atlas) return surface; } -void AtlasManager::convertAtlas(TextureAtlas *atlas) +void AtlasManager::convertAtlas(TextureAtlas *const atlas) { // no check for null pointer in atlas because it was in caller // convert surface to OpemGL image @@ -282,7 +278,7 @@ void AtlasManager::convertAtlas(TextureAtlas *atlas) } } -void AtlasManager::injectToResources(AtlasResource *resource) +void AtlasManager::injectToResources(AtlasResource *const resource) { ResourceManager *const resman = ResourceManager::getInstance(); FOR_EACH (std::vector<TextureAtlas*>::iterator, it, resource->atlases) @@ -306,7 +302,7 @@ void AtlasManager::injectToResources(AtlasResource *resource) } } -void AtlasManager::moveToDeleted(AtlasResource *resource) +void AtlasManager::moveToDeleted(AtlasResource *const resource) { ResourceManager *const resman = ResourceManager::getInstance(); FOR_EACH (std::vector<TextureAtlas*>::iterator, it, resource->atlases) diff --git a/src/resources/atlasmanager.h b/src/resources/atlasmanager.h index 845e979d8..015a88e81 100644 --- a/src/resources/atlasmanager.h +++ b/src/resources/atlasmanager.h @@ -33,7 +33,7 @@ class Resource; struct AtlasItem final { - explicit AtlasItem(Image *image0) : + explicit AtlasItem(Image *const image0) : image(image0), x(0), y(0), @@ -100,9 +100,9 @@ class AtlasManager final const StringVect &files) A_WARN_UNUSED; - static void injectToResources(AtlasResource *resource); + static void injectToResources(AtlasResource *const resource); - static void moveToDeleted(AtlasResource *resource); + static void moveToDeleted(AtlasResource *const resource); private: static void loadImages(const StringVect &files, @@ -112,10 +112,11 @@ class AtlasManager final std::vector<TextureAtlas*> &atlases, std::vector<Image*> &images, int size); - static SDL_Surface *createSDLAtlas(TextureAtlas *atlas) A_WARN_UNUSED; + static SDL_Surface *createSDLAtlas(TextureAtlas *const atlas) + A_WARN_UNUSED; - static void convertAtlas(TextureAtlas *atlas); + static void convertAtlas(TextureAtlas *const atlas); }; #endif |