#include "TextureList.h" #include "Text.h" #include "Texture.h" using namespace Framework; int TextureList::id = 0; Critical TextureList::cs; // Contents of the TextureList class // Constructor TextureList::TextureList() : ReferenceCounter() { textures = new RCArray(); names = new RCArray(); } // Destructor TextureList::~TextureList() { textures->release(); names->release(); } // Deletes all textures __declspec(dllexport) void TextureList::clear() { cs.lock(); textures->clear(); names->clear(); cs.unlock(); } // Adds a texture to the list // t: The texture // name: The name under which the texture is stored in the list bool TextureList::addTexture(Texture* t, const char* name) { cs.lock(); for (auto i : *names) { if (i->isEqual(name)) { t->release(); cs.unlock(); return 0; } } t->id = id++; textures->add(t); names->add(new Text(name)); cs.unlock(); return 1; } // Removes a texture from the list // name: The name of the texture void TextureList::removeTexture(const char* name) { cs.lock(); int index = 0; for (auto i : *names) { if (i->isEqual(name)) { names->remove(index); textures->remove(index); cs.unlock(); return; } index++; } cs.unlock(); } // Checks whether a texture has been stored under a specific name // name: The name // return: true if a texture with the name exists bool TextureList::hasTexture(const char* name) const { cs.lock(); for (auto i : *names) { if (i->isEqual(name)) { cs.unlock(); return 1; } } cs.unlock(); return 0; } // Returns a specific texture // name: The name of the texture Texture* TextureList::getTexture(const char* name) const { cs.lock(); int index = 0; for (auto i : *names) { if (i->isEqual(name)) { cs.unlock(); return textures->get(index); } index++; } cs.unlock(); return 0; } // Returns a specific texture // id: The id of the texture Texture* TextureList::getTexture(int id) const { cs.lock(); for (auto i : *textures) { if (i->getId() == id) { cs.unlock(); return dynamic_cast(i->getThis()); } } cs.unlock(); return 0; } // Returns a specific texture without increased reference counter // name: The name of the texture Texture* TextureList::zTexture(const char* name) const { cs.lock(); int index = 0; for (auto i : *names) { if (i->isEqual(name)) { cs.unlock(); return textures->z(index); } index++; } cs.unlock(); return 0; } // Returns a specific texture without increased reference counter // id: The id of the texture Texture* TextureList::zTexture(int id) const { cs.lock(); for (auto i : *textures) { if (i->getId() == id) { cs.unlock(); return i; } } cs.unlock(); return 0; } // static functions // Initializes static private members. Called automatically by the framework. void TextureList::init() { id = 0; } // Deletes static private members. Called automatically by the framework. void TextureList::destroy() {}