Fix immediateSound pool logic

This commit is contained in:
Kae 2023-07-02 03:18:35 +10:00
parent 3c65474062
commit 2c43b50531
2 changed files with 20 additions and 16 deletions

View File

@ -726,20 +726,22 @@ void NetworkedAnimator::update(float dt, DynamicTarget* dynamicTarget) {
if (dynamicTarget) { if (dynamicTarget) {
dynamicTarget->clearFinishedAudio(); dynamicTarget->clearFinishedAudio();
Json jPersistentSound = activeState.properties.value("persistentSound", ""); Json persistentSound = activeState.properties.value("persistentSound", "");
String persistentSoundFile; String persistentSoundFile;
if (jPersistentSound.isType(Json::Type::String)) if (persistentSound.isType(Json::Type::String))
persistentSoundFile = jPersistentSound.toString(); persistentSoundFile = persistentSound.toString();
else if (jPersistentSound.isType(Json::Type::Array)) else if (persistentSound.isType(Json::Type::Array))
persistentSoundFile = Random::randValueFrom(jPersistentSound.toArray(), "").toString(); persistentSoundFile = Random::randValueFrom(persistentSound.toArray(), "").toString();
if (!persistentSoundFile.empty()) if (!persistentSoundFile.empty())
persistentSoundFile = AssetPath::relativeTo(m_relativePath, persistentSoundFile); persistentSoundFile = AssetPath::relativeTo(m_relativePath, persistentSoundFile);
auto& activePersistentSound = dynamicTarget->statePersistentSounds[stateTypeName]; auto& activePersistentSound = dynamicTarget->statePersistentSounds[stateTypeName];
if (persistentSoundFile != activePersistentSound.file || !activePersistentSound.audio) {
activePersistentSound.file = persistentSoundFile; bool changedPersistentSound = persistentSound != activePersistentSound.sound;
if (changedPersistentSound || !activePersistentSound.audio) {
activePersistentSound.sound = move(persistentSound);
if (activePersistentSound.audio) if (activePersistentSound.audio)
activePersistentSound.audio->stop(activePersistentSound.stopRampTime); activePersistentSound.audio->stop(activePersistentSound.stopRampTime);
@ -755,20 +757,22 @@ void NetworkedAnimator::update(float dt, DynamicTarget* dynamicTarget) {
} }
} }
Json jImmediateSound = activeState.properties.value("immediateSound", ""); Json immediateSound = activeState.properties.value("immediateSound", "");
String immediateSoundFile = ""; String immediateSoundFile = "";
if (jImmediateSound.isType(Json::Type::String)) if (immediateSound.isType(Json::Type::String))
immediateSoundFile = jImmediateSound.toString(); immediateSoundFile = immediateSound.toString();
else if (jImmediateSound.isType(Json::Type::Array)) else if (immediateSound.isType(Json::Type::Array))
immediateSoundFile = Random::randValueFrom(jImmediateSound.toArray(), "").toString(); immediateSoundFile = Random::randValueFrom(immediateSound.toArray(), "").toString();
if (!immediateSoundFile.empty()) if (!immediateSoundFile.empty())
immediateSoundFile = AssetPath::relativeTo(m_relativePath, immediateSoundFile); immediateSoundFile = AssetPath::relativeTo(m_relativePath, immediateSoundFile);
auto& activeImmediateSound = dynamicTarget->stateImmediateSounds[stateTypeName]; auto& activeImmediateSound = dynamicTarget->stateImmediateSounds[stateTypeName];
if (immediateSoundFile != activeImmediateSound.file) {
activeImmediateSound.file = immediateSoundFile; bool changedImmediateSound = immediateSound != activeImmediateSound.sound;
if (changedImmediateSound) {
activeImmediateSound.sound = move(immediateSound);
if (!immediateSoundFile.empty()) { if (!immediateSoundFile.empty()) {
activeImmediateSound.audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(immediateSoundFile)); activeImmediateSound.audio = make_shared<AudioInstance>(*Root::singleton().assets()->audio(immediateSoundFile));
activeImmediateSound.audio->setRangeMultiplier(activeState.properties.value("immediateSoundRangeMultiplier", 1.0f).toFloat()); activeImmediateSound.audio->setRangeMultiplier(activeState.properties.value("immediateSoundRangeMultiplier", 1.0f).toFloat());

View File

@ -44,13 +44,13 @@ public:
void clearFinishedAudio(); void clearFinishedAudio();
struct PersistentSound { struct PersistentSound {
String file; Json sound;
AudioInstancePtr audio; AudioInstancePtr audio;
float stopRampTime; float stopRampTime;
}; };
struct ImmediateSound { struct ImmediateSound {
String file; Json sound;
AudioInstancePtr audio; AudioInstancePtr audio;
}; };