sfxParameter.h

Engine/source/sfx/sfxParameter.h

More...

Classes:

class

Parameter for interactive audio.

Public Enumerations

enum
SFXParameterEvent {
  SFXParameterEvent_ValueChanged 
  SFXParameterEvent_Deleted 
}

Enumeration of events triggered by SFXParameters.

Detailed Description

Public Enumerations

SFXParameterEvent

Enumerator

SFXParameterEvent_ValueChanged

The parameter value has changed.

SFXParameterEvent_Deleted

The parameter is about to be deleted.

Enumeration of events triggered by SFXParameters.

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SFXPARAMETER_H_
 25#define _SFXPARAMETER_H_
 26
 27#ifndef _SIMOBJECT_H_
 28   #include "console/simObject.h"
 29#endif
 30#ifndef _SFXCOMMON_H_
 31   #include "sfx/sfxCommon.h"
 32#endif
 33#ifndef _TSIGNAL_H_
 34   #include "core/util/tSignal.h"
 35#endif
 36#ifndef _MPOINT2_H_
 37   #include "math/mPoint2.h"
 38#endif
 39
 40
 41/// Enumeration of events triggered by SFXParameters.
 42enum SFXParameterEvent
 43{
 44   /// The parameter value has changed.
 45   SFXParameterEvent_ValueChanged,
 46   
 47   /// The parameter is about to be deleted.
 48   SFXParameterEvent_Deleted,
 49};
 50
 51
 52/// Parameter for interactive audio.
 53///
 54/// Parameters are tied to sound sources and will signal value changes so that
 55/// sound sources may react.
 56///
 57/// All parameters are global.  The name of a parameter is its internal object name.
 58///
 59/// Like sources, parameters are exclusively client-side.
 60///
 61class SFXParameter : public SimObject
 62{
 63   public:
 64   
 65      typedef SimObject Parent;
 66      typedef Signal< void( SFXParameter* parameter, SFXParameterEvent event ) > EventSignal;
 67            
 68   protected:
 69   
 70      /// The current value.
 71      F32 mValue;
 72      
 73      /// The min/max range of the parameter's value.  Both inclusive.
 74      Point2F mRange;
 75      
 76      /// The channel being controlled by this parameter.
 77      SFXChannel mChannel;
 78      
 79      /// Value assigned to the parameter on creation and reset.
 80      F32 mDefaultValue;
 81      
 82      /// Help text.
 83      String mDescription;
 84   
 85      /// The signal used to notify attached sources of parameter events.
 86      EventSignal mEventSignal;
 87      
 88      /// @name Callbacks
 89      /// @{
 90      
 91      DECLARE_CALLBACK( void, onUpdate, () );
 92      
 93      /// @}
 94      
 95      static bool _setValue( void *object, const char *index, const char *data );
 96      static bool _setRange( void *object, const char *index, const char *data );
 97      static bool _setChannel( void *object, const char *index, const char *data );
 98      static bool _setDefaultValue( void *object, const char *index, const char *data );
 99   
100   public:
101   
102      SFXParameter();
103      
104      ~SFXParameter();
105      
106      /// Look up a parameter by the given name.
107      static SFXParameter* find( StringTableEntry name );
108      
109      /// Update the parameter's value.  The default implementation will invoke a script
110      /// 'onUpdate' method if it is defined and do nothing otherwise.
111      virtual void update();
112      
113      /// Reset the parameter's value to its default.
114      void reset();
115      
116      /// Return the current value of this parameter.
117      F32 getValue() const { return mValue; }
118      
119      /// Set the parameter's current value.  Will be clamped against the parameter's valid
120      /// value range.  If a value change occurs, a SFXParameterEvent_ValueChange event
121      /// is fired.
122      void setValue( F32 value );
123      
124      /// Return the default value of this parameter.  This is the value the parameter
125      /// will be set to when it is added to the system.
126      F32 getDefaultValue() const { return mDefaultValue; }
127      
128      /// Set the default value of this parameter.  This is the value the parameter
129      /// is set to when it is added to the system.
130      void setDefaultValue( F32 value );
131      
132      /// Return the range of valid values that this parameter may take.
133      const Point2F& getRange() const { return mRange; }
134      
135      /// Set the valid range for the value of this parameter.  Note that both min
136      /// and max are inclusive.
137      void setRange( const Point2F& range );
138
139      /// Set the valid range for the value of this parameter.  Note that both min
140      /// and max are inclusive.
141      void setRange( F32 minValue, F32 maxValue ) { setRange( Point2F( minValue, maxValue ) ); }
142      
143      /// Return the parameter channel that is being affected by this parameter.
144      SFXChannel getChannel() const { return mChannel; }
145      
146      /// Set the parameter channel that is being affected by this parameter.
147      void setChannel( SFXChannel channel );
148      
149      /// Return the description text supplied for this parameter.  This is used to help
150      /// identify the purpose of a parameter.
151      const String& getDescription() const { return mDescription; }
152      
153      /// Set the description text for this parameter.  This may be used to help identify
154      /// the purpose of a parameter.
155      void setDescription( const String& str ) { mDescription = str; }
156      
157      /// Return the event signal for this parameter.
158      EventSignal& getEventSignal() { return mEventSignal; }
159      
160      // SimObject.
161      virtual bool onAdd();
162      virtual void onRemove();
163      
164      static void initPersistFields();
165   
166      DECLARE_CONOBJECT( SFXParameter );
167      DECLARE_CATEGORY( "SFX" );
168      DECLARE_DESCRIPTION( "" );
169};
170
171#endif // !_SFXPARAMETER_H_
172
173