Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/GameEngine/Include/Common/AudioRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct AudioRequest : public MemoryPoolObject
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AudioRequest, "AudioRequest" )

public:
AudioEventRTS* releasePendingEvent();

RequestType m_request;
union
{
Expand Down
15 changes: 15 additions & 0 deletions Core/GameEngine/Source/Common/Audio/AudioRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,20 @@

AudioRequest::~AudioRequest()
{
if (m_usePendingEvent)
{
delete m_pendingEvent;
}
}

AudioEventRTS* AudioRequest::releasePendingEvent()
{
if (m_usePendingEvent)
{
m_usePendingEvent = false;
AudioEventRTS* event = m_pendingEvent;
m_pendingEvent = nullptr;
return event;
}
return nullptr;
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class MilesAudioManager : public AudioManager
void initSamplePools();
void processRequest( AudioRequest *req );

void playAudioEvent( AudioEventRTS *event );
void playAudioEvent( AudioRequest* req );
void stopAudioEvent( AudioHandle handle );
void pauseAudioEvent( AudioHandle handle );

Expand Down
24 changes: 14 additions & 10 deletions Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,12 @@ void MilesAudioManager::pauseAmbient( Bool shouldPause )
}

//-------------------------------------------------------------------------------------------------
void MilesAudioManager::playAudioEvent( AudioEventRTS *event )
void MilesAudioManager::playAudioEvent( AudioRequest* req )
{
DEBUG_ASSERTCRASH(req->m_usePendingEvent && req->m_pendingEvent, ("audio request was expected to contain a valid audio event"));

AudioEventRTS* event = req->m_pendingEvent;

#ifdef INTENSIVE_AUDIO_DEBUG
DEBUG_LOG(("MILES (%d) - Processing play request: %d (%s)", TheGameLogic->getFrame(), event->getPlayingHandle(), event->getEventName().str()));
#endif
Expand Down Expand Up @@ -709,16 +713,16 @@ void MilesAudioManager::playAudioEvent( AudioEventRTS *event )
}

// Put this on here, so that the audio event RTS will be cleaned up regardless.
audio->m_audioEventRTS = event;
audio->m_audioEventRTS = req->releasePendingEvent();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also write audio->m_audioEventRTS = event = req->releasePendingEvent(); and just keep using event everywhere.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of the assignment to event?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's optional, but just a tiny bit more robust if releasePendingEvent was changed and would suddenly introduce a new pointer.

audio->m_stream = stream;
audio->m_type = PAT_Stream;

if (stream) {
if ((info->m_soundType == AT_Streaming) && event->getUninterruptible()) {
if ((info->m_soundType == AT_Streaming) && audio->m_audioEventRTS->getUninterruptible()) {
setDisallowSpeech(TRUE);
}
AIL_set_stream_volume_pan(stream, getEffectiveVolume(event), 0.5f);
playStream(event, stream);
AIL_set_stream_volume_pan(stream, getEffectiveVolume(audio->m_audioEventRTS), 0.5f);
playStream(audio->m_audioEventRTS, stream);
m_playingStreams.push_back(audio);
audio = nullptr;
}
Expand Down Expand Up @@ -778,14 +782,14 @@ void MilesAudioManager::playAudioEvent( AudioEventRTS *event )
sample3D = nullptr;
}
// Push it onto the list of playing things
audio->m_audioEventRTS = event;
audio->m_audioEventRTS = req->releasePendingEvent();
audio->m_3DSample = sample3D;
audio->m_file = nullptr;
audio->m_type = PAT_3DSample;
m_playing3DSounds.push_back(audio);

if (sample3D) {
audio->m_file = playSample3D(event, sample3D);
audio->m_file = playSample3D(audio->m_audioEventRTS, sample3D);
m_sound->notifyOf3DSampleStart();
}

Expand Down Expand Up @@ -849,14 +853,14 @@ void MilesAudioManager::playAudioEvent( AudioEventRTS *event )
}

// Push it onto the list of playing things
audio->m_audioEventRTS = event;
audio->m_audioEventRTS = req->releasePendingEvent();
audio->m_sample = sample;
audio->m_file = nullptr;
audio->m_type = PAT_Sample;
m_playingSounds.push_back(audio);

if (sample) {
audio->m_file = playSample(event, sample);
audio->m_file = playSample(audio->m_audioEventRTS, sample);
m_sound->notifyOf2DSampleStart();
}

Expand Down Expand Up @@ -2930,7 +2934,7 @@ void MilesAudioManager::processRequest( AudioRequest *req )
{
case AR_Play:
{
playAudioEvent(req->m_pendingEvent);
playAudioEvent(req);
break;
}
case AR_Pause:
Expand Down
Loading