From 9ab5f61c39a59fccd38fb88b7b32a09a3635fdf2 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 14 Oct 2021 22:31:00 -0500 Subject: [PATCH] sound asset conversions - ambience --- Engine/source/sfx/sfxAmbience.cpp | 19 ++++++++++++------- Engine/source/sfx/sfxAmbience.h | 11 ++++++----- Engine/source/sfx/sfxSoundscape.cpp | 2 +- .../pre40/T3Dpre4ProjectImporter.tscript | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Engine/source/sfx/sfxAmbience.cpp b/Engine/source/sfx/sfxAmbience.cpp index e24b5b6e2..fa1d9ed5b 100644 --- a/Engine/source/sfx/sfxAmbience.cpp +++ b/Engine/source/sfx/sfxAmbience.cpp @@ -85,10 +85,10 @@ SFXAmbience::ChangeSignal SFXAmbience::smChangeSignal; SFXAmbience::SFXAmbience() : mDopplerFactor( 0.5f ), mRolloffFactor( 1.f ), - mSoundTrack( NULL ), mEnvironment( NULL ) { dMemset( mState, 0, sizeof( mState ) ); + INIT_ASSET(SoundTrack); } //----------------------------------------------------------------------------- @@ -100,7 +100,7 @@ void SFXAmbience::initPersistFields() addField( "environment", TypeSFXEnvironmentName, Offset( mEnvironment, SFXAmbience ), "Reverb environment active in the ambience zone.\n" "@ref SFX_reverb" ); - addField( "soundTrack", TypeSFXTrackName, Offset( mSoundTrack, SFXAmbience ), + INITPERSISTFIELD_SOUNDASSET(SoundTrack, SFXAmbience, "Sound track to play in the ambience zone." ); addField( "rolloffFactor", TypeF32, Offset( mRolloffFactor, SFXAmbience ), "The rolloff factor to apply to distance-based volume attenuation in this space.\n" @@ -131,7 +131,8 @@ bool SFXAmbience::onAdd() return false; Sim::getSFXAmbienceSet()->addObject( this ); - + + _setSoundTrack(getSoundTrack()); return true; } @@ -150,9 +151,13 @@ bool SFXAmbience::preload( bool server, String& errorStr ) { if( !sfxResolve( &mEnvironment, errorStr ) ) return false; - - if( !sfxResolve( &mSoundTrack, errorStr ) ) + + _setSoundTrack(getSoundTrack()); + if (!getSoundTrackProfile()) + { + Con::errorf("SFXAmbience::Preload() - unable to find sfxProfile for asset %s", mSoundTrackAssetId); return false; + } for( U32 i = 0; i < MaxStates; ++ i ) if( !sfxResolve( &mState[ i ], errorStr ) ) @@ -169,7 +174,7 @@ void SFXAmbience::packData( BitStream* stream ) Parent::packData( stream ); sfxWrite( stream, mEnvironment ); - sfxWrite( stream, mSoundTrack ); + PACKDATA_ASSET(SoundTrack); stream->write( mRolloffFactor ); stream->write( mDopplerFactor ); @@ -185,7 +190,7 @@ void SFXAmbience::unpackData( BitStream* stream ) Parent::unpackData( stream ); sfxRead( stream, &mEnvironment ); - sfxRead( stream, &mSoundTrack ); + UNPACKDATA_ASSET(SoundTrack); stream->read( &mRolloffFactor ); stream->read( &mDopplerFactor ); diff --git a/Engine/source/sfx/sfxAmbience.h b/Engine/source/sfx/sfxAmbience.h index 22d91be4e..598d42596 100644 --- a/Engine/source/sfx/sfxAmbience.h +++ b/Engine/source/sfx/sfxAmbience.h @@ -33,6 +33,9 @@ #include "core/util/tSignal.h" #endif +#ifndef SOUND_ASSET_H +#include "T3D/assets/SoundAsset.h" +#endif class SFXEnvironment; class SFXTrack; @@ -63,7 +66,8 @@ class SFXAmbience : public SimDataBlock F32 mRolloffFactor; /// Sound track to play when inside the ambient space. - SFXTrack* mSoundTrack; + DECLARE_SOUNDASSET(SFXAmbience, SoundTrack); + DECLARE_ASSET_SETGET(SFXAmbience, SoundTrack); /// Reverb environment to apply when inside the ambient space. SFXEnvironment* mEnvironment; @@ -89,10 +93,7 @@ class SFXAmbience : public SimDataBlock /// Return the reverb environment of the ambient space. SFXEnvironment* getEnvironment() const { return mEnvironment; } - - /// Return the ambient soundtrack of this ambient space. - SFXTrack* getSoundTrack() const { return mSoundTrack; } - + /// Return the given state bound to this ambient space. SFXState* getState( U32 i ) const { diff --git a/Engine/source/sfx/sfxSoundscape.cpp b/Engine/source/sfx/sfxSoundscape.cpp index 855ebd2be..c90015ffc 100644 --- a/Engine/source/sfx/sfxSoundscape.cpp +++ b/Engine/source/sfx/sfxSoundscape.cpp @@ -150,7 +150,7 @@ void SFXSoundscapeManager::update() if( !soundscape->_isOverridden() ) { - SFXTrack* track = ambience->getSoundTrack(); + SFXTrack* track = ambience->getSoundTrackProfile(); if( !soundscape->mSource || soundscape->mSource->getTrack() != track ) { if( soundscape->mSource != NULL ) diff --git a/Templates/BaseGame/game/tools/projectImporter/scripts/pre40/T3Dpre4ProjectImporter.tscript b/Templates/BaseGame/game/tools/projectImporter/scripts/pre40/T3Dpre4ProjectImporter.tscript index a80b4362e..67d683968 100644 --- a/Templates/BaseGame/game/tools/projectImporter/scripts/pre40/T3Dpre4ProjectImporter.tscript +++ b/Templates/BaseGame/game/tools/projectImporter/scripts/pre40/T3Dpre4ProjectImporter.tscript @@ -1079,6 +1079,7 @@ T3Dpre4ProjectImporter::genProcessor("PostEffect", "texture textureAsset"); // Using existing SFXProfiles allows us to also injest the descriptions, giving us // our meta-properties on the sound asset itself. //============================================================================== +T3Dpre4ProjectImporter::genProcessor("SFXAmbience", "soundTrack soundTrackAsset"); function T3Dpre4ProjectImporter::processSFXProfileLine(%this, %line) { return %line;