Skip to content

Commit 2b37732

Browse files
authored
refactor(audio): Simplify volume related code in AudioManager and MilesAudioManager (#2030)
1 parent 5dba2a0 commit 2b37732

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

Core/GameEngine/Include/Common/GameAudio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ enum
105105
local player affiliation, etc. (The entire list of checks is contained in shouldPlayLocally()).
106106
107107
In addition, the world and unit audio are never allowed to exceed their footprint, as specified
108-
in the audio settings INI file. In order to accomodate this, the audio uses an audio cache. The
108+
in the audio settings INI file. In order to accommodate this, the audio uses an audio cache. The
109109
audio cache will attempt to load a sample, assuming there is enough room. If there is not enough
110110
room, then it goes through and finds any samples that are lower priority, and kills them until
111111
enough room is present for the sample. If it cannot free enough room, nothing happens to the
@@ -190,7 +190,7 @@ class AudioManager : public SubsystemInterface
190190
virtual void closeDevice( void ) = 0;
191191
virtual void *getDevice( void ) = 0;
192192

193-
// Debice Dependent notification functions
193+
// Device Dependent notification functions
194194
virtual void notifyOfAudioCompletion( UnsignedInt audioCompleted, UnsignedInt flags ) = 0;
195195

196196
// Device Dependent enumerate providers functions. It is okay for there to be only 1 provider (Miles provides a maximum of 64.

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,13 @@ void AudioEventRTS::setVolume( Real vol )
724724
//-------------------------------------------------------------------------------------------------
725725
const Coord3D *AudioEventRTS::getCurrentPosition( void )
726726
{
727-
if (m_ownerType == OT_Positional)
727+
switch (m_ownerType)
728728
{
729+
case OT_Positional:
729730
return &m_positionOfAudio;
730-
}
731-
else if (m_ownerType == OT_Object)
732-
{
733-
Object *obj = TheGameLogic->findObjectByID(m_objectID);
734-
if (obj)
731+
732+
case OT_Object:
733+
if (Object *obj = TheGameLogic->findObjectByID(m_objectID))
735734
{
736735
m_positionOfAudio.set( obj->getPosition() );
737736
}
@@ -740,11 +739,9 @@ const Coord3D *AudioEventRTS::getCurrentPosition( void )
740739
m_ownerType = OT_Dead;
741740
}
742741
return &m_positionOfAudio;
743-
}
744-
else if (m_ownerType == OT_Drawable)
745-
{
746-
Drawable *draw = TheGameClient->findDrawableByID(m_drawableID);
747-
if( draw )
742+
743+
case OT_Drawable:
744+
if (Drawable *draw = TheGameClient->findDrawableByID(m_drawableID))
748745
{
749746
m_positionOfAudio.set( draw->getPosition() );
750747
}
@@ -753,9 +750,8 @@ const Coord3D *AudioEventRTS::getCurrentPosition( void )
753750
m_ownerType = OT_Dead;
754751
}
755752
return &m_positionOfAudio;
756-
}
757-
else if( m_ownerType == OT_Dead )
758-
{
753+
754+
case OT_Dead:
759755
return &m_positionOfAudio;
760756
}
761757

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,12 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
419419
}
420420
}
421421

422-
switch (eventToAdd->getAudioEventInfo()->m_soundType)
422+
const AudioType soundType = eventToAdd->getAudioEventInfo()->m_soundType;
423+
424+
// Check if audio type is on
425+
// TheSuperHackers @info Zero audio volume is not a fail condition, because music, speech and sounds
426+
// still need to be in flight in case the user raises the volume on runtime after the audio was already triggered.
427+
switch (soundType)
423428
{
424429
case AT_Music:
425430
if (!isOn(AudioAffect_Music))
@@ -430,16 +435,14 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
430435
return AHSV_NoSound;
431436
break;
432437
case AT_Streaming:
438+
// if we're currently playing uninterruptable speech, then disallow the addition of this sample
439+
if (getDisallowSpeech())
440+
return AHSV_NoSound;
433441
if (!isOn(AudioAffect_Speech))
434442
return AHSV_NoSound;
435443
break;
436444
}
437445

438-
// if we're currently playing uninterruptable speech, then disallow the addition of this sample
439-
if (getDisallowSpeech() && eventToAdd->getAudioEventInfo()->m_soundType == AT_Streaming) {
440-
return AHSV_NoSound;
441-
}
442-
443446
if (!eventToAdd->getUninterruptable()) {
444447
if (!shouldPlayLocally(eventToAdd)) {
445448
return AHSV_NotForLocal;
@@ -469,8 +472,7 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
469472
return AHSV_Muted;
470473
}
471474

472-
AudioType type = eventToAdd->getAudioEventInfo()->m_soundType;
473-
if (type == AT_Music)
475+
if (soundType == AT_Music)
474476
{
475477
m_music->addAudioEvent(audioEvent);
476478
}

Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,25 +2677,29 @@ Bool MilesAudioManager::isOnScreen( const Coord3D *pos ) const
26772677
//-------------------------------------------------------------------------------------------------
26782678
Real MilesAudioManager::getEffectiveVolume(AudioEventRTS *event) const
26792679
{
2680-
Real volume = 1.0f;
2681-
volume *= (event->getVolume() * event->getVolumeShift());
2682-
if (event->getAudioEventInfo()->m_soundType == AT_Music)
2680+
Real volume = event->getVolume() * event->getVolumeShift();
2681+
2682+
switch (event->getAudioEventInfo()->m_soundType)
2683+
{
2684+
case AT_Music:
26832685
{
26842686
volume *= m_musicVolume;
2687+
break;
26852688
}
2686-
else if (event->getAudioEventInfo()->m_soundType == AT_Streaming)
2689+
case AT_Streaming:
26872690
{
26882691
volume *= m_speechVolume;
2692+
break;
26892693
}
2690-
else
2694+
case AT_SoundEffect:
26912695
{
26922696
if (event->isPositionalAudio())
26932697
{
26942698
volume *= m_sound3DVolume;
2695-
Coord3D distance = m_listenerPosition;
26962699
const Coord3D *pos = event->getCurrentPosition();
26972700
if (pos)
26982701
{
2702+
Coord3D distance = m_listenerPosition;
26992703
distance.sub(pos);
27002704
Real objMinDistance;
27012705
Real objMaxDistance;
@@ -2730,6 +2734,8 @@ Real MilesAudioManager::getEffectiveVolume(AudioEventRTS *event) const
27302734
{
27312735
volume *= m_soundVolume;
27322736
}
2737+
break;
2738+
}
27332739
}
27342740

27352741
return volume;

0 commit comments

Comments
 (0)