editoronlyobjectnode.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 : leveledit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/editoronlyobjectnode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/22/01 12:56p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "editoronlyobjectnode.h"
  37. #include "editoronlydefinition.h"
  38. #include "phys.h"
  39. #include "rendobj.h"
  40. #include "sceneeditor.h"
  41. #include "filemgr.h"
  42. #include "_assetmgr.h"
  43. #include "editorassetmgr.h"
  44. #include "w3d_file.h"
  45. #include "cameramgr.h"
  46. #include "collisiongroups.h"
  47. #include "persistfactory.h"
  48. #include "editorchunkids.h"
  49. #include "preset.h"
  50. #include "presetmgr.h"
  51. #include "nodemgr.h"
  52. #include "part_emt.h"
  53. #include "modelutils.h"
  54. //////////////////////////////////////////////////////////////////////////////
  55. // Local prototypes
  56. //////////////////////////////////////////////////////////////////////////////
  57. //////////////////////////////////////////////////////////////////////////////
  58. // Persist factory
  59. //////////////////////////////////////////////////////////////////////////////
  60. SimplePersistFactoryClass<EditorOnlyObjectNodeClass, CHUNKID_EDITOR_ONLY_OBJECTS> _EditorOnlyObjNodePersistFactory;
  61. //////////////////////////////////////////////////////////////////////////////
  62. //
  63. // EditorOnlyObjectNodeClass
  64. //
  65. //////////////////////////////////////////////////////////////////////////////
  66. EditorOnlyObjectNodeClass::EditorOnlyObjectNodeClass (PresetClass *preset)
  67. : DisplayObj (NULL),
  68. NodeClass (preset)
  69. {
  70. return ;
  71. }
  72. //////////////////////////////////////////////////////////////////////////////
  73. //
  74. // EditorOnlyObjectNodeClass
  75. //
  76. //////////////////////////////////////////////////////////////////////////////
  77. EditorOnlyObjectNodeClass::EditorOnlyObjectNodeClass (const EditorOnlyObjectNodeClass &src)
  78. : DisplayObj (NULL),
  79. NodeClass (NULL)
  80. {
  81. *this = src;
  82. return ;
  83. }
  84. //////////////////////////////////////////////////////////////////////////////
  85. //
  86. // ~EditorOnlyObjectNodeClass
  87. //
  88. //////////////////////////////////////////////////////////////////////////////
  89. EditorOnlyObjectNodeClass::~EditorOnlyObjectNodeClass (void)
  90. {
  91. Remove_From_Scene ();
  92. MEMBER_RELEASE (DisplayObj);
  93. return ;
  94. }
  95. //////////////////////////////////////////////////////////////////////////////
  96. //
  97. // Initialize
  98. //
  99. // Note: This may be called more than once. It is used as an 'initialize'
  100. // and a 're-initialize'.
  101. //
  102. //////////////////////////////////////////////////////////////////////////////
  103. void
  104. EditorOnlyObjectNodeClass::Initialize (void)
  105. {
  106. EditorOnlyDefinitionClass *definition = static_cast<EditorOnlyDefinitionClass *> (m_Preset->Get_Definition ());
  107. if (definition != NULL) {
  108. MEMBER_RELEASE (DisplayObj);
  109. //
  110. // Make sure we have all the assets loaded into memory that this object needs.
  111. //
  112. m_Preset->Load_All_Assets ();
  113. //
  114. // Create the display object
  115. //
  116. DisplayObj = new DecorationPhysClass;
  117. CString render_obj_name = ::Asset_Name_From_Filename (definition->Get_Model_Name ());
  118. RenderObjClass *render_obj = ::Create_Render_Obj (render_obj_name);
  119. if (render_obj != NULL) {
  120. DisplayObj->Set_Model (render_obj);
  121. MEMBER_RELEASE (render_obj);
  122. DisplayObj->Set_Collision_Group (GAME_COLLISION_GROUP);
  123. DisplayObj->Peek_Model ()->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  124. ::Set_Model_Collision_Type (DisplayObj->Peek_Model (), 15);
  125. }
  126. //
  127. // Update the transforms of both objects
  128. //
  129. Set_Transform (m_Transform);
  130. }
  131. return ;
  132. }
  133. ////////////////////////////////////////////////////////////////
  134. //
  135. // Get_Factory
  136. //
  137. ////////////////////////////////////////////////////////////////
  138. const PersistFactoryClass &
  139. EditorOnlyObjectNodeClass::Get_Factory (void) const
  140. {
  141. return _EditorOnlyObjNodePersistFactory;
  142. }
  143. /////////////////////////////////////////////////////////////////
  144. //
  145. // operator=
  146. //
  147. /////////////////////////////////////////////////////////////////
  148. const EditorOnlyObjectNodeClass &
  149. EditorOnlyObjectNodeClass::operator= (const EditorOnlyObjectNodeClass &src)
  150. {
  151. NodeClass::operator= (src);
  152. return *this;
  153. }
  154. //////////////////////////////////////////////////////////////////////
  155. //
  156. // Pre_Export
  157. //
  158. //////////////////////////////////////////////////////////////////////
  159. void
  160. EditorOnlyObjectNodeClass::Pre_Export (void)
  161. {
  162. //
  163. // Remove ourselves from the 'system' so we don't get accidentally
  164. // saved during the export.
  165. //
  166. Add_Ref ();
  167. if (DisplayObj != NULL && m_IsInScene) {
  168. ::Get_Scene_Editor ()->Remove_Object (DisplayObj);
  169. }
  170. return ;
  171. }
  172. //////////////////////////////////////////////////////////////////////
  173. //
  174. // Post_Export
  175. //
  176. //////////////////////////////////////////////////////////////////////
  177. void
  178. EditorOnlyObjectNodeClass::Post_Export (void)
  179. {
  180. //
  181. // Put ourselves back into the system
  182. //
  183. if (DisplayObj != NULL && m_IsInScene) {
  184. ::Get_Scene_Editor ()->Add_Dynamic_Object (DisplayObj);
  185. }
  186. Release_Ref ();
  187. return ;
  188. }
  189. //////////////////////////////////////////////////////////////////////
  190. //
  191. // Add_To_Scene
  192. //
  193. //////////////////////////////////////////////////////////////////////
  194. void
  195. EditorOnlyObjectNodeClass::Add_To_Scene (void)
  196. {
  197. NodeClass::Add_To_Scene ();
  198. return ;
  199. }
  200. //////////////////////////////////////////////////////////////////////
  201. //
  202. // Remove_From_Scene
  203. //
  204. //////////////////////////////////////////////////////////////////////
  205. void
  206. EditorOnlyObjectNodeClass::Remove_From_Scene (void)
  207. {
  208. NodeClass::Remove_From_Scene ();
  209. return ;
  210. }