sfxAmbience.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 _SFXAMBIENCE_H_
  23. #define _SFXAMBIENCE_H_
  24. #ifndef _SIMDATABLOCK_H_
  25. #include "console/simDatablock.h"
  26. #endif
  27. #ifndef _CONSOLETYPES_H_
  28. #include "console/consoleTypes.h"
  29. #endif
  30. #ifndef _TSIGNAL_H_
  31. #include "core/util/tSignal.h"
  32. #endif
  33. #ifndef SOUND_ASSET_H
  34. #include "T3D/assets/SoundAsset.h"
  35. #endif
  36. class SFXEnvironment;
  37. class SFXTrack;
  38. class SFXState;
  39. /// Datablock for describing an ambient audio space.
  40. ///
  41. class SFXAmbience : public SimDataBlock
  42. {
  43. public:
  44. typedef SimDataBlock Parent;
  45. typedef Signal< void( SFXAmbience* ) > ChangeSignal;
  46. enum
  47. {
  48. /// Maximum number of states that can be tied to an ambient space.
  49. MaxStates = 4
  50. };
  51. protected:
  52. /// Doppler shift factor for this space.
  53. F32 mDopplerFactor;
  54. /// Rolloff factor for this space. Only applies to logarithmic distance model.
  55. F32 mRolloffFactor;
  56. /// Sound track to play when inside the ambient space.
  57. DECLARE_SOUNDASSET(SFXAmbience, SoundTrack);
  58. DECLARE_ASSET_SETGET(SFXAmbience, SoundTrack);
  59. /// Reverb environment to apply when inside the ambient space.
  60. SFXEnvironment* mEnvironment;
  61. /// SFXStates to activate when in this ambient space.
  62. SFXState* mState[ MaxStates ];
  63. ///
  64. static ChangeSignal smChangeSignal;
  65. public:
  66. SFXAmbience();
  67. /// Ensure all properties of this ambience adhere to their value contraints.
  68. void validate();
  69. /// Return the rolloff factor to apply to distance-based volume attenuation in this space (logarithmic distance model only).
  70. F32 getRolloffFactor() const { return mRolloffFactor; }
  71. /// Return the doppler shift factor to apply in this space.
  72. F32 getDopplerFactor() const { return mDopplerFactor; }
  73. /// Return the reverb environment of the ambient space.
  74. SFXEnvironment* getEnvironment() const { return mEnvironment; }
  75. /// Return the given state bound to this ambient space.
  76. SFXState* getState( U32 i ) const
  77. {
  78. AssertFatal( i < MaxStates, "SFXState::getState() - index out of range" );
  79. return mState[ i ];
  80. }
  81. ///
  82. static ChangeSignal& getChangeSignal() { return smChangeSignal; }
  83. // SimDataBlock.
  84. virtual bool onAdd();
  85. virtual void packData( BitStream* stream );
  86. virtual void unpackData( BitStream* stream );
  87. virtual bool preload( bool server, String& errorStr );
  88. virtual void inspectPostApply();
  89. static void initPersistFields();
  90. DECLARE_CONOBJECT( SFXAmbience );
  91. DECLARE_CATEGORY( "SFX" );
  92. DECLARE_DESCRIPTION( "An ambient sound environment." );
  93. };
  94. #endif // !_SFXAMBIENCE_H_