ffactorylist.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/ffactorylist.cpp $*
  25. * *
  26. * $Author:: Patrick $*
  27. * *
  28. * $Modtime:: 2/21/02 3:22p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "ffactorylist.h"
  36. #include "wwfile.h"
  37. FileFactoryListClass * FileFactoryListClass::Instance = NULL;
  38. /*
  39. **
  40. */
  41. FileFactoryListClass::FileFactoryListClass( void ) :
  42. SearchStartIndex( 0 ),
  43. TempFactory( NULL )
  44. {
  45. WWASSERT( Instance == NULL );
  46. Instance = this;
  47. }
  48. FileFactoryListClass::~FileFactoryListClass( void )
  49. {
  50. WWASSERT( Instance == this );
  51. Instance = NULL;
  52. }
  53. /*
  54. **
  55. */
  56. void FileFactoryListClass::Add_FileFactory( FileFactoryClass * factory, const char *name )
  57. {
  58. FactoryList.Add( factory );
  59. FactoryNameList.Add( name );
  60. Reset_Search_Start ();
  61. }
  62. /*
  63. **
  64. */
  65. void FileFactoryListClass::Remove_FileFactory( FileFactoryClass * factory )
  66. {
  67. for (int index = 0; index < FactoryList.Count (); index ++) {
  68. //
  69. // If this is the factory we're looking for, then remove
  70. // it from the list.
  71. //
  72. if (FactoryList[index] == factory) {
  73. FactoryList.Delete (index);
  74. FactoryNameList.Delete (index);
  75. Reset_Search_Start ();
  76. break;
  77. }
  78. }
  79. return ;
  80. }
  81. /***********************************************************************************************
  82. * FileFactoryListClass::Remove_FileFactory -- Remove any old file factory *
  83. * *
  84. * *
  85. * *
  86. * INPUT: Nothing *
  87. * *
  88. * OUTPUT: Ptr to removed factory. NULL if none in the list *
  89. * *
  90. * WARNINGS: None *
  91. * *
  92. * HISTORY: *
  93. * 9/7/2001 4:40PM ST : Created *
  94. *=============================================================================================*/
  95. FileFactoryClass *FileFactoryListClass::Remove_FileFactory(void)
  96. {
  97. FileFactoryClass *factory = NULL;
  98. if (FactoryList.Count()) {
  99. factory = FactoryList[0];
  100. FactoryList.Delete(0);
  101. FactoryNameList.Delete(0);
  102. }
  103. Reset_Search_Start ();
  104. return(factory);
  105. }
  106. void FileFactoryListClass::Add_Temp_FileFactory( FileFactoryClass * factory )
  107. {
  108. WWASSERT( TempFactory == NULL );
  109. TempFactory = factory;
  110. }
  111. FileFactoryClass * FileFactoryListClass::Remove_Temp_FileFactory( void )
  112. {
  113. FileFactoryClass * factory = TempFactory;
  114. TempFactory = NULL;
  115. return factory;
  116. }
  117. FileClass * FileFactoryListClass::Get_File( char const *filename )
  118. {
  119. // Very kludgly...
  120. // Then the temp factory
  121. if ( TempFactory ) {
  122. FileClass * file = TempFactory->Get_File( filename );
  123. if ( file != NULL ) {
  124. if ( file->Is_Available() ) {
  125. return file;
  126. } else {
  127. TempFactory->Return_File( file );
  128. }
  129. }
  130. }
  131. // Try the first in the list...
  132. if ( SearchStartIndex < FactoryList.Count() ) {
  133. FileClass * file = FactoryList[SearchStartIndex]->Get_File( filename );
  134. if ( file != NULL ) {
  135. if ( file->Is_Available() ) {
  136. return file;
  137. } else {
  138. FactoryList[SearchStartIndex]->Return_File( file );
  139. }
  140. }
  141. }
  142. // Then try the rest
  143. for ( int i = 0; i < FactoryList.Count(); i++ ) {
  144. if (i != SearchStartIndex) {
  145. FileClass * file = FactoryList[i]->Get_File( filename );
  146. if ( file != NULL ) {
  147. if ( file->Is_Available() ) {
  148. return file;
  149. } else {
  150. FactoryList[i]->Return_File( file );
  151. }
  152. }
  153. }
  154. }
  155. // Failed!
  156. // Just use the first and don't check for available
  157. if ( FactoryList.Count() > 0 ) {
  158. FileClass * file = FactoryList[0]->Get_File( filename );
  159. if ( file != NULL ) {
  160. return file;
  161. }
  162. }
  163. return NULL;
  164. }
  165. void FileFactoryListClass::Return_File( FileClass *file )
  166. {
  167. // This is kinda bad. Just return it to the first one. (Since they all do the same thing)
  168. FactoryList[0]->Return_File( file );
  169. }
  170. void FileFactoryListClass::Set_Search_Start( const char *name )
  171. {
  172. SearchStartIndex = 0;
  173. //
  174. // Try to find which mix file we should start searching from...
  175. //
  176. for (int index = 0; index < FactoryNameList.Count (); index ++) {
  177. if (FactoryNameList[index].Compare_No_Case( name ) == 0) {
  178. SearchStartIndex = index;
  179. break;
  180. }
  181. }
  182. return ;
  183. }