sfxAmbience.h 4.0 KB

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