Sound3D.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 : WWAudio *
  23. * *
  24. * $Archive:: /Commando/Code/WWAudio/Sound3D.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/28/01 8:57a $*
  29. * *
  30. * $Revision:: 14 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __SOUND3DOBJ_H
  39. #define __SOUND3DOBJ_H
  40. #include "AudibleSound.H"
  41. #include "mempool.h"
  42. /////////////////////////////////////////////////////////////////////////////////
  43. //
  44. // Sound3DClass
  45. //
  46. // Class defining a 3D sound. A 3D sound uses position and velocity information
  47. // to determine volume/panning/doppler etc.
  48. //
  49. // A 3D sound should be added to the SoundScene rather than explicitly played. The
  50. // SoundScene will determine when a 3D sound is 'in range' and play it...
  51. //
  52. class Sound3DClass : public AudibleSoundClass
  53. {
  54. public:
  55. //////////////////////////////////////////////////////////////////////
  56. // Friend classes
  57. //////////////////////////////////////////////////////////////////////
  58. friend class SoundSceneClass;
  59. //////////////////////////////////////////////////////////////////////
  60. // Public constructors/destructors
  61. //////////////////////////////////////////////////////////////////////
  62. Sound3DClass (const Sound3DClass &src);
  63. Sound3DClass (void);
  64. virtual ~Sound3DClass (void);
  65. //////////////////////////////////////////////////////////////////////
  66. // Public operators
  67. //////////////////////////////////////////////////////////////////////
  68. const Sound3DClass &operator= (const Sound3DClass &src);
  69. //////////////////////////////////////////////////////////////////////
  70. // Identification methods
  71. //////////////////////////////////////////////////////////////////////
  72. virtual SOUND_CLASSID Get_Class_ID (void) const { return CLASSID_3D; }
  73. virtual void Make_Static (bool is_static = true) { m_IsStatic = is_static; }
  74. virtual bool Is_Static (void) const { return m_IsStatic; }
  75. //////////////////////////////////////////////////////////////////////
  76. // Conversion methods
  77. //////////////////////////////////////////////////////////////////////
  78. virtual Sound3DClass * As_Sound3DClass (void) { return this; }
  79. //////////////////////////////////////////////////////////////////////
  80. // State control methods
  81. //////////////////////////////////////////////////////////////////////
  82. virtual bool Play (bool alloc_handle = true);
  83. //////////////////////////////////////////////////////////////////////
  84. // Priority control
  85. //////////////////////////////////////////////////////////////////////
  86. virtual float Get_Priority (void) const { if (m_IsCulled) return 0; return m_Priority; }
  87. //////////////////////////////////////////////////////////////////////
  88. // Scene integration
  89. //////////////////////////////////////////////////////////////////////
  90. virtual void Add_To_Scene (bool start_playing = true);
  91. virtual void Remove_From_Scene (void);
  92. //////////////////////////////////////////////////////////////////////
  93. // Position/direction methods
  94. //////////////////////////////////////////////////////////////////////
  95. virtual void Set_Position (const Vector3 &position);
  96. virtual Vector3 Get_Position (void) const { return m_Transform.Get_Translation (); }
  97. virtual void Set_Listener_Transform (const Matrix3D &tm);
  98. virtual void Set_Transform (const Matrix3D &transform);
  99. virtual Matrix3D Get_Transform (void) const { return m_Transform; }
  100. void Update_Miles_Transform (void);
  101. //////////////////////////////////////////////////////////////////////
  102. // Velocity methods
  103. //////////////////////////////////////////////////////////////////////
  104. //
  105. // The velocity settings are in meters per millisecond.
  106. //
  107. virtual void Set_Velocity (const Vector3 &velocity);
  108. virtual Vector3 Get_Velocity (void) const { return m_CurrentVelocity; }
  109. virtual void Get_Velocity (Vector3 &velocity) const { velocity = m_CurrentVelocity; }
  110. virtual void Auto_Calc_Velocity (bool autocalc = true) { m_bAutoCalcVel = autocalc; }
  111. virtual bool Is_Auto_Calc_Velocity_On (void) const { return m_bAutoCalcVel; }
  112. //////////////////////////////////////////////////////////////////////
  113. // Attenuation settings
  114. //////////////////////////////////////////////////////////////////////
  115. //
  116. // The maximum-volume radius is the distance from the sound-emitter where
  117. // it seems as loud as it is going to get. Volume does not increase after this
  118. // point. Volume is linerally interpolated from the DropOff distance to the MaxVol
  119. // distance. For some objects (like an airplane) the max-vol distance is
  120. // not 0, but would be 100 or so meters away.
  121. //
  122. virtual void Set_Max_Vol_Radius (float radius = 0);
  123. virtual float Get_Max_Vol_Radius (void) const { return m_MaxVolRadius; }
  124. //
  125. // This is the distance where the sound can not be heard any longer. (its vol is 0)
  126. //
  127. virtual void Set_DropOff_Radius (float radius = 1);
  128. virtual float Get_DropOff_Radius () {return(m_DropOffRadius);}
  129. // From PersistClass
  130. const PersistFactoryClass & Get_Factory (void) const;
  131. //
  132. // From PersistClass
  133. //
  134. virtual bool Save (ChunkSaveClass &csave);
  135. virtual bool Load (ChunkLoadClass &cload);
  136. protected:
  137. //////////////////////////////////////////////////////////////////////
  138. // Handle information
  139. //////////////////////////////////////////////////////////////////////
  140. virtual SoundCullObjClass * Peek_Cullable_Wrapper (void) const { return m_PhysWrapper; }
  141. virtual void Set_Cullable_Wrapper (SoundCullObjClass *obj) { m_PhysWrapper = obj; }
  142. //////////////////////////////////////////////////////////////////////
  143. // Update methods
  144. //////////////////////////////////////////////////////////////////////
  145. virtual bool On_Frame_Update (unsigned int milliseconds = 0);
  146. void Update_Edge_Volume (void);
  147. //////////////////////////////////////////////////////////////////////
  148. // Handle information
  149. //////////////////////////////////////////////////////////////////////
  150. virtual void Set_Miles_Handle (MILES_HANDLE handle);
  151. virtual void Initialize_Miles_Handle (void);
  152. virtual void Allocate_Miles_Handle (void);
  153. //////////////////////////////////////////////////////////////////////
  154. // Event handling
  155. //////////////////////////////////////////////////////////////////////
  156. virtual void On_Loop_End (void);
  157. //////////////////////////////////////////////////////////////////////
  158. // Protected member data
  159. //////////////////////////////////////////////////////////////////////
  160. bool m_IsTransformInitted;
  161. bool m_bAutoCalcVel;
  162. Vector3 m_CurrentVelocity;
  163. float m_MaxVolRadius;
  164. bool m_IsStatic;
  165. unsigned int m_LastUpdate;
  166. };
  167. #endif //__SOUND3DOBJ_H