AudioSaveLoad.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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/WWAudio/AudioSaveLoad.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/08/01 10:41a $*
  29. * *
  30. * $Revision:: 7 $*
  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. VARID_BACKGROUND_MUSIC_NAME
  65. };
  66. ///////////////////////////////////////////////////////////////////////
  67. //
  68. // Chunk_ID
  69. //
  70. ///////////////////////////////////////////////////////////////////////
  71. uint32
  72. StaticAudioSaveLoadClass::Chunk_ID (void) const
  73. {
  74. return CHUNKID_STATIC_SAVELOAD;
  75. }
  76. ///////////////////////////////////////////////////////////////////////
  77. //
  78. // Contains_Data
  79. //
  80. ///////////////////////////////////////////////////////////////////////
  81. bool
  82. StaticAudioSaveLoadClass::Contains_Data (void) const
  83. {
  84. return true;
  85. }
  86. ///////////////////////////////////////////////////////////////////////
  87. //
  88. // Save
  89. //
  90. ///////////////////////////////////////////////////////////////////////
  91. bool
  92. StaticAudioSaveLoadClass::Save (ChunkSaveClass &csave)
  93. {
  94. WWMEMLOG(MEM_SOUND);
  95. bool retval = true;
  96. //
  97. // Save the static sounds
  98. //
  99. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  100. if (scene != NULL) {
  101. csave.Begin_Chunk (CHUNKID_STATIC_SCENE);
  102. scene->Save_Static (csave);
  103. csave.End_Chunk ();
  104. }
  105. return retval;
  106. }
  107. ///////////////////////////////////////////////////////////////////////
  108. //
  109. // Load
  110. //
  111. ///////////////////////////////////////////////////////////////////////
  112. bool
  113. StaticAudioSaveLoadClass::Load (ChunkLoadClass &cload)
  114. {
  115. WWMEMLOG(MEM_SOUND);
  116. bool retval = true;
  117. while (cload.Open_Chunk ()) {
  118. switch (cload.Cur_Chunk_ID ()) {
  119. //
  120. // Load the static scene information
  121. //
  122. case CHUNKID_STATIC_SCENE:
  123. {
  124. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  125. if (scene != NULL) {
  126. scene->Load_Static (cload);
  127. }
  128. }
  129. break;
  130. }
  131. cload.Close_Chunk ();
  132. }
  133. return retval;
  134. }
  135. //*******************************************************************//
  136. //*
  137. //* Start of DynamicAudioSaveLoadClass
  138. //*
  139. //*******************************************************************//
  140. ///////////////////////////////////////////////////////////////////////
  141. //
  142. // Chunk_ID
  143. //
  144. ///////////////////////////////////////////////////////////////////////
  145. uint32
  146. DynamicAudioSaveLoadClass::Chunk_ID (void) const
  147. {
  148. return CHUNKID_DYNAMIC_SAVELOAD;
  149. }
  150. ///////////////////////////////////////////////////////////////////////
  151. //
  152. // Contains_Data
  153. //
  154. ///////////////////////////////////////////////////////////////////////
  155. bool
  156. DynamicAudioSaveLoadClass::Contains_Data (void) const
  157. {
  158. return true;
  159. }
  160. ///////////////////////////////////////////////////////////////////////
  161. //
  162. // Save
  163. //
  164. ///////////////////////////////////////////////////////////////////////
  165. bool
  166. DynamicAudioSaveLoadClass::Save (ChunkSaveClass &csave)
  167. {
  168. bool retval = true;
  169. //
  170. // Save the static sounds
  171. //
  172. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  173. if (scene != NULL) {
  174. csave.Begin_Chunk (CHUNKID_DYNAMIC_VARIABLES);
  175. float global_scale = LogicalListenerClass::Get_Global_Scale ();
  176. StringClass filename = WWAudioClass::Get_Instance ()->Get_Background_Music_Name ();
  177. WRITE_MICRO_CHUNK (csave, VARID_LOGICAL_LISTENER_GLOBAL_SCALE, global_scale);
  178. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_BACKGROUND_MUSIC_NAME, filename);
  179. csave.End_Chunk ();
  180. csave.Begin_Chunk (CHUNKID_DYNAMIC_SCENE);
  181. scene->Save_Dynamic (csave);
  182. csave.End_Chunk ();
  183. }
  184. return retval;
  185. }
  186. ///////////////////////////////////////////////////////////////////////
  187. //
  188. // Load
  189. //
  190. ///////////////////////////////////////////////////////////////////////
  191. bool
  192. DynamicAudioSaveLoadClass::Load (ChunkLoadClass &cload)
  193. {
  194. bool retval = true;
  195. while (cload.Open_Chunk ()) {
  196. switch (cload.Cur_Chunk_ID ()) {
  197. case CHUNKID_DYNAMIC_VARIABLES:
  198. {
  199. //
  200. // Read all the variables from their micro-chunks
  201. //
  202. while (cload.Open_Micro_Chunk ()) {
  203. switch (cload.Cur_Micro_Chunk_ID ()) {
  204. //
  205. // Load the global scale for logical listeners
  206. //
  207. case VARID_LOGICAL_LISTENER_GLOBAL_SCALE:
  208. {
  209. float global_scale = 1.0F;
  210. LOAD_MICRO_CHUNK (cload, global_scale);
  211. LogicalListenerClass::Set_Global_Scale (global_scale);
  212. break;
  213. }
  214. //
  215. // Load the background music name
  216. //
  217. case VARID_BACKGROUND_MUSIC_NAME:
  218. {
  219. StringClass filename;
  220. LOAD_MICRO_CHUNK_WWSTRING (cload, filename);
  221. WWAudioClass::Get_Instance ()->Set_Background_Music (filename);
  222. break;
  223. }
  224. }
  225. cload.Close_Micro_Chunk ();
  226. }
  227. }
  228. break;
  229. //
  230. // Load the static scene information
  231. //
  232. case CHUNKID_DYNAMIC_SCENE:
  233. {
  234. SoundSceneClass *scene = WWAudioClass::Get_Instance ()->Get_Sound_Scene ();
  235. if (scene != NULL) {
  236. scene->Load_Dynamic (cload);
  237. }
  238. }
  239. break;
  240. }
  241. cload.Close_Chunk ();
  242. }
  243. return retval;
  244. }