| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- #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<Texture>();
- names = new RCArray<Text>();
- }
- // 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<Texture*>(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() {}
|