Przeglądaj źródła

prelim refactor

AzaezelX 1 rok temu
rodzic
commit
da9b9ed787

+ 18 - 21
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];
-   }
-}
-
-void SoundAsset::setSoundFile(const char* pSoundFile, const U32 slotId)
-{
-   // Sanity!
-   AssertFatal(pSoundFile != NULL, "Cannot use a NULL sound file.");
+   SoundAsset* pData = static_cast<SoundAsset*>(object);
 
-   // Fetch sound file.
-   pSoundFile = StringTable->insert(pSoundFile, true);
+   U32 id = 0;
+   if (index)
+      id = dAtoui(index);
 
-   //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)

+ 4 - 8
Engine/source/T3D/assets/SoundAsset.h

@@ -87,9 +87,9 @@ class SoundAsset : public AssetBase
    typedef AssetPtr<SoundAsset> 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<SoundAsset*>(obj)->setSoundFile(data, index ? dAtoi(index) : 0); return false; }
-  static const char* _getSoundFile(void* obj, const char* data) { return static_cast<SoundAsset*>(obj)->getSoundFile(data); }
 };
 
 DefineConsoleType(TypeSoundAssetPtr, SoundAsset)

+ 3 - 3
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

+ 2 - 1
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 );
 }
 
 //-----------------------------------------------------------------------------