TransitionNode.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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/TransitionNode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 5/22/01 11:17a $*
  29. * *
  30. * $Revision:: 12 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "transitionnode.h"
  37. #include "sceneeditor.h"
  38. #include "filemgr.h"
  39. #include "_assetmgr.h"
  40. #include "editorassetmgr.h"
  41. #include "w3d_file.h"
  42. #include "cameramgr.h"
  43. #include "collisiongroups.h"
  44. #include "persistfactory.h"
  45. #include "editorchunkids.h"
  46. #include "preset.h"
  47. #include "spawn.h"
  48. #include "physicalgameobj.h"
  49. #include "presetmgr.h"
  50. #include "decophys.h"
  51. #include "nodemgr.h"
  52. #include "modelutils.h"
  53. //////////////////////////////////////////////////////////////////////////////
  54. // Persist factory
  55. //////////////////////////////////////////////////////////////////////////////
  56. SimplePersistFactoryClass<TransitionNodeClass, CHUNKID_NODE_TRANSITION> _TransitionNodePersistFactory;
  57. //////////////////////////////////////////////////////////////////////////////
  58. //
  59. // TransitionNodeClass
  60. //
  61. //////////////////////////////////////////////////////////////////////////////
  62. TransitionNodeClass::TransitionNodeClass (PresetClass *preset)
  63. : m_PhysObj (NULL),
  64. m_TransitionObj (NULL),
  65. NodeClass (preset)
  66. {
  67. return ;
  68. }
  69. //////////////////////////////////////////////////////////////////////////////
  70. //
  71. // TransitionNodeClass
  72. //
  73. //////////////////////////////////////////////////////////////////////////////
  74. TransitionNodeClass::TransitionNodeClass (const TransitionNodeClass &src)
  75. : m_PhysObj (NULL),
  76. m_TransitionObj (NULL),
  77. NodeClass (NULL)
  78. {
  79. *this = src;
  80. return ;
  81. }
  82. //////////////////////////////////////////////////////////////////////////////
  83. //
  84. // ~TransitionNodeClass
  85. //
  86. //////////////////////////////////////////////////////////////////////////////
  87. TransitionNodeClass::~TransitionNodeClass (void)
  88. {
  89. Remove_From_Scene ();
  90. MEMBER_RELEASE (m_PhysObj);
  91. if (m_TransitionObj != NULL) {
  92. m_TransitionObj->Set_Delete_Pending ();
  93. m_TransitionObj = NULL;
  94. }
  95. return ;
  96. }
  97. //////////////////////////////////////////////////////////////////////////////
  98. //
  99. // Initialize
  100. //
  101. // Note: This may be called more than once. It is used as an 'initialize'
  102. // and a 're-initialize'.
  103. //
  104. //////////////////////////////////////////////////////////////////////////////
  105. void
  106. TransitionNodeClass::Initialize (void)
  107. {
  108. if (m_TransitionObj != NULL) {
  109. m_TransitionObj->Set_Delete_Pending ();
  110. m_TransitionObj = NULL;
  111. }
  112. MEMBER_RELEASE (m_PhysObj);
  113. TransitionGameObjDef *definition = static_cast<TransitionGameObjDef *> (m_Preset->Get_Definition ());
  114. if (definition != NULL) {
  115. // Create the transition object
  116. m_TransitionObj = (TransitionGameObj *)definition->Create ();
  117. // Create the new physics object
  118. m_PhysObj = new DecorationPhysClass;
  119. //
  120. // Configure the physics object with information about
  121. // its new render object and collision data.
  122. //
  123. m_PhysObj->Set_Model_By_Name ("TRANSBOX");
  124. m_PhysObj->Set_Transform (Matrix3D(1));
  125. m_PhysObj->Set_Collision_Group (EDITOR_COLLISION_GROUP);
  126. m_PhysObj->Peek_Model ()->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  127. ::Set_Model_Collision_Type (m_PhysObj->Peek_Model (), COLLISION_TYPE_6);
  128. Set_Transform (m_Transform);
  129. //
  130. // Remove the transitions from the level if the transition
  131. // object is not in the scene
  132. //
  133. if (m_IsInScene == false) {
  134. m_TransitionObj->Destroy_Transitions ();
  135. }
  136. }
  137. return ;
  138. }
  139. ////////////////////////////////////////////////////////////////
  140. //
  141. // Get_Factory
  142. //
  143. ////////////////////////////////////////////////////////////////
  144. const PersistFactoryClass &
  145. TransitionNodeClass::Get_Factory (void) const
  146. {
  147. return _TransitionNodePersistFactory;
  148. }
  149. /////////////////////////////////////////////////////////////////
  150. //
  151. // operator=
  152. //
  153. /////////////////////////////////////////////////////////////////
  154. const TransitionNodeClass &
  155. TransitionNodeClass::operator= (const TransitionNodeClass &src)
  156. {
  157. NodeClass::operator= (src);
  158. return *this;
  159. }
  160. //////////////////////////////////////////////////////////////////////
  161. //
  162. // Pre_Export
  163. //
  164. //////////////////////////////////////////////////////////////////////
  165. void
  166. TransitionNodeClass::Pre_Export (void)
  167. {
  168. //
  169. // Remove ourselves from the 'system' so we don't get accidentally
  170. // saved during the export.
  171. //
  172. Add_Ref ();
  173. if (m_PhysObj != NULL && m_IsInScene) {
  174. ::Get_Scene_Editor ()->Remove_Object (m_PhysObj);
  175. }
  176. return ;
  177. }
  178. //////////////////////////////////////////////////////////////////////
  179. //
  180. // Post_Export
  181. //
  182. //////////////////////////////////////////////////////////////////////
  183. void
  184. TransitionNodeClass::Post_Export (void)
  185. {
  186. //
  187. // Put ourselves back into the system
  188. //
  189. if (m_PhysObj != NULL && m_IsInScene) {
  190. ::Get_Scene_Editor ()->Add_Dynamic_Object (m_PhysObj);
  191. }
  192. Release_Ref ();
  193. return ;
  194. }
  195. //////////////////////////////////////////////////////////////////////
  196. //
  197. // Add_To_Scene
  198. //
  199. //////////////////////////////////////////////////////////////////////
  200. void
  201. TransitionNodeClass::Add_To_Scene (void)
  202. {
  203. if (m_TransitionObj != NULL) {
  204. m_TransitionObj->Create_Transitions ();
  205. }
  206. NodeClass::Add_To_Scene ();
  207. return ;
  208. }
  209. //////////////////////////////////////////////////////////////////////
  210. //
  211. // Remove_From_Scene
  212. //
  213. //////////////////////////////////////////////////////////////////////
  214. void
  215. TransitionNodeClass::Remove_From_Scene (void)
  216. {
  217. if (m_TransitionObj != NULL) {
  218. m_TransitionObj->Destroy_Transitions ();
  219. }
  220. NodeClass::Remove_From_Scene ();
  221. return ;
  222. }
  223. //////////////////////////////////////////////////////////////////////
  224. //
  225. // Find_Transition
  226. //
  227. //////////////////////////////////////////////////////////////////////
  228. int
  229. TransitionNodeClass::Find_Transition (TransitionDataClass::StyleType type)
  230. {
  231. int index = -1;
  232. int count = Get_Transition_Count ();
  233. for ( int trans_index = 0;
  234. (index == -1) && (trans_index < count);
  235. trans_index ++)
  236. {
  237. //
  238. // Is this the type transition we are looking for?
  239. //
  240. TransitionInstanceClass *transition = Get_Transition (trans_index);
  241. if (transition != NULL && transition->Get_Type () == type) {
  242. index = trans_index;
  243. }
  244. }
  245. return index;
  246. }