TileNode.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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/TileNode.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/09/01 10:39a $*
  29. * *
  30. * $Revision:: 23 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "tilenode.h"
  37. #include "staticphys.h"
  38. #include "sceneeditor.h"
  39. #include "tiledefinition.h"
  40. #include "filemgr.h"
  41. #include "_assetmgr.h"
  42. #include "editorassetmgr.h"
  43. #include "w3d_file.h"
  44. #include "cameramgr.h"
  45. #include "collisiongroups.h"
  46. #include "persistfactory.h"
  47. #include "editorchunkids.h"
  48. #include "preset.h"
  49. //////////////////////////////////////////////////////////////////////////////
  50. // Persist factory
  51. //////////////////////////////////////////////////////////////////////////////
  52. SimplePersistFactoryClass<TileNodeClass, CHUNKID_NODE_TILE> _TileNodePersistFactory;
  53. enum
  54. {
  55. CHUNKID_VARIABLES = 0x05050253,
  56. CHUNKID_BASE_CLASS,
  57. };
  58. enum
  59. {
  60. VARID_VISOBJECTID = 0x01,
  61. VARID_VISSECTORID
  62. };
  63. //////////////////////////////////////////////////////////////////////////////
  64. //
  65. // TileNodeClass
  66. //
  67. //////////////////////////////////////////////////////////////////////////////
  68. TileNodeClass::TileNodeClass (PresetClass *preset)
  69. : m_PhysObj (NULL),
  70. m_VisObjectID (0), // (gth) init this to zero, ("always visible")
  71. m_VisSectorID (-1), // (gth) init this to -1, ("no-sector")
  72. NodeClass (preset)
  73. {
  74. Restrict_Rotation (true);
  75. return ;
  76. }
  77. //////////////////////////////////////////////////////////////////////////////
  78. //
  79. // TileNodeClass
  80. //
  81. //////////////////////////////////////////////////////////////////////////////
  82. TileNodeClass::TileNodeClass (const TileNodeClass &src)
  83. : m_PhysObj (NULL),
  84. m_VisObjectID (0),
  85. m_VisSectorID (-1),
  86. NodeClass (NULL)
  87. {
  88. Restrict_Rotation (true);
  89. (*this) = src;
  90. return ;
  91. }
  92. //////////////////////////////////////////////////////////////////////////////
  93. //
  94. // ~TileNodeClass
  95. //
  96. //////////////////////////////////////////////////////////////////////////////
  97. TileNodeClass::~TileNodeClass (void)
  98. {
  99. Remove_From_Scene ();
  100. MEMBER_RELEASE (m_PhysObj);
  101. return ;
  102. }
  103. //////////////////////////////////////////////////////////////////////////////
  104. //
  105. // Initialize
  106. //
  107. // Note: This may be called more than once. It is used as an 'initialize'
  108. // and a 're-initialize'.
  109. //
  110. //////////////////////////////////////////////////////////////////////////////
  111. void
  112. TileNodeClass::Initialize (void)
  113. {
  114. //
  115. // Update the cull-link index
  116. //
  117. Update_Cached_Cull_Link ();
  118. MEMBER_RELEASE (m_PhysObj);
  119. TileDefinitionClass *definition = static_cast<TileDefinitionClass *> (m_Preset->Get_Definition ());
  120. if (definition != NULL) {
  121. //
  122. // Make sure all assets are loaded into memory before this tile is created...
  123. //
  124. m_Preset->Load_All_Assets ();
  125. //
  126. // Lookup the physics definition this tile definition was configured with
  127. //
  128. int def_id = definition->Get_Phys_Def_ID ();
  129. DefinitionClass *phys_def = DefinitionMgrClass::Find_Definition (def_id, false);
  130. if (phys_def != NULL) {
  131. //
  132. // Create an instance of the physics object from its definition
  133. //
  134. PhysClass *phys_obj = (PhysClass *)phys_def->Create ();
  135. ASSERT (phys_obj != NULL);
  136. if (phys_obj != NULL && phys_obj->Peek_Model () != NULL) {
  137. m_PhysObj = phys_obj->As_StaticPhysClass ();
  138. ASSERT (m_PhysObj != NULL);
  139. ASSERT (m_PhysObj->Peek_Model() != NULL);
  140. //
  141. // Configure the physics object
  142. //
  143. if (m_PhysObj != NULL) {
  144. m_PhysObj->Peek_Model ()->Set_User_Data ((PVOID)&m_HitTestInfo, FALSE);
  145. m_PhysObj->Set_Transform (m_Transform);
  146. m_PhysObj->Set_Collision_Group (GAME_COLLISION_GROUP);
  147. m_PhysObj->Set_ID (Get_ID ());
  148. m_PhysObj->Set_Vis_Object_ID (m_VisObjectID);
  149. m_PhysObj->Set_Vis_Sector_ID (m_VisSectorID);
  150. }
  151. } else {
  152. MEMBER_RELEASE (phys_obj);
  153. }
  154. }
  155. }
  156. return ;
  157. }
  158. ////////////////////////////////////////////////////////////////
  159. //
  160. // Get_Factory
  161. //
  162. ////////////////////////////////////////////////////////////////
  163. const PersistFactoryClass &
  164. TileNodeClass::Get_Factory (void) const
  165. {
  166. return _TileNodePersistFactory;
  167. }
  168. /////////////////////////////////////////////////////////////////
  169. //
  170. // operator=
  171. //
  172. /////////////////////////////////////////////////////////////////
  173. const TileNodeClass &
  174. TileNodeClass::operator= (const TileNodeClass &src)
  175. {
  176. NodeClass::operator= (src);
  177. return *this;
  178. }
  179. /////////////////////////////////////////////////////////////////
  180. //
  181. // Save
  182. //
  183. /////////////////////////////////////////////////////////////////
  184. bool
  185. TileNodeClass::Save (ChunkSaveClass &csave)
  186. {
  187. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  188. NodeClass::Save (csave);
  189. csave.End_Chunk ();
  190. csave.Begin_Chunk (CHUNKID_VARIABLES);
  191. //
  192. // Save the tile's vis-id to the chunk
  193. //
  194. if (m_PhysObj != NULL) {
  195. uint32 vis_id = ((StaticPhysClass *)m_PhysObj)->Get_Vis_Object_ID ();
  196. WRITE_MICRO_CHUNK (csave, VARID_VISOBJECTID, vis_id);
  197. vis_id = ((StaticPhysClass *)m_PhysObj)->Get_Vis_Sector_ID ();
  198. WRITE_MICRO_CHUNK (csave, VARID_VISSECTORID, vis_id);
  199. }
  200. csave.End_Chunk ();
  201. return true;
  202. }
  203. /////////////////////////////////////////////////////////////////
  204. //
  205. // Load
  206. //
  207. /////////////////////////////////////////////////////////////////
  208. bool
  209. TileNodeClass::Load (ChunkLoadClass &cload)
  210. {
  211. while (cload.Open_Chunk ()) {
  212. switch (cload.Cur_Chunk_ID ()) {
  213. case CHUNKID_BASE_CLASS:
  214. NodeClass::Load (cload);
  215. break;
  216. case CHUNKID_VARIABLES:
  217. Load_Variables (cload);
  218. break;
  219. }
  220. cload.Close_Chunk ();
  221. }
  222. return true;
  223. }
  224. /////////////////////////////////////////////////////////////////
  225. //
  226. // Load_Variables
  227. //
  228. /////////////////////////////////////////////////////////////////
  229. bool
  230. TileNodeClass::Load_Variables (ChunkLoadClass &cload)
  231. {
  232. while (cload.Open_Micro_Chunk ()) {
  233. switch (cload.Cur_Micro_Chunk_ID ()) {
  234. READ_MICRO_CHUNK (cload, VARID_VISOBJECTID, m_VisObjectID);
  235. READ_MICRO_CHUNK (cload, VARID_VISSECTORID, m_VisSectorID);
  236. }
  237. cload.Close_Micro_Chunk ();
  238. }
  239. return true;
  240. }
  241. /////////////////////////////////////////////////////////////////
  242. //
  243. // Update_Cached_Vis_IDs
  244. //
  245. /////////////////////////////////////////////////////////////////
  246. void
  247. TileNodeClass::Update_Cached_Vis_IDs (void)
  248. {
  249. if (m_PhysObj != NULL) {
  250. m_VisObjectID = m_PhysObj->Get_Vis_Object_ID ();
  251. m_VisSectorID = m_PhysObj->Get_Vis_Object_ID ();
  252. }
  253. return ;
  254. }
  255. //////////////////////////////////////////////////////////////////////
  256. //
  257. // Pre_Export
  258. //
  259. //////////////////////////////////////////////////////////////////////
  260. void
  261. TileNodeClass::Pre_Export (void)
  262. {
  263. //
  264. // Change our collision group the collision group that the
  265. // game is expecting
  266. //
  267. if (m_PhysObj != NULL) {
  268. m_PhysObj->Set_Collision_Group (15);
  269. }
  270. return ;
  271. }
  272. //////////////////////////////////////////////////////////////////////
  273. //
  274. // Post_Export
  275. //
  276. //////////////////////////////////////////////////////////////////////
  277. void
  278. TileNodeClass::Post_Export (void)
  279. {
  280. //
  281. // Restore our collision group
  282. //
  283. if (m_PhysObj != NULL) {
  284. m_PhysObj->Set_Collision_Group (GAME_COLLISION_GROUP);
  285. }
  286. return ;
  287. }