SoundScene.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 : WWAudio *
  23. * *
  24. * $Archive:: /Commando/Code/WWAudio/SoundScene.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/07/01 6:10p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __SOUNDSCENE_H
  39. #define __SOUNDSCENE_H
  40. #include "aabtreecull.h"
  41. #include "gridcull.h"
  42. #include "listener.h"
  43. #include "vector.h"
  44. #include "priorityvector.h"
  45. #include "soundcullobj.h"
  46. #include "logicallistener.h"
  47. #include "multilist.h"
  48. // Forward declarations
  49. class RenderObjClass;
  50. class ChunkSaveClass;
  51. class ChunkLoadClass;
  52. //////////////////////////////////////////////////////////////////////////////////
  53. //
  54. // Typedefs
  55. //
  56. //////////////////////////////////////////////////////////////////////////////////
  57. typedef TypedGridCullSystemClass<SoundCullObjClass> DynamicSoundCullClass;
  58. typedef TypedAABTreeCullSystemClass<SoundCullObjClass> StaticSoundCullClass;
  59. typedef MultiListClass<AudibleSoundClass> AUDIBLE_SOUND_LIST;
  60. typedef MultiListClass<SoundCullObjClass> SOUND_LIST;
  61. typedef MultiListClass<LogicalSoundClass> LOGICAL_SOUND_LIST;
  62. typedef MultiListClass<LogicalListenerClass> LOGICAL_LISTENER_LIST;
  63. /////////////////////////////////////////////////////////////////////////////////
  64. //
  65. // SoundSceneClass
  66. //
  67. // Mimics the 'SceneClass' for render objects. Used to insert 3D sounds into
  68. // a virtual world. Used to efficiently cull sounds that are too far away
  69. // from the listner to be heard.
  70. //
  71. class SoundSceneClass
  72. {
  73. public:
  74. //////////////////////////////////////////////////////////////////////
  75. // Friend classes
  76. //////////////////////////////////////////////////////////////////////
  77. friend class WWAudioClass;
  78. //////////////////////////////////////////////////////////////////////
  79. // Public constructors/destructors
  80. //////////////////////////////////////////////////////////////////////
  81. SoundSceneClass (void);
  82. virtual ~SoundSceneClass (void);
  83. //////////////////////////////////////////////////////////////////////
  84. // Partition methods
  85. //////////////////////////////////////////////////////////////////////
  86. virtual void Re_Partition (const Vector3 &min_dimension, const Vector3 &max_dimension);
  87. //////////////////////////////////////////////////////////////////////
  88. // Logical sound methods
  89. //////////////////////////////////////////////////////////////////////
  90. virtual void Collect_Logical_Sounds (int listener_count = -1);
  91. //////////////////////////////////////////////////////////////////////
  92. // Listener methods
  93. //////////////////////////////////////////////////////////////////////
  94. virtual void Attach_Listener_To_Obj (RenderObjClass *render_obj, int bone_index = -1) { m_Listener->Attach_To_Object (render_obj, bone_index); }
  95. virtual void Set_Listener_Position (const Vector3 &pos) { m_Listener->Set_Position (pos); }
  96. virtual Vector3 Get_Listener_Position (void) const { return m_Listener->Get_Position (); }
  97. virtual void Set_Listener_Transform (const Matrix3D &transform) { m_Listener->Set_Transform (transform); }
  98. virtual Matrix3D Get_Listener_Transform (void) const { return m_Listener->Get_Transform (); }
  99. virtual Listener3DClass *Peek_2nd_Listener (void) const { return m_2ndListener; }
  100. virtual void Set_2nd_Listener (Listener3DClass *listener);
  101. //////////////////////////////////////////////////////////////////////
  102. // Sound insertion
  103. //////////////////////////////////////////////////////////////////////
  104. virtual void Flush_Scene (void);
  105. virtual void Update_Sound (SoundCullObjClass *sound_obj);
  106. //
  107. // These methods are for inserting audible-dynamic sounds into the scene.
  108. //
  109. virtual void Add_Sound (AudibleSoundClass *sound_obj, bool start_playing = true);
  110. virtual void Remove_Sound (AudibleSoundClass *sound_obj, bool stop_playing = true);
  111. //
  112. // Static sounds are those that will never change position in the world.
  113. // These sounds can be more efficiently culled.
  114. //
  115. virtual void Add_Static_Sound (AudibleSoundClass *sound_obj, bool start_playing = true);
  116. virtual void Remove_Static_Sound (AudibleSoundClass *sound_obj, bool stop_playing = true);
  117. //
  118. // These methods are for inserting logical sounds and listeners into the scene.
  119. //
  120. virtual void Add_Logical_Sound (LogicalSoundClass *sound_obj, bool single_shot = false);
  121. virtual void Remove_Logical_Sound (LogicalSoundClass *sound_obj, bool single_shot = false, bool remove_from_list = true);
  122. virtual void Add_Logical_Listener (LogicalListenerClass *listener_obj);
  123. virtual void Remove_Logical_Listener (LogicalListenerClass *listener_obj);
  124. //////////////////////////////////////////////////////////////////////
  125. // Save/Load
  126. //////////////////////////////////////////////////////////////////////
  127. bool Save_Static (ChunkSaveClass &csave);
  128. bool Load_Static (ChunkLoadClass &cload);
  129. bool Save_Dynamic (ChunkSaveClass &csave);
  130. bool Load_Dynamic (ChunkLoadClass &cload);
  131. bool Is_Batch_Mode (void) const { return m_IsBatchMode; }
  132. void Set_Batch_Mode (bool batch_mode) { m_IsBatchMode = batch_mode; }
  133. //////////////////////////////////////////////////////////////////////
  134. // Debugging
  135. //////////////////////////////////////////////////////////////////////
  136. bool Is_Sound_In_Scene (AudibleSoundClass *sound_obj, bool all = true);
  137. protected:
  138. //////////////////////////////////////////////////////////////////////
  139. // Protected methods
  140. //////////////////////////////////////////////////////////////////////
  141. virtual void On_Frame_Update (unsigned int milliseconds = 0);
  142. virtual void Initialize (void);
  143. virtual bool Is_Logical_Sound_In_Scene (LogicalSoundClass *sound_obj, bool single_shot = false);
  144. // Save/load methods
  145. virtual void Save_Static_Sounds (ChunkSaveClass &csave);
  146. virtual void Load_Static_Sounds (ChunkLoadClass &cload);
  147. //////////////////////////////////////////////////////////////////////
  148. // Collection methods
  149. //////////////////////////////////////////////////////////////////////
  150. class AudibleInfoClass : public MultiListObjectClass, public AutoPoolClass<AudibleInfoClass, 64>
  151. {
  152. public:
  153. AudibleInfoClass (void)
  154. : sound_obj (NULL),
  155. distance2 (0) { }
  156. AudibleInfoClass (AudibleSoundClass *obj, float dist2)
  157. : sound_obj (obj),
  158. distance2 (dist2) { }
  159. AudibleSoundClass * sound_obj;
  160. float distance2;
  161. };
  162. typedef MultiListClass<AudibleInfoClass> COLLECTED_SOUNDS;
  163. virtual void Collect_Audible_Sounds (Listener3DClass *listener, COLLECTED_SOUNDS &list);
  164. private:
  165. //////////////////////////////////////////////////////////////////////
  166. // Private member data
  167. //////////////////////////////////////////////////////////////////////
  168. Listener3DClass * m_Listener;
  169. Listener3DClass * m_2ndListener;
  170. AUDIBLE_SOUND_LIST m_LastSoundsAudible;
  171. SOUND_LIST m_DynamicSounds;
  172. SOUND_LIST m_StaticSounds;
  173. LOGICAL_SOUND_LIST m_LogicalSounds;
  174. LOGICAL_SOUND_LIST m_SingleShotLogicalSounds;
  175. LOGICAL_LISTENER_LIST m_LogicalListeners;
  176. DynamicSoundCullClass m_ListenerCullingSystem;
  177. DynamicSoundCullClass m_LogicalCullingSystem;
  178. DynamicSoundCullClass m_DynamicCullingSystem;
  179. StaticSoundCullClass m_StaticCullingSystem;
  180. Vector3 m_MinExtents;
  181. Vector3 m_MaxExtents;
  182. bool m_IsBatchMode;
  183. };
  184. #endif //__SOUNDSCENE_H