sfxFMODEventSource.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 _SFXFMODEVENTSOURCE_H_
  23. #define _SFXFMODEVENTSOURCE_H_
  24. #ifndef _SFXSOURCE_H_
  25. #include "sfx/sfxSource.h"
  26. #endif
  27. #include "fmod_event.h"
  28. class SFXFMODEvent;
  29. /// An SFXSource that controls the playback of an SFXFMODEvent.
  30. ///
  31. /// SFXFMODEvents can be played back directly through their console methods.
  32. /// However, this class integrates them with the remaining SFX system and makes
  33. /// events usable wherever SFX tracks are usable though with the important
  34. /// distinction that there can only ever be a single source for a given event.
  35. ///
  36. /// Note that calling playback methods directly on an event will cause a source
  37. /// for the event to be created if there is not already one.
  38. ///
  39. /// Be aware that using fade-outs in events in combination with play-once sources
  40. /// does not work well at the moment.
  41. ///
  42. class SFXFMODEventSource : public SFXSource
  43. {
  44. public:
  45. typedef SFXSource Parent;
  46. protected:
  47. /// The event instance handle for this source.
  48. FMOD_EVENT* mHandle;
  49. ///
  50. SFXFMODEventSource( SFXFMODEvent* event );
  51. /// Update 3D position, velocity, and orientation from current source transform.
  52. void _update3DAttributes();
  53. // SFXSource.
  54. virtual void _updateStatus();
  55. virtual void _updateVolume( const MatrixF& listener );
  56. virtual void _updatePitch();
  57. virtual void _updatePriority();
  58. virtual void _onParameterEvent( SFXParameter* parameter, SFXParameterEvent event );
  59. virtual void _setMinMaxDistance( F32 min, F32 max );
  60. virtual void _setCone( F32 innerAngle, F32 outerAngle, F32 outerVolume );
  61. virtual void _setFadeTimes( F32 fadeInTime, F32 fadeOutTime );
  62. public:
  63. ///
  64. SFXFMODEventSource();
  65. virtual ~SFXFMODEventSource();
  66. /// Return the FMOD event object that is being played back by this source.
  67. SFXFMODEvent* getEvent() const { return ( SFXFMODEvent* ) mTrack.getPointer(); }
  68. /// Create a new source for the given event.
  69. static SFXFMODEventSource* create( SFXFMODEvent* event );
  70. // SFXSource.
  71. virtual void play( F32 fadeInTime = -1.f ); // fadeInTime ignored when resuming from paused
  72. virtual void stop( F32 fadeOutTime = -1.f ); // fadeOutTime!=0 ignored
  73. virtual void pause( F32 fadeOutTime = -1.f ); // fadeOutTime currently ignored
  74. virtual void setTransform( const MatrixF& transform );
  75. virtual void setVelocity( const VectorF& velocity );
  76. DECLARE_CONOBJECT( SFXFMODEventSource );
  77. DECLARE_CATEGORY( "SFX FMOD" );
  78. DECLARE_DESCRIPTION( "An SFX source controlling the playback of an FMOD Designer event." );
  79. };
  80. #endif // !_SFXFMODEVENTSOURCE_H_