mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-28 11:03:49 +00:00
sound asset final cleanup
remove mSoundPath array no longer needed add a SFXDescription pointer to resolve to. cleanup on teardown
This commit is contained in:
parent
da40838560
commit
bcdac43338
2 changed files with 63 additions and 17 deletions
|
|
@ -152,7 +152,6 @@ SoundAsset::SoundAsset()
|
|||
for (U32 i = 0; i < SFXPlayList::NUM_SLOTS; i++)
|
||||
{
|
||||
mSoundFile[i] = StringTable->EmptyString();
|
||||
mSoundPath[i] = StringTable->EmptyString();
|
||||
mSoundResource[i] = NULL;
|
||||
|
||||
mPlaylist.mSlots.mTransitionOut[i] = SFXPlayList::TRANSITION_Wait;
|
||||
|
|
@ -204,12 +203,24 @@ SoundAsset::SoundAsset()
|
|||
mPlaylist.mActiveSlots = 1;
|
||||
|
||||
mResolvedTrack = NULL;
|
||||
mResolvedDescription = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
SoundAsset::~SoundAsset()
|
||||
{
|
||||
if (mResolvedTrack)
|
||||
{
|
||||
if (mResolvedTrack->isProperlyAdded() && !mResolvedTrack->isDeleted())
|
||||
mResolvedTrack->deleteObject();
|
||||
}
|
||||
|
||||
if (mResolvedDescription)
|
||||
{
|
||||
if (mResolvedDescription->isProperlyAdded() && !mResolvedDescription->isDeleted())
|
||||
mResolvedDescription->deleteObject();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -387,7 +398,7 @@ void SoundAsset::_onResourceChanged(const Torque::Path &path)
|
|||
for (U32 i = 0; i < SFXPlayList::NUM_SLOTS; i++)
|
||||
{
|
||||
|
||||
if (path != Torque::Path(mSoundPath[i]))
|
||||
if (path != Torque::Path(mSoundFile[i]))
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -443,7 +454,7 @@ StringTableEntry SoundAsset::getAssetIdByFilename(StringTableEntry fileName)
|
|||
SoundAsset* soundAsset = AssetDatabase.acquireAsset<SoundAsset>(query.mAssetList[i]);
|
||||
if (soundAsset)
|
||||
{
|
||||
if (soundAsset->getSoundPath() == fileName)
|
||||
if (soundAsset->getSoundFile() == fileName)
|
||||
soundAssetId = soundAsset->getAssetId();
|
||||
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
|
|
@ -485,7 +496,7 @@ U32 SoundAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<SoundAsse
|
|||
for (U32 i = 0; i < foundAssetcount; i++)
|
||||
{
|
||||
SoundAsset* tSoundAsset = AssetDatabase.acquireAsset<SoundAsset>(query.mAssetList[i]);
|
||||
if (tSoundAsset && tSoundAsset->getSoundPath() == fileName)
|
||||
if (tSoundAsset && tSoundAsset->getSoundFile() == fileName)
|
||||
{
|
||||
soundAsset->setAssetId(query.mAssetList[i]);
|
||||
AssetDatabase.releaseAsset(query.mAssetList[i]);
|
||||
|
|
@ -499,9 +510,44 @@ U32 SoundAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<SoundAsse
|
|||
return AssetErrCode::Failed;
|
||||
}
|
||||
|
||||
void SoundAsset::buildDescription()
|
||||
{
|
||||
if (!mResolvedDescription)
|
||||
{
|
||||
mResolvedDescription = new SFXDescription;
|
||||
// calls on add which should validate the description. but do it on mProfileDesc before applying values anyway.
|
||||
mResolvedDescription->registerObject(String::ToString("%s_profile_description", getAssetName()).c_str());
|
||||
}
|
||||
|
||||
mProfileDesc.validate();
|
||||
|
||||
mResolvedDescription->mPitch = mProfileDesc.mPitch;
|
||||
mResolvedDescription->mVolume = mProfileDesc.mVolume;
|
||||
mResolvedDescription->mIs3D = mProfileDesc.mIs3D;
|
||||
mResolvedDescription->mIsLooping = mProfileDesc.mIsLooping;
|
||||
mResolvedDescription->mIsStreaming = mProfileDesc.mIsStreaming;
|
||||
mResolvedDescription->mUseHardware = mProfileDesc.mUseHardware;
|
||||
mResolvedDescription->mMinDistance = mProfileDesc.mMinDistance;
|
||||
mResolvedDescription->mMaxDistance = mProfileDesc.mMaxDistance;
|
||||
mResolvedDescription->mConeInsideAngle = mProfileDesc.mConeInsideAngle;
|
||||
mResolvedDescription->mConeOutsideAngle = mProfileDesc.mConeOutsideAngle;
|
||||
mResolvedDescription->mConeOutsideVolume = mProfileDesc.mConeOutsideVolume;
|
||||
mResolvedDescription->mRolloffFactor = mProfileDesc.mRolloffFactor;
|
||||
mResolvedDescription->mFadeInTime = mProfileDesc.mFadeInTime;
|
||||
mResolvedDescription->mFadeOutTime = mProfileDesc.mFadeOutTime;
|
||||
mResolvedDescription->mFadeLoops = mProfileDesc.mFadeLoops;
|
||||
mResolvedDescription->mScatterDistance = mProfileDesc.mScatterDistance;
|
||||
mResolvedDescription->mStreamPacketSize = mProfileDesc.mStreamPacketSize;
|
||||
mResolvedDescription->mStreamReadAhead = mProfileDesc.mStreamReadAhead;
|
||||
mResolvedDescription->mPriority = mProfileDesc.mPriority;
|
||||
mResolvedDescription->mSourceGroup = mProfileDesc.mSourceGroup;
|
||||
mResolvedDescription->mFadeInEase = mProfileDesc.mFadeInEase;
|
||||
mResolvedDescription->mSourceGroup = mProfileDesc.mSourceGroup;
|
||||
}
|
||||
|
||||
SFXProfile* SoundAsset::buildProfile()
|
||||
{
|
||||
SFXProfile* profile = new SFXProfile(&mProfileDesc, mSoundFile[0], mPreload);
|
||||
SFXProfile* profile = new SFXProfile(mResolvedDescription, mSoundFile[0], mPreload);
|
||||
mSoundResource[0] = profile->getResource();
|
||||
return profile;
|
||||
}
|
||||
|
|
@ -527,7 +573,7 @@ SFXPlayList* SoundAsset::buildPlaylist()
|
|||
continue;
|
||||
|
||||
// Build child SFXProfile
|
||||
SFXProfile* child = new SFXProfile(&mProfileDesc, mSoundFile[i], mPreload);
|
||||
SFXProfile* child = new SFXProfile(mResolvedDescription, mSoundFile[i], mPreload);
|
||||
mSoundResource[i] = child->getResource();
|
||||
pl->mSlots.mTrack[i] = child;
|
||||
}
|
||||
|
|
@ -544,13 +590,14 @@ void SoundAsset::populateSFXTrack(void)
|
|||
|
||||
mIsPlaylist = (count > 1);
|
||||
|
||||
if (mResolvedTrack)
|
||||
buildDescription();
|
||||
|
||||
if (mResolvedTrack && mResolvedDescription)
|
||||
{
|
||||
if (mResolvedTrack->isProperlyAdded() && !mResolvedTrack->isDeleted())
|
||||
{
|
||||
// Track will be referenced through simobjectptr
|
||||
mResolvedTrack->deleteObject();
|
||||
}
|
||||
if (SFX)
|
||||
SFX->notifyDescriptionChanged(mResolvedDescription);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mResolvedTrack = NULL;
|
||||
|
|
@ -618,7 +665,7 @@ void SoundAsset::onTamlCustomRead(const TamlCustomNodes& customNodes)
|
|||
|
||||
DefineEngineMethod(SoundAsset, getSoundPath, const char*, (), , "")
|
||||
{
|
||||
return object->getSoundPath();
|
||||
return object->getSoundFile();
|
||||
}
|
||||
|
||||
DefineEngineMethod(SoundAsset, playSound, S32, (Point3F position), (Point3F::Zero),
|
||||
|
|
|
|||
|
|
@ -133,7 +133,6 @@ public:
|
|||
|
||||
private:
|
||||
StringTableEntry mSoundFile[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
|
||||
StringTableEntry mSoundPath[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
|
||||
Resource<SFXResource> mSoundResource[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS];
|
||||
|
||||
SFXDescription mProfileDesc;
|
||||
|
|
@ -144,6 +143,7 @@ private:
|
|||
bool mPreload;
|
||||
bool mIsPlaylist;
|
||||
SFXTrack* mResolvedTrack;
|
||||
SFXDescription* mResolvedDescription;
|
||||
|
||||
public:
|
||||
SoundAsset();
|
||||
|
|
@ -167,10 +167,9 @@ public:
|
|||
void setSoundFile(StringTableEntry pSoundFile, U32 slot = 0);
|
||||
inline StringTableEntry getSoundFile(U32 slot = 0) { return mSoundFile[slot]; }
|
||||
inline StringTableEntry getRelativeSoundFile(U32 slot = 0) { return collapseAssetFilePath(mSoundFile[slot]); }
|
||||
inline StringTableEntry getSoundPath(const U32 slot = 0) const { return mSoundPath[slot]; };
|
||||
|
||||
SFXTrack* getSFXTrack() { load(); return mResolvedTrack; }
|
||||
SFXDescription* getSfxDescription() { return &mProfileDesc; }
|
||||
SFXDescription* getSfxDescription() { return mResolvedDescription ? mResolvedDescription : &mProfileDesc; }
|
||||
bool isPlaylist(){ return mIsPlaylist; }
|
||||
|
||||
bool isLoop() { return mProfileDesc.mIsLooping; }
|
||||
|
|
@ -180,8 +179,8 @@ public:
|
|||
static U32 getAssetById(StringTableEntry assetId, AssetPtr<SoundAsset>* materialAsset);
|
||||
static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<SoundAsset>* matAsset);
|
||||
|
||||
void buildDescription();
|
||||
SFXProfile* buildProfile();
|
||||
|
||||
SFXPlayList* buildPlaylist();
|
||||
|
||||
void populateSFXTrack(void);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue