123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //-----------------------------------------------------------------------------
- // Verve
- // Copyright (C) 2014 - Violent Tulip
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "Verve/Core/VGroup.h"
- #include "Verve/Extension/SoundEffect/VSoundEffectEvent.h"
- #include "Verve/Extension/SoundEffect/VSoundEffectTrack.h"
- #include "console/consoleTypes.h"
- //-----------------------------------------------------------------------------
- IMPLEMENT_CONOBJECT( VSoundEffectEvent );
- //-----------------------------------------------------------------------------
- VSoundEffectEvent::VSoundEffectEvent( void ) :
- mSoundEffect( NULL )
- {
- setLabel( "SoundEvent" );
- }
- void VSoundEffectEvent::initPersistFields( void )
- {
- Parent::initPersistFields();
- addProtectedField( "SoundEffect", TYPEID<VTorque::SoundEffectType>(), Offset( mSoundEffect, VSoundEffectEvent ), &setSoundData, &defaultProtectedGetFn, "" );
- }
- //-----------------------------------------------------------------------------
- //
- // Callback Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VSoundEffectEvent::onTrigger( pTime, pDelta );
- //
- // Play the target sound effect. If this track belongs to a SceneObjectGroup,
- // then the sound will play with the reference object's transform. If this is
- // not the case, then a 2D sound will be played.
- //
- //-----------------------------------------------------------------------------
- void VSoundEffectEvent::onTrigger( const S32 &pTime, const S32 &pDelta )
- {
- Parent::onTrigger( pTime, pDelta );
- // Fetch Track.
- VSoundEffectTrack *track;
- if ( !getTrack( track ) )
- {
- return;
- }
- // Position & Pitch.
- U32 position = mAbs( ( pTime + pDelta ) - getStartTime() );
- F32 pitch = mFabs( getControllerTimeScale() );
- if ( position < SFXStartBuffer )
- {
- // Zero.
- position = 0;
- }
- VSceneObjectGroup *group;
- if ( getGroup( group ) )
- {
- // Play Sound With Reference.
- track->mSource = VTorque::playSound( mSoundEffect, group->getSceneObject(), position, pitch );
- }
- else
- {
- // Play Sound.
- track->mSource = VTorque::playSound( mSoundEffect, position, pitch );
- }
- }
- //-----------------------------------------------------------------------------
- //
- // Property Methods.
- //
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //
- // VSoundEffectEvent::setDuration( pDuration );
- //
- // This event's duration is always set to the sound object's duration.
- //
- //-----------------------------------------------------------------------------
- void VSoundEffectEvent::setDuration( const S32 &pDuration )
- {
- // Clear Duration.
- mDuration = VTorque::getSoundDuration( mSoundEffect );
- }
- //-----------------------------------------------------------------------------
- //
- // Static Field Methods.
- //
- //-----------------------------------------------------------------------------
- bool VSoundEffectEvent::setSoundData( void *pObject, const char *pArray, const char *pData )
- {
- // Fetch Event.
- VSoundEffectEvent *event = static_cast<VSoundEffectEvent*>( pObject );
- // Use Object.
- event->mSoundEffect = dynamic_cast<VTorque::SoundEffectType*>( Sim::findObject( pData ) );
- // Set Duration.
- event->setDuration( 0 );
- return false;
- }
|