Skip to content

Commit b42cc31

Browse files
committed
perf(audio): optimize addAudioEvent with early shouldPlayLocally check now that init order is fixed
1 parent ea259ab commit b42cc31

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,17 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
443443
return AHSV_NoSound;
444444
}
445445

446-
AudioEventRTS tempEvent = *eventToAdd;
447-
tempEvent.generateFilename();
448-
((AudioEventRTS*)eventToAdd)->setPlayingAudioIndex( tempEvent.getPlayingAudioIndex() );
449-
tempEvent.generatePlayInfo();
450-
451-
if (!tempEvent.getUninterruptable()) {
452-
if (!shouldPlayLocally(&tempEvent)) {
446+
if (!eventToAdd->getUninterruptable()) {
447+
if (!shouldPlayLocally(eventToAdd)) {
453448
return AHSV_NotForLocal;
454449
}
455450
}
456451

457-
AudioEventRTS *audioEvent = MSGNEW("AudioEventRTS") AudioEventRTS(tempEvent); // poolify
452+
AudioEventRTS *audioEvent = MSGNEW("AudioEventRTS") AudioEventRTS(*eventToAdd); // poolify
458453
audioEvent->setPlayingHandle( allocateNewHandle() );
454+
audioEvent->generateFilename(); // which file are we actually going to play?
455+
((AudioEventRTS*)eventToAdd)->setPlayingAudioIndex( audioEvent->getPlayingAudioIndex() );
456+
audioEvent->generatePlayInfo(); // generate pitch shift and volume shift now as well
459457

460458
std::list<std::pair<AsciiString, Real> >::iterator it;
461459
for (it = m_adjustedVolumes.begin(); it != m_adjustedVolumes.end(); ++it) {

0 commit comments

Comments
 (0)