#include "TextureList.h" #include "Text.h" #include "Texture.h" using namespace Framework; int TexturList::id = 0; Critical TexturList::cs; // Contents of the TexturList class // Constructor TexturList::TexturList() : ReferenceCounter() { textures = new RCArray(); names = new RCArray(); } // Destructor TexturList::~TexturList() { textures->release(); names->release(); } // Deletes all textures __declspec(dllexport) void TexturList::leeren() { cs.lock(); textures->leeren(); names->leeren(); cs.unlock(); } // Adds a texture to the list // t: The texture // name: The name under which the texture is stored in the list bool TexturList::addTextur(Textur* t, const char* name) { cs.lock(); for (auto i : *names) { if (i->istGleich(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 TexturList::removeTextur(const char* name) { cs.lock(); int index = 0; for (auto i : *names) { if (i->istGleich(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 TexturList::hatTextur(const char* name) const { cs.lock(); for (auto i : *names) { if (i->istGleich(name)) { cs.unlock(); return 1; } } cs.unlock(); return 0; } // Returns a specific texture // name: The name of the texture Textur* TexturList::getTextur(const char* name) const { cs.lock(); int index = 0; for (auto i : *names) { if (i->istGleich(name)) { cs.unlock(); return textures->get(index); } index++; } cs.unlock(); return 0; } // Returns a specific texture // id: The id of the texture Textur* TexturList::getTextur(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 Textur* TexturList::zTextur(const char* name) const { cs.lock(); int index = 0; for (auto i : *names) { if (i->istGleich(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 Textur* TexturList::zTextur(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 TexturList::init() { id = 0; } // Deletes static private members. Called automatically by the framework. void TexturList::destroy() {}