Skip to content

Commit 360da94

Browse files
committed
perf(audio): optimize AudioManager::addAudioEvent by checking locality early and avoiding string allocations
1 parent 35b3f01 commit 360da94

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
///////////////////////////////////////////////////////////////////////////////////////////////////
7474

75+
static const AsciiString s_noSoundString("NoSound");
76+
7577
static const char* TheSpeakerTypes[] =
7678
{
7779
"2 Speakers",
@@ -407,7 +409,7 @@ void AudioManager::getInfoForAudioEvent( const AudioEventRTS *eventToFindAndFill
407409
//-------------------------------------------------------------------------------------------------
408410
AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
409411
{
410-
if (eventToAdd->getEventName().isEmpty() || eventToAdd->getEventName() == AsciiString("NoSound")) {
412+
if (eventToAdd->getEventName().isEmpty() || eventToAdd->getEventName() == s_noSoundString) {
411413
return AHSV_NoSound;
412414
}
413415

@@ -443,6 +445,11 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
443445
return AHSV_NoSound;
444446
}
445447

448+
if (!eventToAdd->getUninterruptable()) {
449+
if (!shouldPlayLocally(eventToAdd)) {
450+
return AHSV_NotForLocal;
451+
}
452+
}
446453

447454
AudioEventRTS *audioEvent = MSGNEW("AudioEventRTS") AudioEventRTS(*eventToAdd); // poolify
448455
audioEvent->setPlayingHandle( allocateNewHandle() );
@@ -458,13 +465,6 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
458465
}
459466
}
460467

461-
if (!audioEvent->getUninterruptable()) {
462-
if (!shouldPlayLocally(audioEvent)) {
463-
releaseAudioEventRTS(audioEvent);
464-
return AHSV_NotForLocal;
465-
}
466-
}
467-
468468
// cull muted audio
469469
if (audioEvent->getVolume() < m_audioSettings->m_minVolume) {
470470
#ifdef INTENSIVE_AUDIO_DEBUG

0 commit comments

Comments
 (0)