TerrainDefinition.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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/TerrainDefinition.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/19/00 2:20p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "terraindefinition.h"
  37. #include "simpledefinitionfactory.h"
  38. #include "definitionclassids.h"
  39. #include "definitionmgr.h"
  40. #include "persistfactory.h"
  41. #include "editorchunkids.h"
  42. #include "terrainnode.h"
  43. //////////////////////////////////////////////////////////////////////////////////
  44. // Constants
  45. //////////////////////////////////////////////////////////////////////////////////
  46. enum
  47. {
  48. CHUNKID_VARIABLES = 0x00000100,
  49. CHUNKID_BASE_CLASS = 0x00000200,
  50. };
  51. enum
  52. {
  53. VARID_LOD_DIST = 0x01,
  54. VARID_MODEL_NAME,
  55. VARID_LIGHT_FILENAME
  56. };
  57. //////////////////////////////////////////////////////////////////////////////////
  58. //
  59. // Static factories
  60. //
  61. //////////////////////////////////////////////////////////////////////////////////
  62. DECLARE_DEFINITION_FACTORY(TerrainDefinitionClass, CLASSID_TERRAIN, "Terrain") _TerrainDefFactory;
  63. SimplePersistFactoryClass<TerrainDefinitionClass, CHUNKID_TERRAIN_DEF> _TerrainPersistFactory;
  64. //////////////////////////////////////////////////////////////////////////////////
  65. //
  66. // TerrainDefinitionClass
  67. //
  68. //////////////////////////////////////////////////////////////////////////////////
  69. TerrainDefinitionClass::TerrainDefinitionClass (void)
  70. : DefinitionClass ()
  71. {
  72. FILENAME_PARAM (TerrainDefinitionClass, m_ModelName, "Westwood 3D Files", ".w3d");
  73. FILENAME_PARAM (TerrainDefinitionClass, m_LightFilename, "Westwood Light Database", ".wlt");
  74. return ;
  75. }
  76. //////////////////////////////////////////////////////////////////////////////////
  77. //
  78. // ~TerrainDefinitionClass
  79. //
  80. //////////////////////////////////////////////////////////////////////////////////
  81. TerrainDefinitionClass::~TerrainDefinitionClass (void)
  82. {
  83. return ;
  84. }
  85. //////////////////////////////////////////////////////////////////////////////////
  86. //
  87. // Get_Factory
  88. //
  89. //////////////////////////////////////////////////////////////////////////////////
  90. const PersistFactoryClass &
  91. TerrainDefinitionClass::Get_Factory (void) const
  92. {
  93. return _TerrainPersistFactory;
  94. }
  95. //////////////////////////////////////////////////////////////////////////////////
  96. //
  97. // Save
  98. //
  99. //////////////////////////////////////////////////////////////////////////////////
  100. bool
  101. TerrainDefinitionClass::Save (ChunkSaveClass &csave)
  102. {
  103. bool retval = true;
  104. csave.Begin_Chunk (CHUNKID_VARIABLES);
  105. retval &= Save_Variables (csave);
  106. csave.End_Chunk ();
  107. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  108. retval &= DefinitionClass::Save (csave);
  109. csave.End_Chunk ();
  110. return retval;
  111. }
  112. //////////////////////////////////////////////////////////////////////////////////
  113. //
  114. // Load
  115. //
  116. //////////////////////////////////////////////////////////////////////////////////
  117. bool
  118. TerrainDefinitionClass::Load (ChunkLoadClass &cload)
  119. {
  120. bool retval = true;
  121. while (cload.Open_Chunk ()) {
  122. switch (cload.Cur_Chunk_ID ()) {
  123. case CHUNKID_VARIABLES:
  124. retval &= Load_Variables (cload);
  125. break;
  126. case CHUNKID_BASE_CLASS:
  127. retval &= DefinitionClass::Load (cload);
  128. break;
  129. }
  130. cload.Close_Chunk ();
  131. }
  132. return retval;
  133. }
  134. //////////////////////////////////////////////////////////////////////////////////
  135. //
  136. // Save_Variables
  137. //
  138. //////////////////////////////////////////////////////////////////////////////////
  139. bool
  140. TerrainDefinitionClass::Save_Variables (ChunkSaveClass &csave)
  141. {
  142. bool retval = true;
  143. //
  144. // Write the list of distances to the chunk
  145. //
  146. for (int index = 0; index < m_DistanceList.Count (); index ++) {
  147. uint32 distance = m_DistanceList[index];
  148. //
  149. // Create a new micro-chunk and write this data out to it.
  150. //
  151. csave.Begin_Micro_Chunk (VARID_LOD_DIST);
  152. retval &= (csave.Write (&distance, sizeof (distance)) == sizeof (distance));
  153. csave.End_Micro_Chunk ();
  154. }
  155. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_MODEL_NAME, m_ModelName)
  156. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_LIGHT_FILENAME, m_LightFilename)
  157. return retval;
  158. }
  159. //////////////////////////////////////////////////////////////////////////////////
  160. //
  161. // Load_Variables
  162. //
  163. //////////////////////////////////////////////////////////////////////////////////
  164. bool
  165. TerrainDefinitionClass::Load_Variables (ChunkLoadClass &cload)
  166. {
  167. bool retval = true;
  168. // Start fresh
  169. m_DistanceList.Delete_All ();
  170. //
  171. // Loop through all the microchunks that define the variables
  172. //
  173. while (cload.Open_Micro_Chunk ()) {
  174. switch (cload.Cur_Micro_Chunk_ID ()) {
  175. case VARID_LOD_DIST:
  176. {
  177. uint32 distance = 0;
  178. retval &= (cload.Read (&distance, sizeof (distance)) == sizeof (distance));
  179. m_DistanceList.Add (distance);
  180. }
  181. break;
  182. READ_MICRO_CHUNK_WWSTRING (cload, VARID_MODEL_NAME, m_ModelName)
  183. READ_MICRO_CHUNK_WWSTRING (cload, VARID_LIGHT_FILENAME, m_LightFilename)
  184. }
  185. cload.Close_Micro_Chunk ();
  186. }
  187. return retval;
  188. }
  189. //////////////////////////////////////////////////////////////////////////////////
  190. //
  191. // Create
  192. //
  193. //////////////////////////////////////////////////////////////////////////////////
  194. PersistClass *
  195. TerrainDefinitionClass::Create (void) const
  196. {
  197. return new TerrainNodeClass ();
  198. }