Skip to content

Commit 61d4465

Browse files
committed
tweak(gameaudio): Only update sound volumes if the volume has really changed (#3252)
1 parent 4655078 commit 61d4465

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

Core/GameEngine/Source/Common/Audio/GameAudio.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,12 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
708708
m_scriptMusicVolume = volume;
709709
}
710710

711-
m_musicVolume = m_scriptMusicVolume * m_systemMusicVolume;
711+
const Real newVolume = m_scriptMusicVolume * m_systemMusicVolume;
712+
if (m_musicVolume != newVolume)
713+
{
714+
m_musicVolume = newVolume;
715+
m_volumeHasChanged = true;
716+
}
712717
}
713718

714719
if (whichToAffect & AudioAffect_Sound) {
@@ -718,7 +723,12 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
718723
m_scriptSoundVolume = volume;
719724
}
720725

721-
m_soundVolume = m_scriptSoundVolume * m_systemSoundVolume;
726+
const Real newVolume = m_scriptSoundVolume * m_systemSoundVolume;
727+
if (m_soundVolume != newVolume)
728+
{
729+
m_soundVolume = newVolume;
730+
m_volumeHasChanged = true;
731+
}
722732
}
723733

724734
if (whichToAffect & AudioAffect_Sound3D) {
@@ -727,7 +737,13 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
727737
} else {
728738
m_scriptSound3DVolume = volume;
729739
}
730-
m_sound3DVolume = m_scriptSound3DVolume * m_systemSound3DVolume;
740+
741+
const Real newVolume = m_scriptSound3DVolume * m_systemSound3DVolume;
742+
if (m_sound3DVolume != newVolume)
743+
{
744+
m_sound3DVolume = newVolume;
745+
m_volumeHasChanged = true;
746+
}
731747
}
732748

733749
if (whichToAffect & AudioAffect_Speech) {
@@ -736,10 +752,14 @@ void AudioManager::setVolume( Real volume, AudioAffect whichToAffect )
736752
} else {
737753
m_scriptSpeechVolume = volume;
738754
}
739-
m_speechVolume = m_scriptSpeechVolume * m_systemSpeechVolume;
740-
}
741755

742-
m_volumeHasChanged = true;
756+
const Real newVolume = m_scriptSpeechVolume * m_systemSpeechVolume;
757+
if (m_speechVolume != newVolume)
758+
{
759+
m_speechVolume = newVolume;
760+
m_volumeHasChanged = true;
761+
}
762+
}
743763
}
744764

745765
//-------------------------------------------------------------------------------------------------
@@ -760,16 +780,13 @@ Real AudioManager::getVolume( AudioAffect whichToGet )
760780
//-------------------------------------------------------------------------------------------------
761781
void AudioManager::set3DVolumeAdjustment( Real volumeAdjustment )
762782
{
763-
m_sound3DVolume = volumeAdjustment * m_scriptSound3DVolume * m_systemSound3DVolume;
764-
765-
// clamp
766-
if (m_sound3DVolume < 0.0f)
767-
m_sound3DVolume = 0.0f;
783+
const Real newVolume = clamp(0.0f, volumeAdjustment * m_scriptSound3DVolume * m_systemSound3DVolume, 1.0f);
768784

769-
if (m_sound3DVolume > 1.0f)
770-
m_sound3DVolume = 1.0f;
771-
772-
m_volumeHasChanged = TRUE;
785+
if (m_sound3DVolume != newVolume)
786+
{
787+
m_sound3DVolume = newVolume;
788+
m_volumeHasChanged = true;
789+
}
773790
}
774791

775792
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)