Torque3D Documentation / _generateds / VSoundEffectEvent.cpp

VSoundEffectEvent.cpp

Engine/source/Verve/Extension/SoundEffect/VSoundEffectEvent.cpp

More...

Detailed Description

Public Functions

IMPLEMENT_CONOBJECT(VSoundEffectEvent )

  1
  2//-----------------------------------------------------------------------------
  3// Verve
  4// Copyright (C) 2014 - Violent Tulip
  5//
  6// Permission is hereby granted, free of charge, to any person obtaining a copy
  7// of this software and associated documentation files (the "Software"), to
  8// deal in the Software without restriction, including without limitation the
  9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10// sell copies of the Software, and to permit persons to whom the Software is
 11// furnished to do so, subject to the following conditions:
 12//
 13// The above copyright notice and this permission notice shall be included in
 14// all copies or substantial portions of the Software.
 15//
 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 22// IN THE SOFTWARE.
 23//-----------------------------------------------------------------------------
 24#include "Verve/Core/VGroup.h"
 25#include "Verve/Extension/SoundEffect/VSoundEffectEvent.h"
 26#include "Verve/Extension/SoundEffect/VSoundEffectTrack.h"
 27
 28#include "console/consoleTypes.h"
 29
 30//-----------------------------------------------------------------------------
 31IMPLEMENT_CONOBJECT( VSoundEffectEvent );
 32//-----------------------------------------------------------------------------
 33
 34VSoundEffectEvent::VSoundEffectEvent( void ) : 
 35        mSoundEffect( NULL )
 36{
 37    setLabel( "SoundEvent" );
 38}
 39
 40void VSoundEffectEvent::initPersistFields( void )
 41{
 42    Parent::initPersistFields();
 43
 44    addProtectedField( "SoundEffect", TYPEID<VTorque::SoundEffectType>(), Offset( mSoundEffect, VSoundEffectEvent ), &setSoundData, &defaultProtectedGetFn, "" );
 45}
 46
 47//-----------------------------------------------------------------------------
 48//
 49// Callback Methods.
 50//
 51//-----------------------------------------------------------------------------
 52
 53//-----------------------------------------------------------------------------
 54// 
 55// VSoundEffectEvent::onTrigger( pTime, pDelta );
 56// 
 57// Play the target sound effect. If this track belongs to a SceneObjectGroup,
 58// then the sound will play with the reference object's transform. If this is
 59// not the case, then a 2D sound will be played.
 60// 
 61//-----------------------------------------------------------------------------
 62void VSoundEffectEvent::onTrigger( const S32 &pTime, const S32 &pDelta )
 63{
 64    Parent::onTrigger( pTime, pDelta );
 65
 66    // Fetch Track.
 67    VSoundEffectTrack *track;
 68    if ( !getTrack( track ) )
 69    {
 70        return;
 71    }
 72
 73    // Position & Pitch.
 74    U32 position = mAbs( ( pTime + pDelta ) - getStartTime() );
 75    F32 pitch    = mFabs( getControllerTimeScale() );
 76    if ( position < SFXStartBuffer )
 77    {
 78        // Zero.
 79        position = 0;
 80    }
 81
 82    VSceneObjectGroup *group;
 83    if ( getGroup( group ) )
 84    {
 85        // Play Sound With Reference.
 86        track->mSource = VTorque::playSound( mSoundEffect, group->getSceneObject(), position, pitch );
 87    }
 88    else
 89    {
 90        // Play Sound.
 91        track->mSource = VTorque::playSound( mSoundEffect, position, pitch );
 92    }
 93}
 94
 95//-----------------------------------------------------------------------------
 96//
 97// Property Methods.
 98//
 99//-----------------------------------------------------------------------------
100
101//-----------------------------------------------------------------------------
102// 
103// VSoundEffectEvent::setDuration( pDuration );
104// 
105// This event's duration is always set to the sound object's duration.
106// 
107//-----------------------------------------------------------------------------
108void VSoundEffectEvent::setDuration( const S32 &pDuration )
109{
110    // Clear Duration.
111    mDuration = VTorque::getSoundDuration( mSoundEffect );
112}
113
114//-----------------------------------------------------------------------------
115//
116// Static Field Methods.
117//
118//-----------------------------------------------------------------------------
119
120bool VSoundEffectEvent::setSoundData( void *pObject, const char *pArray, const char *pData )
121{
122    // Fetch Event.
123    VSoundEffectEvent *event = static_cast<VSoundEffectEvent*>( pObject );
124
125    // Use Object.
126    event->mSoundEffect = dynamic_cast<VTorque::SoundEffectType*>( Sim::findObject( pData ) );
127
128    // Set Duration.
129    event->setDuration( 0 );
130
131    return false;
132}
133