TexturList.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include "TexturList.h"
  2. #include "Textur.h"
  3. #include "Text.h"
  4. using namespace Framework;
  5. int TexturList::id = 0;
  6. Critical TexturList::cs;
  7. // Inhalt der TexturList Klasse
  8. // Konstruktor
  9. TexturList::TexturList()
  10. : ReferenceCounter()
  11. {
  12. textures = new RCArray< Textur >();
  13. names = new RCArray< Text >();
  14. }
  15. // Destruktor
  16. TexturList::~TexturList()
  17. {
  18. textures->release();
  19. names->release();
  20. }
  21. // Löscht alle Texturen
  22. __declspec( dllexport ) void TexturList::leeren()
  23. {
  24. cs.lock();
  25. textures->leeren();
  26. names->leeren();
  27. cs.unlock();
  28. }
  29. // Fügt der Liste eine Textur hinzu
  30. // t: Die Textur
  31. // name: Der name, unter dem die Textur in der Liste gespeichert wird
  32. bool TexturList::addTextur( Textur *t, const char *name )
  33. {
  34. cs.lock();
  35. for( auto i = names->getIterator(); i; i++ )
  36. {
  37. if( i->istGleich( name ) )
  38. {
  39. t->release();
  40. cs.unlock();
  41. return 0;
  42. }
  43. }
  44. t->id = id++;
  45. textures->add( t );
  46. names->add( new Text( name ) );
  47. cs.unlock();
  48. return 1;
  49. }
  50. // Entfernt eine Textur aus der Liste
  51. // name: Der Name der Textur
  52. void TexturList::removeTextur( const char *name )
  53. {
  54. cs.lock();
  55. int index = 0;
  56. for( auto i = names->getIterator(); i; i++ )
  57. {
  58. if( i->istGleich( name ) )
  59. {
  60. names->remove( index );
  61. textures->remove( index );
  62. cs.unlock();
  63. return;
  64. }
  65. index++;
  66. }
  67. cs.unlock();
  68. }
  69. // Überprüft, ob unter einem bestimmten Namen eine Textur abgespeichert wurde
  70. // name: Der Name
  71. // return: true, wenn eine Textur mit dem Namen existiert
  72. bool TexturList::hatTextur( const char *name ) const
  73. {
  74. cs.lock();
  75. for( auto i = names->getIterator(); i; i++ )
  76. {
  77. if( i->istGleich( name ) )
  78. {
  79. cs.unlock();
  80. return 1;
  81. }
  82. }
  83. cs.unlock();
  84. return 0;
  85. }
  86. // Gibt eine bestimmte Textur zurück
  87. // name: Der Name der Textur
  88. Textur *TexturList::getTextur( const char *name ) const
  89. {
  90. cs.lock();
  91. int index = 0;
  92. for( auto i = names->getIterator(); i; i++ )
  93. {
  94. if( i->istGleich( name ) )
  95. {
  96. cs.unlock();
  97. return textures->get( index );
  98. }
  99. index++;
  100. }
  101. cs.unlock();
  102. return 0;
  103. }
  104. // Gibt eine bestimmte Textur zurück
  105. // id: Die Id der Textur
  106. Textur *TexturList::getTextur( int id ) const
  107. {
  108. cs.lock();
  109. for( auto i = textures->getIterator(); i; i++ )
  110. {
  111. if( i->getId() == id )
  112. {
  113. cs.unlock();
  114. return (Textur *)i->getThis();
  115. }
  116. }
  117. cs.unlock();
  118. return 0;
  119. }
  120. // Gibt eine bestimmte Textur ohne erhöhten Reference Counter zurück
  121. // name: Der Name der Textur
  122. Textur *TexturList::zTextur( const char *name ) const
  123. {
  124. cs.lock();
  125. int index = 0;
  126. for( auto i = names->getIterator(); i; i++ )
  127. {
  128. if( i->istGleich( name ) )
  129. {
  130. cs.unlock();
  131. return textures->z( index );
  132. }
  133. index++;
  134. }
  135. cs.unlock();
  136. return 0;
  137. }
  138. // Gibt eine bestimmte Textur ohne erhöhten Reference Counter zurück
  139. // id: Die Id der Textur
  140. Textur *TexturList::zTextur( int id ) const
  141. {
  142. cs.lock();
  143. for( auto i = textures->getIterator(); i; i++ )
  144. {
  145. if( i->getId() == id )
  146. {
  147. cs.unlock();
  148. return i;
  149. }
  150. }
  151. cs.unlock();
  152. return 0;
  153. }
  154. // statische Funktionen
  155. // Initialisiert statische private member. Wird vom Framework automatisch aufgerufen.
  156. void TexturList::init()
  157. {
  158. id = 0;
  159. }
  160. // Löscht statische private member. Wird vom Framework automatisch aufgerufen.
  161. void TexturList::destroy()
  162. {}