effectrecycler.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Renegade *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/effectrecycler.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 7/11/01 5:15p $*
  31. * *
  32. * $Revision:: 3 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * EffectRecyclerClass::EffectRecyclerClass -- constructor *
  37. * EffectRecyclerClass::~EffectRecyclerClass -- destructor *
  38. * EffectRecyclerClass::Reset -- releases all resources *
  39. * EffectRecyclerClass::Spawn_Effect -- Spawn a timed effect into the combat scene *
  40. * EffectRecyclerClass::Spawn_Effect -- spawn an effect into the combat scene *
  41. * EffectRecyclerClass::Object_Removed_From_Scene -- physobserver interface, reclaim our obj *
  42. * EffectRecyclerClass::internal_get_tdeco -- internally recycle or allocate a tdeco *
  43. * EffectRecyclerClass::internal_get_model -- recycle or allocate a render object *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. #include "effectrecycler.h"
  46. #include "timeddecophys.h"
  47. #include "rendobj.h"
  48. #include "combat.h"
  49. #include "assetmgr.h"
  50. #include "htree.h"
  51. #include "hanim.h"
  52. #include "part_emt.h"
  53. /***********************************************************************************************
  54. * EffectRecyclerClass::EffectRecyclerClass -- constructor *
  55. * *
  56. * INPUT: *
  57. * *
  58. * OUTPUT: *
  59. * *
  60. * WARNINGS: *
  61. * *
  62. * HISTORY: *
  63. *=============================================================================================*/
  64. EffectRecyclerClass::EffectRecyclerClass(void)
  65. {
  66. }
  67. /***********************************************************************************************
  68. * EffectRecyclerClass::~EffectRecyclerClass -- destructor *
  69. * *
  70. * INPUT: *
  71. * *
  72. * OUTPUT: *
  73. * *
  74. * WARNINGS: *
  75. * *
  76. * HISTORY: *
  77. *=============================================================================================*/
  78. EffectRecyclerClass::~EffectRecyclerClass(void)
  79. {
  80. Reset();
  81. }
  82. /***********************************************************************************************
  83. * EffectRecyclerClass::Reset -- releases all resources *
  84. * *
  85. * INPUT: *
  86. * *
  87. * OUTPUT: *
  88. * *
  89. * WARNINGS: *
  90. * *
  91. * HISTORY: *
  92. * 5/8/2001 gth : Created. *
  93. * 7/11/2001 gth : Created. *
  94. *=============================================================================================*/
  95. void EffectRecyclerClass::Reset(void)
  96. {
  97. ModelRecycler.Reset();
  98. InactiveTDecos.Reset_List();
  99. }
  100. /***********************************************************************************************
  101. * EffectRecyclerClass::Spawn_Effect -- Spawn a timed effect into the combat scene *
  102. * *
  103. * INPUT: *
  104. * *
  105. * OUTPUT: *
  106. * *
  107. * WARNINGS: *
  108. * *
  109. * HISTORY: *
  110. * 5/8/2001 gth : Created. *
  111. *=============================================================================================*/
  112. void EffectRecyclerClass::Spawn_Effect(TimedDecorationPhysDefClass * def,const Matrix3D & tm)
  113. {
  114. Spawn_Effect(def->Get_Model_Name(),tm,def->Get_Lifetime());
  115. }
  116. /***********************************************************************************************
  117. * EffectRecyclerClass::Spawn_Effect -- spawn an effect into the combat scene *
  118. * *
  119. * INPUT: *
  120. * *
  121. * OUTPUT: *
  122. * *
  123. * WARNINGS: *
  124. * *
  125. * HISTORY: *
  126. * 5/8/2001 gth : Created. *
  127. *=============================================================================================*/
  128. void EffectRecyclerClass::Spawn_Effect(const char * robj_name,const Matrix3D & tm,float time)
  129. {
  130. // allocate/recycle the render object
  131. RenderObjClass * model = internal_get_model(robj_name,tm);
  132. if (model != NULL) {
  133. // allocate/recycle a TDeco
  134. TimedDecorationPhysClass * tdeco = internal_get_tdeco();
  135. if ((time == -1.0f) && (model->Class_ID() == RenderObjClass::CLASSID_PARTICLEEMITTER)) {
  136. ParticleEmitterClass * emitter = (ParticleEmitterClass *)model;
  137. time = emitter->Get_Lifetime();
  138. }
  139. // configure and add to the scene
  140. tdeco->Set_Model(model);
  141. tdeco->Set_Lifetime(time);
  142. tdeco->Enable_Dont_Save(true);
  143. tdeco->Enable_Is_Pre_Lit(true);
  144. tdeco->Set_Collision_Group(UNCOLLIDEABLE_GROUP);
  145. tdeco->Set_Observer(this);
  146. COMBAT_SCENE->Add_Dynamic_Object(tdeco);
  147. tdeco->Set_Transform(tm);
  148. REF_PTR_RELEASE(model);
  149. REF_PTR_RELEASE(tdeco);
  150. }
  151. }
  152. /***********************************************************************************************
  153. * EffectRecyclerClass::Object_Removed_From_Scene -- physobserver interface, reclaim our objec *
  154. * *
  155. * Reclaims the model and tdeco when they expire. *
  156. * *
  157. * INPUT: *
  158. * *
  159. * OUTPUT: *
  160. * *
  161. * WARNINGS: *
  162. * *
  163. * HISTORY: *
  164. * 5/8/2001 gth : Created. *
  165. *=============================================================================================*/
  166. void EffectRecyclerClass::Object_Removed_From_Scene(PhysClass * observed_obj)
  167. {
  168. WWASSERT(observed_obj != NULL);
  169. WWASSERT(observed_obj->As_TimedDecorationPhysClass() != NULL);
  170. WWASSERT(observed_obj->Peek_Model() != NULL);
  171. TimedDecorationPhysClass * tdeco = observed_obj->As_TimedDecorationPhysClass();
  172. RenderObjClass * model = tdeco->Peek_Model();
  173. ModelRecycler.Return_Render_Object(model);
  174. tdeco->Set_Model(NULL);
  175. InactiveTDecos.Add(tdeco);
  176. }
  177. /***********************************************************************************************
  178. * EffectRecyclerClass::internal_get_tdeco -- internally recycle or allocate a tdeco *
  179. * *
  180. * INPUT: *
  181. * *
  182. * OUTPUT: *
  183. * *
  184. * WARNINGS: *
  185. * *
  186. * HISTORY: *
  187. * 5/8/2001 gth : Created. *
  188. *=============================================================================================*/
  189. TimedDecorationPhysClass * EffectRecyclerClass::internal_get_tdeco(void)
  190. {
  191. if (InactiveTDecos.Is_Empty()) {
  192. return NEW_REF(TimedDecorationPhysClass,());
  193. } else {
  194. return InactiveTDecos.Remove_Head();
  195. }
  196. }
  197. /***********************************************************************************************
  198. * EffectRecyclerClass::internal_get_model -- recycle or allocate a render object *
  199. * *
  200. * INPUT: *
  201. * *
  202. * OUTPUT: *
  203. * *
  204. * WARNINGS: *
  205. * *
  206. * HISTORY: *
  207. * 5/8/2001 gth : Created. *
  208. *=============================================================================================*/
  209. RenderObjClass * EffectRecyclerClass::internal_get_model(const char * robj_name,const Matrix3D & tm)
  210. {
  211. RenderObjClass * model = ModelRecycler.Get_Render_Object(robj_name,tm);
  212. if ((model != NULL) && (model->Get_HTree() != NULL)) {
  213. /*
  214. ** Auto play an anim if we find it
  215. */
  216. StringClass anim_name;
  217. anim_name.Format( "%s.%s",
  218. model->Get_HTree()->Get_Name(),
  219. model->Get_HTree()->Get_Name() );
  220. WWASSERT(WW3DAssetManager::Get_Instance() != NULL);
  221. HAnimClass * anim = WW3DAssetManager::Get_Instance()->Get_HAnim( anim_name );
  222. if ( anim != NULL ) {
  223. model->Set_Animation( anim, 0, RenderObjClass::ANIM_MODE_ONCE );
  224. anim->Release_Ref();
  225. }
  226. }
  227. return model;
  228. }