Torque3D Documentation / _generateds / sfxAmbience.cpp

sfxAmbience.cpp

Engine/source/sfx/sfxAmbience.cpp

More...

Public Functions

ConsoleDocClass(SFXAmbience , "@brief A datablock that describes an ambient sound <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">space.\n\n</a>" "Each ambience datablock captures the properties of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique ambient sound space. A sound space is comprised <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">of:\n</a>" "- an ambient audio track that is played when the listener is inside the space, \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> reverb environment that is active inside the space, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">and\n</a>" "- <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> number of SFXStates that are activated when entering the space and deactivated when exiting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "Each of these properties is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">optional.\n\n</a>" "An important characteristic of ambient audio spaces is that their unique nature is not determined by their location " "in space but rather by their <a href="/coding/class/classsfxambience/">SFXAmbience</a> datablock. This means that the same <a href="/coding/class/classsfxambience/">SFXAmbience</a> datablock assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "multiple locations in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> level represents the same unique audio space <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the sound <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">system.\n\n</a>" "This is an important distinction <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the ambient sound mixer which will activate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given ambient audio space only " "once at any one time regardless of how many intersecting audio spaces with the same <a href="/coding/class/classsfxambience/">SFXAmbience</a> datablock assigned " "the listener may currently be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">in.\n\n</a>" "All <a href="/coding/class/classsfxambience/">SFXAmbience</a> instances are automatically added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the global @c <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXAmbienceSet.\n\n</a>" "At the moment, transitions between reverb environments are not blended and different reverb environments from multiple " "active SFXAmbiences will not be blended together. This will be added in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> future <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">version.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classsfxambience/">SFXAmbience</a>(Underwater)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " environment=AudioEnvUnderwater;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " soundTrack=ScubaSoundList;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " states[0]=AudioLocationUnderwater;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXEnvironment\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXTrack\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXState\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">LevelInfo::soundAmbience\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Zone::soundAmbience\n\n</a>" " @ref <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablock_Networking\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(SFXAmbience , "@brief A datablock that describes an ambient sound <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">space.\n\n</a>" "Each ambience datablock captures the properties of <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> unique ambient sound space. A sound space is comprised <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">of:\n</a>" "- an ambient audio track that is played when the listener is inside the space, \<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "- <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> reverb environment that is active inside the space, <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">and\n</a>" "- <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> number of SFXStates that are activated when entering the space and deactivated when exiting <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">it.\n</a>" "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "Each of these properties is <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">optional.\n\n</a>" "An important characteristic of ambient audio spaces is that their unique nature is not determined by their location " "in space but rather by their <a href="/coding/class/classsfxambience/">SFXAmbience</a> datablock. This means that the same <a href="/coding/class/classsfxambience/">SFXAmbience</a> datablock assigned <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> " "multiple locations in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> level represents the same unique audio space <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the sound <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">system.\n\n</a>" "This is an important distinction <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the ambient sound mixer which will activate <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> given ambient audio space only " "once at any one time regardless of how many intersecting audio spaces with the same <a href="/coding/class/classsfxambience/">SFXAmbience</a> datablock assigned " "the listener may currently be <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">in.\n\n</a>" "All <a href="/coding/class/classsfxambience/">SFXAmbience</a> instances are automatically added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the global @c <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXAmbienceSet.\n\n</a>" "At the moment, transitions between reverb environments are not blended and different reverb environments from multiple " "active SFXAmbiences will not be blended together. This will be added in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> future <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">version.\n\n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "singleton <a href="/coding/class/classsfxambience/">SFXAmbience</a>(Underwater)\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "{\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " environment=AudioEnvUnderwater;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " soundTrack=ScubaSoundList;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " states[0]=AudioLocationUnderwater;\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" "};\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">endtsexample\n\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXEnvironment\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXTrack\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXState\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">LevelInfo::soundAmbience\n</a>" " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Zone::soundAmbience\n\n</a>" " @ref <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablock_Networking\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(SFXAmbience )

  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#include "sfx/sfxAmbience.h"
 25#include "sfx/sfxEnvironment.h"
 26#include "sfx/sfxTrack.h"
 27#include "sfx/sfxSystem.h"
 28#include "sfx/sfxTypes.h"
 29#include "math/mathTypes.h"
 30#include "core/stream/bitStream.h"
 31
 32
 33IMPLEMENT_CO_DATABLOCK_V1( SFXAmbience );
 34
 35
 36ConsoleDocClass( SFXAmbience,
 37   "@brief A datablock that describes an ambient sound space.\n\n"
 38   
 39   "Each ambience datablock captures the properties of a unique ambient sound space.  A sound space is comprised of:\n"
 40   
 41   "- an ambient audio track that is played when the listener is inside the space,\n"
 42   "- a reverb environment that is active inside the space, and\n"
 43   "- a number of SFXStates that are activated when entering the space and deactivated when exiting it.\n"
 44   "\n"
 45   
 46   "Each of these properties is optional.\n\n"
 47   
 48   "An important characteristic of ambient audio spaces is that their unique nature is not determined by their location "
 49   "in space but rather by their SFXAmbience datablock.  This means that the same SFXAmbience datablock assigned to "
 50   "multiple locations in a level represents the same unique audio space to the sound system.\n\n"
 51   
 52   "This is an important distinction for the ambient sound mixer which will activate a given ambient audio space only "
 53   "once at any one time regardless of how many intersecting audio spaces with the same SFXAmbience datablock assigned "
 54   "the listener may currently be in.\n\n"
 55   
 56   "All SFXAmbience instances are automatically added to the global @c SFXAmbienceSet.\n\n"
 57
 58   "At the moment, transitions between reverb environments are not blended and different reverb environments from multiple "
 59   "active SFXAmbiences will not be blended together.  This will be added in a future version.\n\n"
 60   
 61   "@tsexample\n"
 62   "singleton SFXAmbience( Underwater )\n"
 63   "{\n"
 64   "   environment = AudioEnvUnderwater;\n"
 65   "   soundTrack = ScubaSoundList;\n"
 66   "   states[ 0 ] = AudioLocationUnderwater;\n"
 67   "};\n"
 68   "@endtsexample\n\n"
 69      
 70   "@see SFXEnvironment\n"
 71   "@see SFXTrack\n"
 72   "@see SFXState\n"
 73   "@see LevelInfo::soundAmbience\n"
 74   "@see Zone::soundAmbience\n\n"
 75   "@ref Datablock_Networking\n"
 76   "@ingroup SFX\n"
 77   "@ingroup Datablocks\n"
 78);
 79
 80
 81SFXAmbience::ChangeSignal SFXAmbience::smChangeSignal;
 82
 83
 84//-----------------------------------------------------------------------------
 85
 86SFXAmbience::SFXAmbience()
 87   : mDopplerFactor( 0.5f ),
 88     mRolloffFactor( 1.f ),
 89     mSoundTrack( NULL ),
 90     mEnvironment( NULL )
 91{
 92   dMemset( mState, 0, sizeof( mState ) );
 93}
 94
 95//-----------------------------------------------------------------------------
 96
 97void SFXAmbience::initPersistFields()
 98{
 99   addGroup( "Sound" );
100   
101      addField( "environment",            TypeSFXEnvironmentName, Offset( mEnvironment, SFXAmbience ),
102         "Reverb environment active in the ambience zone.\n"
103         "@ref SFX_reverb" );
104      addField( "soundTrack",             TypeSFXTrackName,       Offset( mSoundTrack, SFXAmbience ),
105         "Sound track to play in the ambience zone." );
106      addField( "rolloffFactor",          TypeF32, Offset( mRolloffFactor, SFXAmbience ),
107         "The rolloff factor to apply to distance-based volume attenuation in this space.\n"
108         "Defaults to 1.0.\n\n"
109         "@note This applies to the logarithmic distance model only.\n\n"
110         "@ref SFXSource_volume" );
111      addField( "dopplerFactor",          TypeF32, Offset( mDopplerFactor, SFXAmbience ),
112         "The factor to apply to the doppler affect in this space.\n"
113         "Defaults to 0.5.\n\n"
114         "@ref SFXSource_doppler" );
115      addField( "states",                 TypeSFXStateName,       Offset( mState, SFXAmbience ),
116         MaxStates,
117         "States to activate when the ambient zone is entered.\n"
118         "When the ambient sound state is entered, all states associated with the state will "
119         "be activated (given that they are not disabled) and deactivated when the space "
120         "is exited again." );
121               
122   endGroup( "Sound" );
123   
124   Parent::initPersistFields();
125}
126
127//-----------------------------------------------------------------------------
128
129bool SFXAmbience::onAdd()
130{
131   if( !Parent::onAdd() )
132      return false;
133      
134   Sim::getSFXAmbienceSet()->addObject( this );
135      
136   return true;
137}
138
139//-----------------------------------------------------------------------------
140
141bool SFXAmbience::preload( bool server, String& errorStr )
142{
143   if( !Parent::preload( server, errorStr ) )
144      return false;
145      
146   validate();
147      
148   // Resolve datablocks on client.
149   
150   if( !server )
151   {
152      if( !sfxResolve( &mEnvironment, errorStr ) )
153         return false;
154         
155      if( !sfxResolve( &mSoundTrack, errorStr ) )
156         return false;
157         
158      for( U32 i = 0; i < MaxStates; ++ i )
159         if( !sfxResolve( &mState[ i ], errorStr ) )
160            return false;
161   }
162         
163   return true;
164}
165
166//-----------------------------------------------------------------------------
167
168void SFXAmbience::packData( BitStream* stream )
169{
170   Parent::packData( stream );
171      
172   sfxWrite( stream, mEnvironment );
173   sfxWrite( stream, mSoundTrack );
174   
175   stream->write( mRolloffFactor );
176   stream->write( mDopplerFactor );
177
178   for( U32 i = 0; i < MaxStates; ++ i )
179      sfxWrite( stream, mState[ i ] );
180}
181
182//-----------------------------------------------------------------------------
183
184void SFXAmbience::unpackData( BitStream* stream )
185{
186   Parent::unpackData( stream );
187      
188   sfxRead( stream, &mEnvironment );
189   sfxRead( stream, &mSoundTrack );
190   
191   stream->read( &mRolloffFactor );
192   stream->read( &mDopplerFactor );
193
194   for( U32 i = 0; i < MaxStates; ++ i )
195      sfxRead( stream, &mState[ i ] );
196}
197
198//-----------------------------------------------------------------------------
199
200void SFXAmbience::inspectPostApply()
201{
202   Parent::inspectPostApply();
203   
204   validate();
205   
206   smChangeSignal.trigger( this );
207}
208
209//-----------------------------------------------------------------------------
210
211void SFXAmbience::validate()
212{
213}
214