From 2c43b505311b9c7f2a0ee2b798cf4c39b2b0d2b7 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sun, 2 Jul 2023 03:18:35 +1000 Subject: [PATCH] Fix immediateSound pool logic --- source/game/StarNetworkedAnimator.cpp | 32 +++++++++++++++------------ source/game/StarNetworkedAnimator.hpp | 4 ++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/source/game/StarNetworkedAnimator.cpp b/source/game/StarNetworkedAnimator.cpp index b679f63..f76882f 100644 --- a/source/game/StarNetworkedAnimator.cpp +++ b/source/game/StarNetworkedAnimator.cpp @@ -726,20 +726,22 @@ void NetworkedAnimator::update(float dt, DynamicTarget* dynamicTarget) { if (dynamicTarget) { dynamicTarget->clearFinishedAudio(); - Json jPersistentSound = activeState.properties.value("persistentSound", ""); + Json persistentSound = activeState.properties.value("persistentSound", ""); String persistentSoundFile; - if (jPersistentSound.isType(Json::Type::String)) - persistentSoundFile = jPersistentSound.toString(); - else if (jPersistentSound.isType(Json::Type::Array)) - persistentSoundFile = Random::randValueFrom(jPersistentSound.toArray(), "").toString(); + if (persistentSound.isType(Json::Type::String)) + persistentSoundFile = persistentSound.toString(); + else if (persistentSound.isType(Json::Type::Array)) + persistentSoundFile = Random::randValueFrom(persistentSound.toArray(), "").toString(); if (!persistentSoundFile.empty()) persistentSoundFile = AssetPath::relativeTo(m_relativePath, persistentSoundFile); 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) 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 = ""; - if (jImmediateSound.isType(Json::Type::String)) - immediateSoundFile = jImmediateSound.toString(); - else if (jImmediateSound.isType(Json::Type::Array)) - immediateSoundFile = Random::randValueFrom(jImmediateSound.toArray(), "").toString(); + if (immediateSound.isType(Json::Type::String)) + immediateSoundFile = immediateSound.toString(); + else if (immediateSound.isType(Json::Type::Array)) + immediateSoundFile = Random::randValueFrom(immediateSound.toArray(), "").toString(); if (!immediateSoundFile.empty()) immediateSoundFile = AssetPath::relativeTo(m_relativePath, immediateSoundFile); 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()) { activeImmediateSound.audio = make_shared(*Root::singleton().assets()->audio(immediateSoundFile)); activeImmediateSound.audio->setRangeMultiplier(activeState.properties.value("immediateSoundRangeMultiplier", 1.0f).toFloat()); diff --git a/source/game/StarNetworkedAnimator.hpp b/source/game/StarNetworkedAnimator.hpp index 18ea4d5..563a21e 100644 --- a/source/game/StarNetworkedAnimator.hpp +++ b/source/game/StarNetworkedAnimator.hpp @@ -44,13 +44,13 @@ public: void clearFinishedAudio(); struct PersistentSound { - String file; + Json sound; AudioInstancePtr audio; float stopRampTime; }; struct ImmediateSound { - String file; + Json sound; AudioInstancePtr audio; };