AudioSaveLoad.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. ** Command & Conquer Generals(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/WWAudio/AudioSaveLoad.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 8/14/01 11:46a $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "always.h"
  36. #include "audiosaveload.h"
  37. #include "persist.h"
  38. #include "persistfactory.h"
  39. #include "definition.h"
  40. #include "soundchunkids.h"
  41. #include "chunkio.h"
  42. #include "SoundScene.h"
  43. #include "wwmemlog.h"
  44. ///////////////////////////////////////////////////////////////////////
  45. // Global singleton instance
  46. ///////////////////////////////////////////////////////////////////////
  47. StaticAudioSaveLoadClass _StaticAudioSaveLoadSubsystem;
  48. DynamicAudioSaveLoadClass _DynamicAudioSaveLoadSubsystem;
  49. ///////////////////////////////////////////////////////////////////////
  50. // Constants
  51. ///////////////////////////////////////////////////////////////////////
  52. enum
  53. {
  54. CHUNKID_STATIC_SCENE = 0x10291220,
  55. CHUNKID_DYNAMIC_SCENE,
  56. CHUNKID_DYNAMIC_VARIABLES
  57. };
  58. enum
  59. {
  60. VARID_INCLUDE_FILE = 0x01,
  61. VARID_CAMERA_TM,
  62. VARID_BACK_COLOR,
  63. VARID_LOGICAL_LISTENER_GLOBAL_SCALE
  64. };
  65. ///////////////////////////////////////////////////////////////////////
  66. //
  67. // Chunk_ID
  68. //
  69. ///////////////////////////////////////////////////////////////////////
  70. uint32
  71. StaticAudioSaveLoadClass::Chunk_ID (void) const
  72. {
  73. return CHUNKID_STATIC_SAVELOAD;
  74. }
  75. ///////////////////////////////////////////////////////////////////////
  76. //
  77. // Contains_Data
  78. //
  79. ///////////////////////////////////////////////////////////////////////
  80. bool
  81. StaticAudioSaveLoadClass::Contains_Data (void) const
  82. {
  83. return true;
  84. }
  85. ///////////////////////////////////////////////////////////////////////
  86. //
  87. // Save
  88. //
  89. ///////////////////////////////////////////////////////////////////////
  90. bool
  91. StaticAudioSaveLoadClass::Save (ChunkSaveClass &csave)
  92. {
  93. WWMEMLOG(MEM_SOUND);
  94. bool retval = true;
  95. //
  96. // Save the static sounds
  97. //
  98. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  99. if (scene != NULL) {
  100. csave.Begin_Chunk (CHUNKID_STATIC_SCENE);
  101. scene->Save_Static (csave);
  102. csave.End_Chunk ();
  103. }
  104. return retval;
  105. }
  106. ///////////////////////////////////////////////////////////////////////
  107. //
  108. // Load
  109. //
  110. ///////////////////////////////////////////////////////////////////////
  111. bool
  112. StaticAudioSaveLoadClass::Load (ChunkLoadClass &cload)
  113. {
  114. WWMEMLOG(MEM_SOUND);
  115. bool retval = true;
  116. while (cload.Open_Chunk ()) {
  117. switch (cload.Cur_Chunk_ID ()) {
  118. //
  119. // Load the static scene information
  120. //
  121. case CHUNKID_STATIC_SCENE:
  122. {
  123. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  124. if (scene != NULL) {
  125. scene->Load_Static (cload);
  126. }
  127. }
  128. break;
  129. }
  130. cload.Close_Chunk ();
  131. }
  132. return retval;
  133. }
  134. //*******************************************************************//
  135. //*
  136. //* Start of DynamicAudioSaveLoadClass
  137. //*
  138. //*******************************************************************//
  139. ///////////////////////////////////////////////////////////////////////
  140. //
  141. // Chunk_ID
  142. //
  143. ///////////////////////////////////////////////////////////////////////
  144. uint32
  145. DynamicAudioSaveLoadClass::Chunk_ID (void) const
  146. {
  147. return CHUNKID_DYNAMIC_SAVELOAD;
  148. }
  149. ///////////////////////////////////////////////////////////////////////
  150. //
  151. // Contains_Data
  152. //
  153. ///////////////////////////////////////////////////////////////////////
  154. bool
  155. DynamicAudioSaveLoadClass::Contains_Data (void) const
  156. {
  157. return true;
  158. }
  159. ///////////////////////////////////////////////////////////////////////
  160. //
  161. // Save
  162. //
  163. ///////////////////////////////////////////////////////////////////////
  164. bool
  165. DynamicAudioSaveLoadClass::Save (ChunkSaveClass &csave)
  166. {
  167. bool retval = true;
  168. //
  169. // Save the static sounds
  170. //
  171. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  172. if (scene != NULL) {
  173. csave.Begin_Chunk (CHUNKID_DYNAMIC_VARIABLES);
  174. float global_scale = LogicalListenerClass::Get_Global_Scale ();
  175. WRITE_MICRO_CHUNK (csave, VARID_LOGICAL_LISTENER_GLOBAL_SCALE, global_scale);
  176. csave.End_Chunk ();
  177. csave.Begin_Chunk (CHUNKID_DYNAMIC_SCENE);
  178. scene->Save_Dynamic (csave);
  179. csave.End_Chunk ();
  180. }
  181. return retval;
  182. }
  183. ///////////////////////////////////////////////////////////////////////
  184. //
  185. // Load
  186. //
  187. ///////////////////////////////////////////////////////////////////////
  188. bool
  189. DynamicAudioSaveLoadClass::Load (ChunkLoadClass &cload)
  190. {
  191. bool retval = true;
  192. while (cload.Open_Chunk ()) {
  193. switch (cload.Cur_Chunk_ID ()) {
  194. case CHUNKID_DYNAMIC_VARIABLES:
  195. {
  196. //
  197. // Read all the variables from their micro-chunks
  198. //
  199. while (cload.Open_Micro_Chunk ()) {
  200. switch (cload.Cur_Micro_Chunk_ID ()) {
  201. //
  202. // Load the global scale for logical listeners
  203. //
  204. case VARID_LOGICAL_LISTENER_GLOBAL_SCALE:
  205. {
  206. float global_scale = 1.0F;
  207. LOAD_MICRO_CHUNK (cload, global_scale);
  208. LogicalListenerClass::Set_Global_Scale (global_scale);
  209. break;
  210. }
  211. }
  212. cload.Close_Micro_Chunk ();
  213. }
  214. }
  215. break;
  216. //
  217. // Load the static scene information
  218. //
  219. case CHUNKID_DYNAMIC_SCENE:
  220. {
  221. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  222. if (scene != NULL) {
  223. scene->Load_Dynamic (cload);
  224. }
  225. }
  226. break;
  227. }
  228. cload.Close_Chunk ();
  229. }
  230. return retval;
  231. }