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
This commit is contained in:
JeffR 2022-06-03 02:04:39 -05:00
parent 956bd51d6d
commit 943cf8351b
6 changed files with 43 additions and 27 deletions

View file

@ -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);
}
}