renderobjectrecycler.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. ** Command & Conquer Generals(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 : ww3d *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/renderobjectrecycler.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 5/08/01 3:54p $*
  31. * *
  32. * $Revision:: 1 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * RenderObjectRecyclerClass::Reset -- reset the cache *
  37. * RenderObjectRecyclerClass::Get_Render_Object -- Create/Re-use a render object *
  38. * RenderObjectRecyclerClass::Return_Render_Object -- Return a render object to the cache *
  39. * RenderObjectRecyclerClass::Insert_Inactive_Model -- Internally add a render object to the *
  40. * RenderObjectRecyclerClass::Reset_Model -- resets a render object so it can be re-used *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "renderobjectrecycler.h"
  43. #include <string.h>
  44. #include "rendobj.h"
  45. #include "assetmgr.h"
  46. #include "part_emt.h"
  47. #include "matrix3d.h"
  48. /***********************************************************************************************
  49. * RenderObjectRecyclerClass::Reset -- reset the pool *
  50. * *
  51. * INPUT: *
  52. * *
  53. * OUTPUT: *
  54. * *
  55. * WARNINGS: *
  56. * *
  57. * HISTORY: *
  58. * 4/25/2001 gth : Created. *
  59. *=============================================================================================*/
  60. void RenderObjectRecyclerClass::Reset(void)
  61. {
  62. InactiveModels.Reset_List();
  63. }
  64. /***********************************************************************************************
  65. * RenderObjectRecyclerClass::Get_Render_Object -- Create/Re-use a render object *
  66. * *
  67. * INPUT: *
  68. * *
  69. * OUTPUT: *
  70. * *
  71. * WARNINGS: *
  72. * *
  73. * HISTORY: *
  74. * 4/25/2001 gth : Created. *
  75. *=============================================================================================*/
  76. RenderObjClass * RenderObjectRecyclerClass::Get_Render_Object(const char * name,const Matrix3D & tm)
  77. {
  78. RefRenderObjListIterator it(&InactiveModels);
  79. RenderObjClass * found = NULL;
  80. while (!it.Is_Done()) {
  81. if (stricmp(it.Peek_Obj()->Get_Name(),name) == 0) {
  82. found = it.Peek_Obj();
  83. break;
  84. }
  85. it.Next();
  86. }
  87. if (found != NULL) {
  88. found->Add_Ref();
  89. InactiveModels.Remove(found);
  90. found->Set_Transform(tm);
  91. Reset_Model(found);
  92. return found;
  93. } else {
  94. RenderObjClass * new_model = WW3DAssetManager::Get_Instance()->Create_Render_Obj(name);
  95. if (new_model != NULL) {
  96. new_model->Set_Transform(tm);
  97. return new_model;
  98. }
  99. }
  100. return NULL;
  101. }
  102. /***********************************************************************************************
  103. * RenderObjectRecyclerClass::Return_Render_Object -- Return a render object to the pool *
  104. * *
  105. * INPUT: *
  106. * *
  107. * OUTPUT: *
  108. * *
  109. * WARNINGS: *
  110. * *
  111. * HISTORY: *
  112. * 4/25/2001 gth : Created. *
  113. *=============================================================================================*/
  114. void RenderObjectRecyclerClass::Return_Render_Object(RenderObjClass * obj)
  115. {
  116. Insert_Inactive_Model(obj);
  117. }
  118. /***********************************************************************************************
  119. * RenderObjectRecyclerClass::Insert_Inactive_Model -- Internally add a render object to the po*
  120. * *
  121. * INPUT: *
  122. * *
  123. * OUTPUT: *
  124. * *
  125. * WARNINGS: *
  126. * *
  127. * HISTORY: *
  128. * 4/25/2001 gth : Created. *
  129. *=============================================================================================*/
  130. void RenderObjectRecyclerClass::Insert_Inactive_Model(RenderObjClass * obj)
  131. {
  132. WWASSERT(obj != NULL);
  133. InactiveModels.Add(obj);
  134. }
  135. /***********************************************************************************************
  136. * RenderObjectRecyclerClass::Reset_Model -- resets a render object so it can be re-used *
  137. * *
  138. * INPUT: *
  139. * *
  140. * OUTPUT: *
  141. * *
  142. * WARNINGS: *
  143. * *
  144. * HISTORY: *
  145. * 5/8/2001 gth : Created. *
  146. *=============================================================================================*/
  147. void RenderObjectRecyclerClass::Reset_Model(RenderObjClass * model)
  148. {
  149. /*
  150. ** recursively reset all sub-objects (if any)
  151. */
  152. for (int i=0; i<model->Get_Num_Sub_Objects(); i++) {
  153. RenderObjClass * robj = model->Get_Sub_Object(i);
  154. Reset_Model(robj);
  155. robj->Release_Ref();
  156. }
  157. /*
  158. ** particle emitters must be reset (this should release their buffers)
  159. */
  160. if (model->Class_ID() == RenderObjClass::CLASSID_PARTICLEEMITTER) {
  161. ParticleEmitterClass * emitter = (ParticleEmitterClass *)model;
  162. emitter->Reset();
  163. }
  164. /*
  165. ** animated models must have their animation reset (if present)
  166. */
  167. if (model->Peek_Animation() != NULL) {
  168. model->Set_Animation(model->Peek_Animation(),0.0f,RenderObjClass::ANIM_MODE_ONCE);
  169. }
  170. }