Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFXPlaylist asset groundwork #1104

248 changes: 201 additions & 47 deletions Engine/source/T3D/assets/SoundAsset.cpp

Large diffs are not rendered by default.

67 changes: 49 additions & 18 deletions Engine/source/T3D/assets/SoundAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
#include "sfx/sfxDescription.h"
#endif // !_SFXDESCRIPTION_H_


#ifndef _SFXTRACK_H_
#include "sfx/sfxTrack.h"
#endif

#ifndef _SFXPROFILE_H_
#include "sfx/sfxProfile.h"
#endif // !_SFXPROFILE_H_
Expand All @@ -63,22 +68,31 @@
#include "core/resourceManager.h"
#endif

#ifndef _SFXPLAYLIST_H_
#include "sfx/sfxPlayList.h"
#endif

#include "assetMacroHelpers.h"
class SFXResource;
class SFXPlayList;

//-----------------------------------------------------------------------------
class SoundAsset : public AssetBase
{
typedef AssetBase Parent;

protected:
StringTableEntry mSoundFile;
StringTableEntry mSoundPath;
SFXProfile mSFXProfile;
StringTableEntry mSoundFile[12];
StringTableEntry mSoundPath[12];
SFXProfile mSFXProfile[12];

SFXDescription mProfileDesc;
SFXPlayList mPlaylist;
// subtitles
StringTableEntry mSubtitleString;
bool mPreload;
bool mIsPlaylist;
//SFXPlayList::SlotData mSlots;

/*These will be needed in the refactor!
Resource<SFXResource> mSoundResource;
Expand Down Expand Up @@ -114,17 +128,19 @@ class SoundAsset : public AssetBase
virtual void copyTo(SimObject* object);

//SFXResource* getSound() { return mSoundResource; }
Resource<SFXResource> getSoundResource() { return mSFXProfile.getResource(); }
Resource<SFXResource> getSoundResource(const U32 slotId = 0) { return mSFXProfile[slotId].getResource(); }

/// Declare Console Object.
DECLARE_CONOBJECT(SoundAsset);

void setSoundFile(const char* pSoundFile);
bool loadSound();
inline StringTableEntry getSoundFile(void) const { return mSoundFile; };
inline StringTableEntry getSoundPath(void) const { return mSoundPath; };
SFXProfile* getSfxProfile() { return &mSFXProfile; }
bool loadSound(U32 numSlots);
inline StringTableEntry getSoundFile(const U32 slotId = 0) const { return mSoundFile[slotId]; };
inline StringTableEntry getSoundPath(const U32 slotId = 0) const { return mSoundPath[slotId]; };
SFXProfile* getSfxProfile(const U32 slotId = 0) { return &mSFXProfile[slotId]; }
SFXPlayList* getSfxPlaylist() { return &mPlaylist; }
SFXDescription* getSfxDescription() { return &mProfileDesc; }
bool isPlaylist(){ return mIsPlaylist; }

bool isLoop() { return mProfileDesc.mIsLooping; }
bool is3D() { return mProfileDesc.mIs3D; }
Expand All @@ -138,8 +154,8 @@ class SoundAsset : public AssetBase
void _onResourceChanged(const Torque::Path & path);
virtual void onAssetRefresh(void);

static bool setSoundFile(void *obj, const char *index, const char *data) { static_cast<SoundAsset*>(obj)->setSoundFile(data); return false; }
static const char* getSoundFile(void* obj, const char* data) { return static_cast<SoundAsset*>(obj)->getSoundFile(); }
// static bool setSoundFile(void *obj, const char *index, const char *data) { static_cast<SoundAsset*>(obj)->setSoundFile(data); return false; }
// static const char* getSoundFile(void* obj, const char* data) { return static_cast<SoundAsset*>(obj)->getSoundFile(); }
};

DefineConsoleType(TypeSoundAssetPtr, SoundAsset)
Expand All @@ -157,7 +173,7 @@ DefineConsoleType(TypeSoundAssetId, String)
StringTableEntry m##name##Name; \
StringTableEntry m##name##AssetId;\
AssetPtr<SoundAsset> m##name##Asset = NULL;\
SFXProfile* m##name##Profile = NULL;\
SFXTrack* m##name##Profile = NULL;\
SFXDescription* m##name##Desc = NULL;\
SimObjectId m##name##SFXId = 0;\
public: \
Expand Down Expand Up @@ -250,11 +266,20 @@ public: \
{\
return m##name;\
}\
SFXProfile* get##name##Profile()\
SFXTrack* get##name##Profile()\
{\
if (get##name() != StringTable->EmptyString() && m##name##Asset.notNull()){\
m##name##Profile = m##name##Asset->getSfxProfile();\
return m##name##Profile;}\
if(m##name##Asset->isPlaylist())\
{\
m##name##Profile = m##name##Asset->getSfxPlaylist(); \
return m##name##Profile;\
}\
else\
{\
m##name##Profile = m##name##Asset->getSfxProfile(); \
return m##name##Profile;\
}\
}\
return NULL;\
}\
SFXDescription* get##name##Description()\
Expand Down Expand Up @@ -341,7 +366,7 @@ public: \
StringTableEntry m##name##Name[max]; \
StringTableEntry m##name##AssetId[max];\
AssetPtr<SoundAsset> m##name##Asset[max];\
SFXProfile* m##name##Profile[max];\
SFXTrack* m##name##Profile[max];\
SimObjectId m##name##SFXId[max];\
public: \
const StringTableEntry get##name##File(const U32& index) const { return m##name##Name[index]; }\
Expand Down Expand Up @@ -443,10 +468,16 @@ public: \
return ResourceManager::get().load( "" );\
return m##name[id];\
}\
SFXProfile* get##name##Profile(const U32& id)\
SFXTrack* get##name##Profile(const U32& id)\
{\
if (get##name(id) != StringTable->EmptyString() && m##name##Asset[id].notNull())\
return m##name##Asset[id]->getSfxProfile();\
if (m##name##Asset[id]->isPlaylist())\
{\
return m##name##Asset[id]->getSfxPlaylist(); \
}\
else\
{\
return m##name##Asset[id]->getSfxProfile(); \
}\
return NULL;\
}\
bool is##name##Valid(const U32& id) {return (get##name(id) != StringTable->EmptyString() && m##name##Asset[id] && m##name##Asset[id]->getStatus() == AssetBase::Ok); }
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/fx/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ bool Explosion::explode()
resetWorldBox();
}

SFXProfile* sound_prof = mDataBlock->getSoundProfile();
SFXProfile* sound_prof = static_cast<SFXProfile*>(mDataBlock->getSoundProfile());
if (sound_prof)
{
soundProfile_clone = sound_prof->cloneAndPerformSubstitutions(ss_object, ss_index);
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/fx/splash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ void Splash::spawnExplosion()

/// could just play the explosion one, but explosion could be weapon specific,
/// splash sound could be liquid specific. food for thought.
SFXProfile* sound_prof = mDataBlock->getSoundProfile();
SFXTrack* sound_prof = mDataBlock->getSoundProfile();
if (sound_prof)
{
SFX->playOnce(sound_prof, &getTransform());
Expand Down
4 changes: 2 additions & 2 deletions Engine/source/T3D/gameBase/gameConnectionEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ void SimSoundAssetEvent::process(NetConnection* con)
{

if (mAsset->is3D())
SFX->playOnce(mAsset->getSfxProfile(), &mTransform);
SFX->playOnce(mAsset->getSFXTrack(), &mTransform);
else
SFX->playOnce(mAsset->getSfxProfile());
SFX->playOnce(mAsset->getSFXTrack());

}

Expand Down
35 changes: 18 additions & 17 deletions Engine/source/T3D/sfx/sfxEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ SFXEmitter::SFXEmitter()
mDescription.mFadeInTime = -1.f;
mDescription.mFadeOutTime = -1.f;
mInstanceDescription = &mDescription;
mLocalProfile.mFilename = StringTable->EmptyString();
mLocalProfile._registerSignals();
mLocalProfile = NULL;

INIT_ASSET(Sound);

Expand All @@ -119,7 +118,9 @@ SFXEmitter::SFXEmitter()

SFXEmitter::~SFXEmitter()
{
mLocalProfile.onRemove();
if(mLocalProfile != NULL)
mLocalProfile->onRemove();

SFX_DELETE( mSource );
}

Expand Down Expand Up @@ -653,7 +654,7 @@ void SFXEmitter::_update()
SFXStatus prevState = mSource ? mSource->getStatus() : SFXStatusNull;

// are we overriding the asset properties?
bool useTrackDescriptionOnly = (mUseTrackDescriptionOnly && mSoundAsset.notNull() && mSoundAsset->getSfxProfile());
bool useTrackDescriptionOnly = (mUseTrackDescriptionOnly && mSoundAsset.notNull() && getSoundProfile());

if (mSoundAsset.notNull())
{
Expand All @@ -662,12 +663,12 @@ void SFXEmitter::_update()
else
mInstanceDescription = &mDescription;

mLocalProfile = *mSoundAsset->getSfxProfile();
}
// Make sure all the settings are valid.
mInstanceDescription->validate();
mLocalProfile.setDescription(mInstanceDescription);
mLocalProfile = getSoundProfile();

// Make sure all the settings are valid.
mInstanceDescription->validate();
mLocalProfile->setDescription(mInstanceDescription);
}

const MatrixF& transform = getTransform();
const VectorF& velocity = getVelocity();
Expand All @@ -676,12 +677,12 @@ void SFXEmitter::_update()
if( mDirty.test( Track | Is3D | IsLooping | IsStreaming | TrackOnly ) )
{
SFX_DELETE( mSource );
if (mLocalProfile.getSoundFileName().isNotEmpty())
if (getSoundProfile())
{
mSource = SFX->createSource(&mLocalProfile, &transform, &velocity);
mSource = SFX->createSource(mLocalProfile, &transform, &velocity);
if (!mSource)
Con::errorf("SFXEmitter::_update() - failed to create sound for track %i (%s)",
mSoundAsset->getSfxProfile()->getId(), mSoundAsset->getSfxProfile()->getName());
getSoundProfile()->getId(), getSoundProfile()->getName());

// If we're supposed to play when the emitter is
// added to the scene then also restart playback
Expand All @@ -698,7 +699,7 @@ void SFXEmitter::_update()
// is toggled on a local profile sound. It makes the
// editor feel responsive and that things are working.
if( gEditingMission &&
(mSoundAsset.isNull() || !mSoundAsset->getSfxProfile()) &&
(mSoundAsset.isNull() || !getSoundProfile()) &&
mPlayOnAdd &&
mDirty.test( IsLooping ) )
prevState = SFXStatusPlaying;
Expand Down Expand Up @@ -1043,8 +1044,8 @@ SFXStatus SFXEmitter::_getPlaybackStatus() const

bool SFXEmitter::is3D() const
{
if( mSoundAsset.notNull() && mSoundAsset->getSfxProfile() != NULL )
return mSoundAsset->getSfxProfile()->getDescription()->mIs3D;
if( mSoundAsset.notNull() )
return mSoundAsset->getSfxDescription()->mIs3D;
else
return mInstanceDescription->mIs3D;
}
Expand Down Expand Up @@ -1080,8 +1081,8 @@ void SFXEmitter::setScale( const VectorF &scale )
{
F32 maxDistance;

if( mUseTrackDescriptionOnly && mSoundAsset.notNull() && mSoundAsset->getSfxProfile())
maxDistance = mSoundAsset->getSfxProfile()->getDescription()->mMaxDistance;
if( mUseTrackDescriptionOnly && mSoundAsset.notNull() && getSoundProfile())
maxDistance = mSoundAsset->getSfxDescription()->mMaxDistance;
else
{
// Use the average of the three coords.
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/sfx/sfxEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SFXEmitter : public SceneObject

/// A local profile object used to coax the
/// sound system to play a custom sound.
SFXProfile mLocalProfile;
SFXTrack* mLocalProfile;

/// The description used by the local profile.
SFXDescription mDescription;
Expand Down
2 changes: 1 addition & 1 deletion Engine/source/T3D/shapeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ void ShapeBase::updateAudioState(SoundThread& st)
// if asset is valid, play
if (st.asset->isAssetValid() )
{
st.sound = SFX->createSource( st.asset->getSfxProfile() , &getTransform() );
st.sound = SFX->createSource( st.asset->getSFXTrack() , &getTransform() );
if ( st.sound )
st.sound->play();
}
Expand Down
4 changes: 2 additions & 2 deletions Engine/source/T3D/shapeImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2785,7 +2785,7 @@ void ShapeBase::setImageState(U32 imageSlot, U32 newState, bool force)
// Delete any loooping sounds that were in the previous state.
// this is the crazy bit =/ needs to know prev state in order to stop sounds.
// lastState does not return an id for the prev state so we keep track of it.
if (lastState->sound && lastState->sound->getSfxProfile()->getDescription()->mIsLooping)
if (lastState->sound && lastState->sound->getSFXTrack()->getDescription()->mIsLooping)
{
for (Vector<SFXSource*>::iterator i = image.mSoundSources.begin(); i != image.mSoundSources.end(); i++)
SFX_DELETE((*i));
Expand All @@ -2799,7 +2799,7 @@ void ShapeBase::setImageState(U32 imageSlot, U32 newState, bool force)
if (stateData.sound)
{
const Point3F& velocity = getVelocity();
image.addSoundSource(SFX->createSource(stateData.sound->getSfxProfile(), &getRenderTransform(), &velocity));
image.addSoundSource(SFX->createSource(stateData.sound->getSFXTrack(), &getRenderTransform(), &velocity));
}
if (stateData.soundTrack)
{
Expand Down
4 changes: 2 additions & 2 deletions Engine/source/sfx/sfxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void SFXController::_compileList( SFXPlayList* playList )

// If there's no track in this slot, ignore it.

if( !playList->getTrackProfile(slotIndex))
if( !playList->getSlots().mTrack[slotIndex])
continue;

// If this is a looped slot and the list is not set to loop
Expand Down Expand Up @@ -394,7 +394,7 @@ bool SFXController::_execInsn()
case OP_Play:
{
SFXPlayList* playList = getPlayList();
SFXTrack* track = playList->getTrackProfile(insn.mSlotIndex);
SFXTrack* track = playList->getSlots().mTrack[insn.mSlotIndex];

// Handle existing sources playing on this slot and find
// whether we need to start a new source.
Expand Down
Loading