heightfieldmgr.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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/heightfieldmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 3/07/02 1:53p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "heightfieldmgr.h"
  37. #include "heightfieldeditor.h"
  38. #include "editableheightfield.h"
  39. #include "chunkio.h"
  40. #include "saveload.h"
  41. #include "staticphys.h"
  42. #include "sceneeditor.h"
  43. #include "utils.h"
  44. #include "nodemgr.h"
  45. ///////////////////////////////////////////////////////////////////////
  46. // Global singleton instance
  47. ///////////////////////////////////////////////////////////////////////
  48. HeightfieldMgrClass _TheHeightfieldMgrSaveLoadSubsystem;
  49. ////////////////////////////////////////////////////////////////
  50. // Local constants
  51. ////////////////////////////////////////////////////////////////
  52. enum
  53. {
  54. CHUNKID_VARIABLES = 0x02261012,
  55. CHUNKID_HEIGHTFIELD
  56. };
  57. enum
  58. {
  59. VARID_TEXTURE_NAME = 0x01,
  60. VARID_CENTER_POINT,
  61. VARID_SCALE,
  62. VARID_MAP_TITLE_ID,
  63. VARID_IS_PLAYER_MARKDER_VISIBLE,
  64. VARID_ENABLE_VTOL
  65. };
  66. ///////////////////////////////////////////////////////////////////////
  67. // Static member initialization
  68. ///////////////////////////////////////////////////////////////////////
  69. DynamicVectorClass<EditableHeightfieldClass *> HeightfieldMgrClass::HeightfieldList;
  70. //////////////////////////////////////////////////////////////////////
  71. //
  72. // Initialize
  73. //
  74. //////////////////////////////////////////////////////////////////////
  75. void
  76. HeightfieldMgrClass::Initialize (void)
  77. {
  78. return ;
  79. }
  80. //////////////////////////////////////////////////////////////////////
  81. //
  82. // Shutdown
  83. //
  84. //////////////////////////////////////////////////////////////////////
  85. void
  86. HeightfieldMgrClass::Shutdown (void)
  87. {
  88. //
  89. // Release each heightfield in our list
  90. //
  91. for (int index = 0; index < HeightfieldList.Count (); index ++) {
  92. delete HeightfieldList[index];
  93. }
  94. HeightfieldList.Delete_All ();
  95. return ;
  96. }
  97. ////////////////////////////////////////////////////////////////
  98. //
  99. // Save
  100. //
  101. ////////////////////////////////////////////////////////////////
  102. bool
  103. HeightfieldMgrClass::Save (ChunkSaveClass &csave)
  104. {
  105. //
  106. // Write the variables
  107. //
  108. csave.Begin_Chunk (CHUNKID_VARIABLES);
  109. csave.End_Chunk ();
  110. //
  111. // Save each heightfield to its own chunk
  112. //
  113. for (int index = 0; index < HeightfieldList.Count (); index ++) {
  114. csave.Begin_Chunk (CHUNKID_HEIGHTFIELD);
  115. HeightfieldList[index]->Save (csave);
  116. csave.End_Chunk ();
  117. }
  118. return true;
  119. }
  120. ////////////////////////////////////////////////////////////////
  121. //
  122. // Load
  123. //
  124. ////////////////////////////////////////////////////////////////
  125. bool
  126. HeightfieldMgrClass::Load (ChunkLoadClass &cload)
  127. {
  128. while (cload.Open_Chunk ()) {
  129. switch (cload.Cur_Chunk_ID ()) {
  130. //
  131. // Load all the variables from this chunk
  132. //
  133. case CHUNKID_VARIABLES:
  134. Load_Variables (cload);
  135. break;
  136. case CHUNKID_HEIGHTFIELD:
  137. {
  138. //
  139. // Load this heightfield from disk
  140. //
  141. EditableHeightfieldClass *heightfield = new EditableHeightfieldClass;
  142. heightfield->Load (cload);
  143. //
  144. // Add this heightfield to our list
  145. //
  146. HeightfieldList.Add (heightfield);
  147. break;
  148. }
  149. }
  150. cload.Close_Chunk ();
  151. }
  152. //
  153. // Start editing the first heightfield in the list
  154. //
  155. if (HeightfieldList.Count () > 0) {
  156. HeightfieldEditorClass::Load_Materials (HeightfieldList[0]);
  157. }
  158. return true;
  159. }
  160. ////////////////////////////////////////////////////////////////
  161. //
  162. // Load_Variables
  163. //
  164. ////////////////////////////////////////////////////////////////
  165. void
  166. HeightfieldMgrClass::Load_Variables (ChunkLoadClass &cload)
  167. {
  168. /*while (cload.Open_Micro_Chunk ()) {
  169. switch (cload.Cur_Micro_Chunk_ID ()) {
  170. }
  171. cload.Close_Micro_Chunk ();
  172. }*/
  173. SaveLoadSystemClass::Register_Post_Load_Callback (this);
  174. return ;
  175. }
  176. ///////////////////////////////////////////////////////////////////////
  177. //
  178. // On_Post_Load
  179. //
  180. ///////////////////////////////////////////////////////////////////////
  181. void
  182. HeightfieldMgrClass::On_Post_Load (void)
  183. {
  184. //
  185. // Let each heightfield post-load
  186. //
  187. for (int index = 0; index < HeightfieldList.Count (); index ++) {
  188. HeightfieldList[index]->On_Post_Load ();
  189. }
  190. return ;
  191. }
  192. ///////////////////////////////////////////////////////////////////////
  193. //
  194. // Assign_Unique_IDs
  195. //
  196. ///////////////////////////////////////////////////////////////////////
  197. void
  198. HeightfieldMgrClass::Assign_Unique_IDs (void)
  199. {
  200. //
  201. // Ask each heightfield to update its IDs
  202. //
  203. for (int index = 0; index < HeightfieldList.Count (); index ++) {
  204. HeightfieldList[index]->Assign_Unique_IDs ();
  205. }
  206. return ;
  207. }
  208. ///////////////////////////////////////////////////////////////////////
  209. //
  210. // Create_Heightfield
  211. //
  212. ///////////////////////////////////////////////////////////////////////
  213. EditableHeightfieldClass *
  214. HeightfieldMgrClass::Create_Heightfield (float width, float height, float density)
  215. {
  216. //
  217. // Create a new heightfield and add it to our list
  218. //
  219. EditableHeightfieldClass *heightfield = new EditableHeightfieldClass;
  220. heightfield->Set_Dimensions (width, height, density);
  221. //
  222. // Add these objects to our lists
  223. //
  224. HeightfieldList.Add (heightfield);
  225. //
  226. // Set this heightfield as the current heightfield
  227. //
  228. HeightfieldEditorClass::Set_Current_Heightfield (heightfield);
  229. return heightfield;
  230. }
  231. ///////////////////////////////////////////////////////////////////////
  232. //
  233. // Create_Heightfield
  234. //
  235. ///////////////////////////////////////////////////////////////////////
  236. EditableHeightfieldClass *
  237. HeightfieldMgrClass::Create_Heightfield
  238. (
  239. const char * heightmap_filename,
  240. float width,
  241. float height,
  242. float density,
  243. float scale
  244. )
  245. {
  246. //
  247. // Create a new heightfield and add it to our list
  248. //
  249. EditableHeightfieldClass *heightfield = new EditableHeightfieldClass;
  250. heightfield->Create (heightmap_filename, width, height, density, scale);
  251. //
  252. // Add these objects to our lists
  253. //
  254. HeightfieldList.Add (heightfield);
  255. //
  256. // Set this heightfield as the current heightfield
  257. //
  258. HeightfieldEditorClass::Set_Current_Heightfield (heightfield);
  259. return heightfield;
  260. }