sfxParameter.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 _SFXPARAMETER_H_
  23. #define _SFXPARAMETER_H_
  24. #ifndef _SIMOBJECT_H_
  25. #include "console/simObject.h"
  26. #endif
  27. #ifndef _SFXCOMMON_H_
  28. #include "sfx/sfxCommon.h"
  29. #endif
  30. #ifndef _TSIGNAL_H_
  31. #include "core/util/tSignal.h"
  32. #endif
  33. #ifndef _MPOINT2_H_
  34. #include "math/mPoint2.h"
  35. #endif
  36. /// Enumeration of events triggered by SFXParameters.
  37. enum SFXParameterEvent
  38. {
  39. /// The parameter value has changed.
  40. SFXParameterEvent_ValueChanged,
  41. /// The parameter is about to be deleted.
  42. SFXParameterEvent_Deleted,
  43. };
  44. /// Parameter for interactive audio.
  45. ///
  46. /// Parameters are tied to sound sources and will signal value changes so that
  47. /// sound sources may react.
  48. ///
  49. /// All parameters are global. The name of a parameter is its internal object name.
  50. ///
  51. /// Like sources, parameters are exclusively client-side.
  52. ///
  53. class SFXParameter : public SimObject
  54. {
  55. public:
  56. typedef SimObject Parent;
  57. typedef Signal< void( SFXParameter* parameter, SFXParameterEvent event ) > EventSignal;
  58. protected:
  59. /// The current value.
  60. F32 mValue;
  61. /// The min/max range of the parameter's value. Both inclusive.
  62. Point2F mRange;
  63. /// The channel being controlled by this parameter.
  64. SFXChannel mChannel;
  65. /// Value assigned to the parameter on creation and reset.
  66. F32 mDefaultValue;
  67. /// Help text.
  68. String mDescription;
  69. /// The signal used to notify attached sources of parameter events.
  70. EventSignal mEventSignal;
  71. /// @name Callbacks
  72. /// @{
  73. DECLARE_CALLBACK( void, onUpdate, () );
  74. /// @}
  75. static bool _setValue( void *object, const char *index, const char *data );
  76. static bool _setRange( void *object, const char *index, const char *data );
  77. static bool _setChannel( void *object, const char *index, const char *data );
  78. static bool _setDefaultValue( void *object, const char *index, const char *data );
  79. public:
  80. SFXParameter();
  81. ~SFXParameter();
  82. /// Look up a parameter by the given name.
  83. static SFXParameter* find( StringTableEntry name );
  84. /// Update the parameter's value. The default implementation will invoke a script
  85. /// 'onUpdate' method if it is defined and do nothing otherwise.
  86. virtual void update();
  87. /// Reset the parameter's value to its default.
  88. void reset();
  89. /// Return the current value of this parameter.
  90. F32 getValue() const { return mValue; }
  91. /// Set the parameter's current value. Will be clamped against the parameter's valid
  92. /// value range. If a value change occurs, a SFXParameterEvent_ValueChange event
  93. /// is fired.
  94. void setValue( F32 value );
  95. /// Return the default value of this parameter. This is the value the parameter
  96. /// will be set to when it is added to the system.
  97. F32 getDefaultValue() const { return mDefaultValue; }
  98. /// Set the default value of this parameter. This is the value the parameter
  99. /// is set to when it is added to the system.
  100. void setDefaultValue( F32 value );
  101. /// Return the range of valid values that this parameter may take.
  102. const Point2F& getRange() const { return mRange; }
  103. /// Set the valid range for the value of this parameter. Note that both min
  104. /// and max are inclusive.
  105. void setRange( const Point2F& range );
  106. /// Set the valid range for the value of this parameter. Note that both min
  107. /// and max are inclusive.
  108. void setRange( F32 minValue, F32 maxValue ) { setRange( Point2F( minValue, maxValue ) ); }
  109. /// Return the parameter channel that is being affected by this parameter.
  110. SFXChannel getChannel() const { return mChannel; }
  111. /// Set the parameter channel that is being affected by this parameter.
  112. void setChannel( SFXChannel channel );
  113. /// Return the description text supplied for this parameter. This is used to help
  114. /// identify the purpose of a parameter.
  115. const String& getDescription() const { return mDescription; }
  116. /// Set the description text for this parameter. This may be used to help identify
  117. /// the purpose of a parameter.
  118. void setDescription( const String& str ) { mDescription = str; }
  119. /// Return the event signal for this parameter.
  120. EventSignal& getEventSignal() { return mEventSignal; }
  121. // SimObject.
  122. virtual bool onAdd();
  123. virtual void onRemove();
  124. static void initPersistFields();
  125. DECLARE_CONOBJECT( SFXParameter );
  126. DECLARE_CATEGORY( "SFX" );
  127. DECLARE_DESCRIPTION( "" );
  128. };
  129. #endif // !_SFXPARAMETER_H_