2
0
Эх сурвалжийг харах

Adds safety check to SoundAsset's playSound so if we don't have a source, it doesn't crash
Adds logic to SoundAsset's load sound to 'nudge' the SFX system to load the required data for first use
Shifts SimSoundAssetEvent constructor to utilize assetId instead of raw asset so we can safely fail if for whatever reason we end up default constructor'ing blanks
Standardizes the shapeImage playList lookup a bit into a common function and ensures that on packet receive we force an update of the state's sound

JeffR 3 жил өмнө
parent
commit
943cf8351b

+ 7 - 1
Engine/source/T3D/assets/SoundAsset.cpp

@@ -228,6 +228,9 @@ bool SoundAsset::loadSound()
          mSFXProfile.setDescription(&mProfileDesc);
          mSFXProfile.setSoundFileName(mSoundPath);
          mSFXProfile.setPreload(mPreload);
+
+         //give it a nudge to preload if required
+         mSFXProfile.getBuffer();
       }
 
    }
@@ -341,7 +344,10 @@ DefineEngineMethod(SoundAsset, playSound, S32, (Point3F position), (Point3F::Zer
       MatrixF transform;
       transform.setPosition(position);
       SFXSource* source = SFX->playOnce(object->getSfxProfile(), &transform, NULL, -1);
-      return source->getId();
+      if(source)
+         return source->getId();
+      else
+         return 0;
    }
    else
       return 0;

+ 3 - 8
Engine/source/T3D/gameBase/gameConnection.cpp

@@ -1566,12 +1566,7 @@ void GameConnection::play2D(StringTableEntry assetId)
 {
    if (AssetDatabase.isDeclaredAsset(assetId))
    {
-
-      AssetPtr<SoundAsset> tempSoundAsset;
-      tempSoundAsset = assetId;
-
-      postNetEvent(new SimSoundAssetEvent(tempSoundAsset));
-
+      postNetEvent(new SimSoundAssetEvent(assetId));
    }
 }
 
@@ -1587,7 +1582,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform)
       tempSoundAsset = assetId;
 
       if (!mControlObject)
-         postNetEvent(new SimSoundAssetEvent(tempSoundAsset, transform));
+         postNetEvent(new SimSoundAssetEvent(assetId, *transform));
       else
       {
          // TODO: Maybe improve this to account for the duration
@@ -1601,7 +1596,7 @@ void GameConnection::play3D(StringTableEntry assetId, const MatrixF *transform)
          transform->getColumn(3, &pos);
          mControlObject->getTransform().getColumn(3, &ear);
          if ((ear - pos).len() < tempSoundAsset->getSfxDescription()->mMaxDistance)
-            postNetEvent(new SimSoundAssetEvent(tempSoundAsset, transform));
+            postNetEvent(new SimSoundAssetEvent(assetId, *transform));
       }
 
    }

+ 3 - 3
Engine/source/T3D/gameBase/gameConnectionEvents.cpp

@@ -297,13 +297,13 @@ void SimDataBlockEvent::process(NetConnection *cptr)
 static F32 SoundPosAccuracy = 0.5;
 static S32 SoundRotBits = 8;
 
-SimSoundAssetEvent::SimSoundAssetEvent(AssetPtr<SoundAsset> asset, const MatrixF* mat)
+SimSoundAssetEvent::SimSoundAssetEvent(StringTableEntry assetId, const MatrixF& mat)
 {
    // cant get here unless the asset is declared.
-   mAsset = asset;
+   mAsset = assetId;
 
    if (mat)
-      mTransform = *mat;
+      mTransform = mat;
 }
 
 void SimSoundAssetEvent::pack(NetConnection* con, BitStream* stream)

+ 1 - 1
Engine/source/T3D/gameBase/gameConnectionEvents.h

@@ -114,7 +114,7 @@ private:
 public:
    typedef NetEvent Parent;
    
-   SimSoundAssetEvent(AssetPtr<SoundAsset> asset = NULL, const MatrixF* mat = NULL);
+   SimSoundAssetEvent(StringTableEntry assetId = StringTable->EmptyString(), const MatrixF& mat = MatrixF::Identity);
    void pack(NetConnection*, BitStream* bstream);
    void write(NetConnection*, BitStream* bstream);
    void unpack(NetConnection*, BitStream* bstream);

+ 2 - 0
Engine/source/T3D/shapeBase.h

@@ -504,6 +504,8 @@ struct ShapeBaseImageData: public GameBaseData {
    
    void inspectPostApply();
 
+   void handleStateSoundTrack(const U32& stateId);
+
    /// @}
 
    /// @name Callbacks

+ 27 - 14
Engine/source/T3D/shapeImage.cpp

@@ -372,20 +372,8 @@ bool ShapeBaseImageData::onAdd()
          s.shapeSequenceScale = stateScaleShapeSequence[i];
 
          //_setstateSound(getstateSound(i),i);
-         s.sound = getstateSoundAsset(i);
-         if (s.sound == NULL && mstateSoundName[i] != StringTable->EmptyString())
-         {
-            //ok, so we've got some sort of special-case here like a fallback or SFXPlaylist. So do the hook-up now
-            SFXTrack* sndTrack;
-            if (!Sim::findObject(mstateSoundName[i], sndTrack))
-            {
-               Con::errorf("ShapeBaseImageData::onAdd() - attempted to find sound %s but failed!", mstateSoundName[i]);
-            }
-            else
-            {
-               s.soundTrack = sndTrack;
-            }
-         }
+         handleStateSoundTrack(i);
+
          s.script = stateScript[i];
          s.emitter = stateEmitter[i];
          s.emitterTime = stateEmitterTime[i];
@@ -591,6 +579,30 @@ bool ShapeBaseImageData::preload(bool server, String &errorStr)
    return true;
 }
 
+void ShapeBaseImageData::handleStateSoundTrack(const U32& stateId)
+{
+   if (stateId > MaxStates)
+      return;
+
+   StateData& s = state[stateId];
+
+   s.sound = getstateSoundAsset(stateId);
+
+   if (s.sound == NULL && mstateSoundName[stateId] != StringTable->EmptyString())
+   {
+      //ok, so we've got some sort of special-case here like a fallback or SFXPlaylist. So do the hook-up now
+      SFXTrack* sndTrack;
+      if (!Sim::findObject(mstateSoundName[stateId], sndTrack))
+      {
+         Con::errorf("ShapeBaseImageData::onAdd() - attempted to find sound %s but failed!", mstateSoundName[stateId]);
+      }
+      else
+      {
+         s.soundTrack = sndTrack;
+      }
+   }
+}
+
 S32 ShapeBaseImageData::lookupState(const char* name)
 {
    if (!name || !name[0])
@@ -1366,6 +1378,7 @@ void ShapeBaseImageData::unpackData(BitStream* stream)
             s.emitter = 0;
             
          UNPACKDATA_ASSET_ARRAY(stateSound, i);
+         handleStateSoundTrack(i);
       }
    }