key sprites in sprite atlas by name and wrap value

This commit is contained in:
Konstantin Käfer
2015-07-02 17:36:27 +02:00
parent a0e391c0cb
commit 70d0a26f98
2 changed files with 5 additions and 3 deletions

View File

@@ -51,7 +51,7 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(const size_t pixel_width
SpriteAtlasElement SpriteAtlas::getImage(const std::string& name, const bool wrap) {
std::lock_guard<std::recursive_mutex> lock(mtx);
auto rect_it = images.find(name);
auto rect_it = images.find({ name, wrap });
if (rect_it != images.end()) {
return { rect_it->second.pos, rect_it->second.texture };
}
@@ -69,7 +69,7 @@ SpriteAtlasElement SpriteAtlas::getImage(const std::string& name, const bool wra
return { Rect<dimension> { 0, 0, 0, 0 }, nullptr };
}
const Holder& holder = images.emplace(name, Holder{ sprite, rect }).first->second;
const Holder& holder = images.emplace(Key{ name, wrap }, Holder{ sprite, rect }).first->second;
copy(holder, wrap);
return { rect, sprite };

View File

@@ -75,6 +75,8 @@ private:
const Rect<dimension> pos;
};
using Key = std::pair<std::string, bool>;
void allocate();
Rect<SpriteAtlas::dimension> allocateImage(size_t width, size_t height);
void copy(const Holder& holder, const bool wrap);
@@ -83,7 +85,7 @@ private:
SpriteStore& store;
const float pixelRatio;
BinPack<dimension> bin;
std::map<std::string, Holder> images;
std::map<Key, Holder> images;
std::set<std::string> uninitialized;
std::unique_ptr<uint32_t[]> data;
std::atomic<bool> dirty;