From da9b9ed787887180a25d775089ac49eedf796b0f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 5 Feb 2024 14:23:11 -0600 Subject: [PATCH 1/4] prelim refactor --- Engine/source/T3D/assets/SoundAsset.cpp | 39 ++++++++++------------ Engine/source/T3D/assets/SoundAsset.h | 12 +++---- Engine/source/T3D/assets/assetImporter.cpp | 6 ++-- Engine/source/sfx/sfxSource.cpp | 3 +- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp index e182bf9bd..236463a11 100644 --- a/Engine/source/T3D/assets/SoundAsset.cpp +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -173,7 +173,7 @@ SoundAsset::SoundAsset() mPlaylist.mRandomMode = SFXPlayList::RANDOM_NotRandom; mPlaylist.mTrace = false; mPlaylist.mLoopMode = SFXPlayList::LOOP_All; - mPlaylist.mActiveSlots = 12; + mPlaylist.mActiveSlots = 1; } @@ -192,7 +192,7 @@ void SoundAsset::initPersistFields() Parent::initPersistFields(); addArray("slots", SFXPlayList::SFXPlaylistSettings::NUM_SLOTS); addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset), - &_setSoundFile, &_getSoundFile, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS, "Path to the sound file."); + &_setSoundFile, &defaultProtectedGetFn, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS, "Path to the sound file."); addField("replay", TYPEID< SFXPlayList::EReplayMode >(), Offset(mPlaylist.mSlots.mReplayMode, SoundAsset), SFXPlayList::SFXPlaylistSettings::NUM_SLOTS, "Behavior when an already playing sound is encountered on this slot from a previous cycle.\n" @@ -321,6 +321,8 @@ void SoundAsset::initializeAsset(void) break; mSoundPath[i] = getOwned() ? expandAssetFilePath(mSoundFile[i]) : mSoundPath[i]; + if (!Torque::FS::IsFile(mSoundPath[i])) + Con::errorf("SoundAsset::initializeAsset (%s)[%d] could not find %s!", getAssetName(), i, mSoundPath[i]); } } @@ -437,32 +439,27 @@ U32 SoundAsset::load() return mLoadedState; } -StringTableEntry SoundAsset::getSoundFile(const char* pSoundFile, const U32 slotId) +bool SoundAsset::_setSoundFile(void* object, const char* index, const char* data) { - for (U32 i = 0; i < 12; i++) - { - if(mSoundFile[i] == pSoundFile) - return mSoundFile[i]; - } -} + SoundAsset* pData = static_cast(object); -void SoundAsset::setSoundFile(const char* pSoundFile, const U32 slotId) -{ - // Sanity! - AssertFatal(pSoundFile != NULL, "Cannot use a NULL sound file."); + U32 id = 0; + if (index) + id = dAtoui(index); - // Fetch sound file. - pSoundFile = StringTable->insert(pSoundFile, true); - - //Ignore no change, - if (pSoundFile == mSoundFile[slotId]) - return; + if (pData->mSoundFile[id] == data) + return true; // Update. - mSoundFile[slotId] = getOwned() ? expandAssetFilePath(pSoundFile) : pSoundFile; + pData->mSoundFile[id] = data; + if (pData->mSoundFile[id] == StringTable->EmptyString()) + pData->mSoundPath[id] = StringTable->EmptyString(); + else + pData->mSoundPath[id] = pData->getOwned() ? pData->expandAssetFilePath(pData->mSoundFile[id]) : pData->mSoundFile[id]; // Refresh the asset. - refreshAsset(); + pData->refreshAsset(); + return false; } StringTableEntry SoundAsset::getAssetIdByFileName(StringTableEntry fileName) diff --git a/Engine/source/T3D/assets/SoundAsset.h b/Engine/source/T3D/assets/SoundAsset.h index 5e2ecb3e7..a6fda3f3f 100644 --- a/Engine/source/T3D/assets/SoundAsset.h +++ b/Engine/source/T3D/assets/SoundAsset.h @@ -87,9 +87,9 @@ class SoundAsset : public AssetBase typedef AssetPtr ConcreteAssetPtr; protected: - StringTableEntry mSoundFile[12]; - StringTableEntry mSoundPath[12]; - SFXProfile mSFXProfile[12]; + StringTableEntry mSoundFile[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS]; + StringTableEntry mSoundPath[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS]; + SFXProfile mSFXProfile[SFXPlayList::SFXPlaylistSettings::NUM_SLOTS]; SFXDescription mProfileDesc; SFXPlayList mPlaylist; @@ -155,9 +155,8 @@ public: /// Declare Console Object. DECLARE_CONOBJECT(SoundAsset); - void setSoundFile(const char* pSoundFile, const U32 slotId = 0); + static bool _setSoundFile(void* object, const char* index, const char* data); U32 load(); - StringTableEntry getSoundFile(const char* pSoundFile, const U32 slotId = 0); inline StringTableEntry getSoundPath(const U32 slotId = 0) const { return mSoundPath[slotId]; }; SFXProfile* getSfxProfile(const U32 slotId = 0) { return &mSFXProfile[slotId]; } SFXPlayList* getSfxPlaylist() { return &mPlaylist; } @@ -176,9 +175,6 @@ protected: virtual void initializeAsset(void); void _onResourceChanged(const Torque::Path & path); virtual void onAssetRefresh(void); - - static bool _setSoundFile(void *obj, const char *index, const char *data) { static_cast(obj)->setSoundFile(data, index ? dAtoi(index) : 0); return false; } - static const char* _getSoundFile(void* obj, const char* data) { return static_cast(obj)->getSoundFile(data); } }; DefineConsoleType(TypeSoundAssetPtr, SoundAsset) diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index b853121b2..98def1b9c 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -3345,8 +3345,8 @@ Torque::Path AssetImporter::importSoundAsset(AssetImportObject* assetItem) StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str()); - String imageFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension(); - String assetPath = targetPath + "/" + imageFileName; + String soundFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension(); + String assetPath = targetPath + "/" + soundFileName; String tamlPath = targetPath + "/" + assetName + ".asset.taml"; String originalPath = assetItem->filePath.getFullPath().c_str(); @@ -3362,7 +3362,7 @@ Torque::Path AssetImporter::importSoundAsset(AssetImportObject* assetItem) #endif newAsset->setAssetName(assetName); - newAsset->setSoundFile(imageFileName.c_str()); + newAsset->_setSoundFile(newAsset, "0", soundFileName.c_str()); //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original //file path for reimporting support later diff --git a/Engine/source/sfx/sfxSource.cpp b/Engine/source/sfx/sfxSource.cpp index 4a1765c53..5d782dee5 100644 --- a/Engine/source/sfx/sfxSource.cpp +++ b/Engine/source/sfx/sfxSource.cpp @@ -277,7 +277,8 @@ SFXSource::SFXSource( SFXTrack* track, SFXDescription* description ) if( mTrack != NULL ) deleteNotify( mTrack ); - deleteNotify( mDescription ); + if (mDescription != NULL) + deleteNotify( mDescription ); } //----------------------------------------------------------------------------- From ef858d726bf62293371bd57895b61b9ae54f4968 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 5 Feb 2024 14:40:24 -0600 Subject: [PATCH 2/4] remindernote: false for unchanged, true for changed --- Engine/source/T3D/assets/SoundAsset.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp index 236463a11..bd5ca8dda 100644 --- a/Engine/source/T3D/assets/SoundAsset.cpp +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -448,7 +448,7 @@ bool SoundAsset::_setSoundFile(void* object, const char* index, const char* data id = dAtoui(index); if (pData->mSoundFile[id] == data) - return true; + return false; // Update. pData->mSoundFile[id] = data; @@ -459,7 +459,7 @@ bool SoundAsset::_setSoundFile(void* object, const char* index, const char* data // Refresh the asset. pData->refreshAsset(); - return false; + return true; } StringTableEntry SoundAsset::getAssetIdByFileName(StringTableEntry fileName) From cea641b1542bba3c0b03deb7cb1b0e1df590e70a Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 5 Feb 2024 18:41:07 -0600 Subject: [PATCH 3/4] don't early out, *do* use case sensitive filename finding for the stringtable, and finally, don't even bother setting the mSoundpath here unless it's to clear it --- Engine/source/T3D/assets/SoundAsset.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp index bd5ca8dda..e01ad315c 100644 --- a/Engine/source/T3D/assets/SoundAsset.cpp +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -447,15 +447,10 @@ bool SoundAsset::_setSoundFile(void* object, const char* index, const char* data if (index) id = dAtoui(index); - if (pData->mSoundFile[id] == data) - return false; - // Update. - pData->mSoundFile[id] = data; + pData->mSoundFile[id] = StringTable->insert(data, true); if (pData->mSoundFile[id] == StringTable->EmptyString()) pData->mSoundPath[id] = StringTable->EmptyString(); - else - pData->mSoundPath[id] = pData->getOwned() ? pData->expandAssetFilePath(pData->mSoundFile[id]) : pData->mSoundFile[id]; // Refresh the asset. pData->refreshAsset(); From c9ac4ffbfe81dd1db6c7a9c410eb883368a0f02f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 5 Feb 2024 21:02:41 -0600 Subject: [PATCH 4/4] correct grouping --- Engine/source/T3D/assets/SoundAsset.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp index e01ad315c..a71c08f5b 100644 --- a/Engine/source/T3D/assets/SoundAsset.cpp +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -190,6 +190,7 @@ void SoundAsset::initPersistFields() docsURL; // Call parent. Parent::initPersistFields(); + addGroup("SoundSlots"); addArray("slots", SFXPlayList::SFXPlaylistSettings::NUM_SLOTS); addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset), &_setSoundFile, &defaultProtectedGetFn, SFXPlayList::SFXPlaylistSettings::NUM_SLOTS, "Path to the sound file."); @@ -263,7 +264,9 @@ void SoundAsset::initPersistFields() "Behavior when assigned state is deactivated while slot is playing.\n\n" "@ref SFXPlayList_states"); endArray("slots"); + endGroup("SoundSlots"); + addGroup("General Profile"); addField("pitchAdjust", TypeF32, Offset(mProfileDesc.mPitch, SoundAsset), "Adjustment of the pitch value 1 is default."); addField("volumeAdjust", TypeF32, Offset(mProfileDesc.mVolume, SoundAsset), "Adjustment to the volume."); addField("is3D", TypeBool, Offset(mProfileDesc.mIs3D, SoundAsset), "Set this sound to 3D."); @@ -274,6 +277,7 @@ void SoundAsset::initPersistFields() addField("useHardware", TypeBool, Offset(mProfileDesc.mUseHardware, SoundAsset), "Use hardware mixing for this sound."); addField("sourceGroup", TypeSFXSourceName, Offset(mProfileDesc.mSourceGroup, SoundAsset), "Group that sources playing with this description should be put into."); addField("preload", TypeBool, Offset(mPreload, SoundAsset), "Whether to preload sound data when the profile is added to system."); + endGroup("General Profile"); addGroup("Fading"); addField("fadeInTime", TypeF32, Offset(mProfileDesc.mFadeInTime, SoundAsset), "Number of seconds to gradually fade in volume from zero when playback starts.");