sfxDescription.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #ifndef _SFXDESCRIPTION_H_
  27. #define _SFXDESCRIPTION_H_
  28. #ifndef _CONSOLETYPES_H_
  29. #include "console/consoleTypes.h"
  30. #endif
  31. #ifndef _SIMDATABLOCK_H_
  32. #include "console/simDatablock.h"
  33. #endif
  34. #ifndef _MPOINT3_H_
  35. #include "math/mPoint3.h"
  36. #endif
  37. #ifndef _SFXCOMMON_H_
  38. #include "sfx/sfxCommon.h"
  39. #endif
  40. #ifndef _MEASE_H_
  41. #include "math/mEase.h"
  42. #endif
  43. class SFXSource;
  44. /// The SFXDescription defines how a sound should be played.
  45. ///
  46. /// If mConeInsideAngle and mConeOutsideAngle are not both
  47. /// 360 then the sound will be directional and facing out
  48. /// the Y axis. To reorient the cones, reorient the emitter
  49. /// object.
  50. ///
  51. /// A few tips:
  52. ///
  53. /// Make sure that server SFXDescription are defined with the
  54. /// datablock keyword, and that client SFXDescription are defined
  55. /// with the 'new' or 'singleton' keyword.
  56. ///
  57. class SFXDescription : public SimDataBlock
  58. {
  59. typedef SimDataBlock Parent;
  60. public:
  61. enum
  62. {
  63. MaxNumParameters = 8,
  64. };
  65. /// The 0 to 1 volume scale.
  66. F32 mVolume;
  67. /// The pitch scale.
  68. F32 mPitch;
  69. /// If true the sound will loop.
  70. bool mIsLooping;
  71. /// If true the sound data will be streamed from
  72. /// disk and not loaded completely into memory.
  73. bool mIsStreaming;
  74. /// If true the sound will be 3D positional.
  75. bool mIs3D;
  76. /// If this sound is allowed to be mixed in hardware.
  77. bool mUseHardware;
  78. /// If true the sound uses custom reverb properties.
  79. bool mUseReverb;
  80. /// The distance from the emitter at which the
  81. /// sound volume is unchanged. Beyond this distance
  82. /// the volume begins to falloff.
  83. ///
  84. /// This is only valid for 3D sounds.
  85. F32 mMinDistance;
  86. /// The distance from the emitter at which the
  87. /// sound volume becomes zero.
  88. ///
  89. /// This is only valid for 3D sounds.
  90. F32 mMaxDistance;
  91. /// The angle in degrees of the inner part of
  92. /// the cone. It must be within 0 to 360.
  93. ///
  94. /// This is only valid for 3D sounds.
  95. U32 mConeInsideAngle;
  96. /// The angle in degrees of the outer part of
  97. /// the cone. It must be greater than mConeInsideAngle
  98. /// and less than to 360.
  99. ///
  100. /// This is only valid for 3D sounds.
  101. U32 mConeOutsideAngle;
  102. /// The volume scalar for on/beyond the outside angle.
  103. ///
  104. /// This is only valid for 3D sounds.
  105. F32 mConeOutsideVolume;
  106. /// Local logarithmic distance attenuation rolloff factor. -1 to use global setting.
  107. /// Per-sound rolloff settings only supported with some SFX providers.
  108. F32 mRolloffFactor;
  109. /// Max distance in both directions along each axis by which the
  110. /// sound position of a 3D sound will be randomly scattered.
  111. ///
  112. /// Example: if you set x=5, then the final x coordinate of the 3D
  113. /// sound will be (OriginalX + randF( -5, +5 )).
  114. Point3F mScatterDistance;
  115. /// The source to which sources playing with this description will
  116. /// be added.
  117. SFXSource* mSourceGroup;
  118. /// Number of seconds until playback reaches full volume after starting/resuming.
  119. /// Zero to deactivate (default).
  120. F32 mFadeInTime;
  121. /// Number of seconds to fade out fading before stopping/pausing.
  122. /// Zero to deactivate (default).
  123. F32 mFadeOutTime;
  124. /// Easing curve for fade-in.
  125. EaseF mFadeInEase;
  126. /// Easing curve for fade-out.
  127. EaseF mFadeOutEase;
  128. /// When mIsLooping is true, the fades will apply to each cycle. Otherwise, only
  129. /// the first cycle will have a fade-in applied and no fade-out happens when a cycle
  130. /// ends.
  131. ///
  132. /// This also affects the playtime that is used to place fades. If mFadeLoops is
  133. /// false, the total playtime so far will be used rather than the playtime of the
  134. /// current cycle. This makes it possible to apply fades that extend across two or
  135. /// more loops of the sound, i.e. are longer than the actual sound duration.
  136. bool mFadeLoops;
  137. /// The number of seconds of sound data to read per streaming
  138. /// packet. Only relevant if "isStreaming" is true.
  139. U32 mStreamPacketSize;
  140. /// The number of streaming packets to read and buffer in advance.
  141. /// Only relevant if "isStreaming" is true.
  142. U32 mStreamReadAhead;
  143. /// Reverb properties for sound playback.
  144. SFXSoundReverbProperties mReverb;
  145. /// Parameters to which sources playing with this description should automatically
  146. /// connect when created.
  147. StringTableEntry mParameters[ MaxNumParameters ];
  148. /// Priority level for sounds. Higher priority sounds are less likely to be
  149. /// culled.
  150. F32 mPriority;
  151. SFXDescription();
  152. SFXDescription( const SFXDescription& desc );
  153. DECLARE_CONOBJECT( SFXDescription );
  154. static void initPersistFields();
  155. // SimDataBlock.
  156. virtual bool onAdd();
  157. virtual void packData( BitStream* stream );
  158. virtual void unpackData( BitStream* stream );
  159. virtual void inspectPostApply();
  160. /// Validates the description fixing any
  161. /// parameters that are out of range.
  162. void validate();
  163. public:
  164. SFXDescription(const SFXDescription&, bool);
  165. virtual bool allowSubstitutions() const { return true; }
  166. };
  167. #endif // _SFXDESCRIPTION_H_