sfxDescription.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SFXDESCRIPTION_H_
  23. #define _SFXDESCRIPTION_H_
  24. #ifndef _CONSOLETYPES_H_
  25. #include "console/consoleTypes.h"
  26. #endif
  27. #ifndef _SIMDATABLOCK_H_
  28. #include "console/simDatablock.h"
  29. #endif
  30. #ifndef _MPOINT3_H_
  31. #include "math/mPoint3.h"
  32. #endif
  33. #ifndef _SFXCOMMON_H_
  34. #include "sfx/sfxCommon.h"
  35. #endif
  36. #ifndef _MEASE_H_
  37. #include "math/mEase.h"
  38. #endif
  39. class SFXSource;
  40. /// The SFXDescription defines how a sound should be played.
  41. ///
  42. /// If mConeInsideAngle and mConeOutsideAngle are not both
  43. /// 360 then the sound will be directional and facing out
  44. /// the Y axis. To reorient the cones, reorient the emitter
  45. /// object.
  46. ///
  47. /// A few tips:
  48. ///
  49. /// Make sure that server SFXDescription are defined with the
  50. /// datablock keyword, and that client SFXDescription are defined
  51. /// with the 'new' or 'singleton' keyword.
  52. ///
  53. class SFXDescription : public SimDataBlock
  54. {
  55. typedef SimDataBlock Parent;
  56. public:
  57. enum
  58. {
  59. MaxNumParameters = 8,
  60. };
  61. /// The 0 to 1 volume scale.
  62. F32 mVolume;
  63. /// The pitch scale.
  64. F32 mPitch;
  65. /// If true the sound will loop.
  66. bool mIsLooping;
  67. /// If true the sound data will be streamed from
  68. /// disk and not loaded completely into memory.
  69. bool mIsStreaming;
  70. /// If true the sound will be 3D positional.
  71. bool mIs3D;
  72. /// If this sound is allowed to be mixed in hardware.
  73. bool mUseHardware;
  74. /// If true the sound uses custom reverb properties.
  75. bool mUseReverb;
  76. /// The distance from the emitter at which the
  77. /// sound volume is unchanged. Beyond this distance
  78. /// the volume begins to falloff.
  79. ///
  80. /// This is only valid for 3D sounds.
  81. F32 mMinDistance;
  82. /// The distance from the emitter at which the
  83. /// sound volume becomes zero.
  84. ///
  85. /// This is only valid for 3D sounds.
  86. F32 mMaxDistance;
  87. /// The angle in degrees of the inner part of
  88. /// the cone. It must be within 0 to 360.
  89. ///
  90. /// This is only valid for 3D sounds.
  91. U32 mConeInsideAngle;
  92. /// The angle in degrees of the outer part of
  93. /// the cone. It must be greater than mConeInsideAngle
  94. /// and less than to 360.
  95. ///
  96. /// This is only valid for 3D sounds.
  97. U32 mConeOutsideAngle;
  98. /// The volume scalar for on/beyond the outside angle.
  99. ///
  100. /// This is only valid for 3D sounds.
  101. F32 mConeOutsideVolume;
  102. /// Local logarithmic distance attenuation rolloff factor. -1 to use global setting.
  103. /// Per-sound rolloff settings only supported with some SFX providers.
  104. F32 mRolloffFactor;
  105. /// Max distance in both directions along each axis by which the
  106. /// sound position of a 3D sound will be randomly scattered.
  107. ///
  108. /// Example: if you set x=5, then the final x coordinate of the 3D
  109. /// sound will be (OriginalX + randF( -5, +5 )).
  110. Point3F mScatterDistance;
  111. /// The source to which sources playing with this description will
  112. /// be added.
  113. SFXSource* mSourceGroup;
  114. /// Number of seconds until playback reaches full volume after starting/resuming.
  115. /// Zero to deactivate (default).
  116. F32 mFadeInTime;
  117. /// Number of seconds to fade out fading before stopping/pausing.
  118. /// Zero to deactivate (default).
  119. F32 mFadeOutTime;
  120. /// Easing curve for fade-in.
  121. EaseF mFadeInEase;
  122. /// Easing curve for fade-out.
  123. EaseF mFadeOutEase;
  124. /// When mIsLooping is true, the fades will apply to each cycle. Otherwise, only
  125. /// the first cycle will have a fade-in applied and no fade-out happens when a cycle
  126. /// ends.
  127. ///
  128. /// This also affects the playtime that is used to place fades. If mFadeLoops is
  129. /// false, the total playtime so far will be used rather than the playtime of the
  130. /// current cycle. This makes it possible to apply fades that extend across two or
  131. /// more loops of the sound, i.e. are longer than the actual sound duration.
  132. bool mFadeLoops;
  133. /// The number of seconds of sound data to read per streaming
  134. /// packet. Only relevant if "isStreaming" is true.
  135. U32 mStreamPacketSize;
  136. /// The number of streaming packets to read and buffer in advance.
  137. /// Only relevant if "isStreaming" is true.
  138. U32 mStreamReadAhead;
  139. /// Reverb properties for sound playback.
  140. SFXSoundReverbProperties mReverb;
  141. /// Parameters to which sources playing with this description should automatically
  142. /// connect when created.
  143. StringTableEntry mParameters[ MaxNumParameters ];
  144. /// Priority level for sounds. Higher priority sounds are less likely to be
  145. /// culled.
  146. F32 mPriority;
  147. SFXDescription();
  148. SFXDescription( const SFXDescription& desc );
  149. DECLARE_CONOBJECT( SFXDescription );
  150. static void initPersistFields();
  151. // SimDataBlock.
  152. virtual bool onAdd();
  153. virtual void packData( BitStream* stream );
  154. virtual void unpackData( BitStream* stream );
  155. virtual void inspectPostApply();
  156. /// Validates the description fixing any
  157. /// parameters that are out of range.
  158. void validate();
  159. };
  160. #endif // _SFXDESCRIPTION_H_