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
21 changes: 17 additions & 4 deletions Core/GameEngine/Include/Common/AudioEventRTS.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,27 @@ class AudioEventRTS
PortionToPlay m_portionToPlayNext; ///< Which portion (attack, sound, decay) should be played next?
};

class DynamicAudioEventRTS : public MemoryPoolObject
class DynamicAudioEventRTS : public MemoryPoolObject, public RefCountClass, public AudioEventRTS
{
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(DynamicAudioEventRTS, "DynamicAudioEventRTS" )
public:

DynamicAudioEventRTS() { }
DynamicAudioEventRTS(const AudioEventRTS& a) : m_event(a) { }
DynamicAudioEventRTS() {}
DynamicAudioEventRTS( const AsciiString& eventName ) : AudioEventRTS(eventName) {}
DynamicAudioEventRTS( const AsciiString& eventName, ObjectID ownerID ) : AudioEventRTS(eventName, ownerID) {}
DynamicAudioEventRTS( const AsciiString& eventName, DrawableID drawableID ) : AudioEventRTS(eventName, drawableID) {}
DynamicAudioEventRTS( const AsciiString& eventName, const Coord3D *positionOfAudio ) : AudioEventRTS(eventName, positionOfAudio) {}

AudioEventRTS m_event;
DynamicAudioEventRTS(const AudioEventRTS& a) : AudioEventRTS(a) {}
DynamicAudioEventRTS& operator=( const AudioEventRTS& right )
{
*static_cast<AudioEventRTS*>(this) = right;
return *this;
}

void Delete_This() override
{
deleteInstance(this);
}
};
EMPTY_DTOR(DynamicAudioEventRTS)
19 changes: 11 additions & 8 deletions Core/GameEngine/Include/Common/AudioRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@

#include "Common/GameAudio.h"
#include "Common/GameMemory.h"
#include "Common/AudioHandleSpecialValues.h"

class AudioEventRTS;
class DynamicAudioEventRTS;

enum RequestType CPP_11(: Int)
{
Expand All @@ -45,14 +46,16 @@ struct AudioRequest : public MemoryPoolObject
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( AudioRequest, "AudioRequest" )

public:
AudioEventRTS* releasePendingEvent();

AudioRequest()
: m_request(AR_Play)
, m_pendingEvent(nullptr)
, m_handleToInteractOn(AHSV_Error)
, m_requiresCheckForSample(false)
{}

RequestType m_request;
union
{
AudioEventRTS *m_pendingEvent;
AudioHandle m_handleToInteractOn;
};
Bool m_usePendingEvent;
RefCountPtr<DynamicAudioEventRTS> m_pendingEvent;
AudioHandle m_handleToInteractOn;
Bool m_requiresCheckForSample;
};
8 changes: 3 additions & 5 deletions Core/GameEngine/Include/Common/GameAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "Lib/BaseType.h"
#include "Common/STLTypedefs.h"
#include "Common/SubsystemInterface.h"
#include "mutex.h"


// Forward Declarations
Expand Down Expand Up @@ -255,9 +256,9 @@ class AudioManager : public SubsystemInterface
virtual void setListenerPosition( const Coord3D *newListenerPos, const Coord3D *newListenerOrientation );
virtual const Coord3D *getListenerPosition() const;

virtual AudioRequest *allocateAudioRequest( Bool useAudioEvent );
virtual AudioRequest *allocateAudioRequest();
virtual void releaseAudioRequest( AudioRequest *requestToRelease );
virtual void appendAudioRequest( AudioRequest *m_request );
virtual void appendAudioRequest( AudioRequest *request );
virtual void processRequestList();

virtual AudioEventInfo *newAudioEventInfo( AsciiString newEventName );
Expand All @@ -267,9 +268,6 @@ class AudioManager : public SubsystemInterface
const AudioSettings *getAudioSettings() const;
const MiscAudio *getMiscAudio() const;

// This function should only be called by AudioManager, MusicManager and SoundManager
virtual void releaseAudioEventRTS( AudioEventRTS *&eventToRelease );

// For INI
AudioSettings *friend_getAudioSettings();
MiscAudio *friend_getMiscAudio();
Expand Down
4 changes: 2 additions & 2 deletions Core/GameEngine/Include/Common/GameMusic.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ class MusicManager
MusicManager();
virtual ~MusicManager();

void playTrack( AudioEventRTS *eventToUse );
void playTrack( DynamicAudioEventRTS *eventToUse );
void stopTrack( AudioHandle eventToRemove );

virtual void addAudioEvent(AudioEventRTS *eventToAdd); // pre-copied
virtual void addAudioEvent( DynamicAudioEventRTS *eventToAdd ); // pre-copied
virtual void removeAudioEvent( AudioHandle eventToRemove );

void setVolume( Real m_volume );
Expand Down
4 changes: 2 additions & 2 deletions Core/GameEngine/Include/Common/GameSounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#include "Common/GameAudio.h"
#include "Common/GameType.h"

// Forward declarations
class AudioEventRTS;
class DynamicAudioEventRTS;

class SoundManager : public SubsystemInterface
{
Expand All @@ -67,7 +67,7 @@ class SoundManager : public SubsystemInterface
virtual void setCameraAudibleDistance( Real audibleDistance );
virtual Real getCameraAudibleDistance();

virtual void addAudioEvent(AudioEventRTS *&eventToAdd); // pre-copied
virtual Bool addAudioEvent(DynamicAudioEventRTS *eventToAdd); // pre-copied

virtual void notifyOf2DSampleStart();
virtual void notifyOf3DSampleStart();
Expand Down
16 changes: 0 additions & 16 deletions Core/GameEngine/Source/Common/Audio/AudioRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,4 @@

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;
}
44 changes: 18 additions & 26 deletions Core/GameEngine/Source/Common/Audio/GameAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
return AHSV_NotForLocal;
}

AudioEventRTS *audioEvent = MSGNEW("AudioEventRTS") AudioEventRTS(*eventToAdd); // poolify
DynamicAudioEventRTS *newEvent = newInstance(DynamicAudioEventRTS)(*eventToAdd);
RefCountPtr<DynamicAudioEventRTS> audioEvent = RefCountPtr<DynamicAudioEventRTS>::Create_NoAddRef(newEvent);
audioEvent->setPlayingHandle( allocateNewHandle() );
audioEvent->generateFilename(); // which file are we actually going to play?
eventToAdd->setPlayingAudioIndex( audioEvent->getPlayingAudioIndex() );
Expand All @@ -454,7 +455,6 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
#if RETAIL_COMPATIBLE_CRC
if (notForLocal)
{
releaseAudioEventRTS(audioEvent);
return AHSV_NotForLocal;
}
#endif
Expand All @@ -464,21 +464,22 @@ AudioHandle AudioManager::addAudioEvent(const AudioEventRTS *eventToAdd)
#ifdef INTENSIVE_AUDIO_DEBUG
DEBUG_LOG((" - culled due to muting (%d).", audioEvent->getVolume()));
#endif
releaseAudioEventRTS(audioEvent);
return AHSV_Muted;
}

if (soundType == AT_Music)
{
m_music->addAudioEvent(audioEvent);
m_music->addAudioEvent(audioEvent.Peek());
}
else
{
//Possible to nuke audioEvent inside.
m_sound->addAudioEvent(audioEvent);
if (!m_sound->addAudioEvent(audioEvent.Peek()))
{
audioEvent.Clear();
}
}

if( audioEvent )
if( audioEvent != nullptr )
{
return audioEvent->getPlayingHandle();
}
Expand Down Expand Up @@ -576,7 +577,7 @@ void AudioManager::removeAudioEvent(AudioHandle audioEvent)
return;
}

AudioRequest *req = allocateAudioRequest( false );
AudioRequest *req = allocateAudioRequest();
req->m_handleToInteractOn = audioEvent;
req->m_request = AR_Stop;
appendAudioRequest( req );
Expand Down Expand Up @@ -786,10 +787,9 @@ const Coord3D *AudioManager::getListenerPosition() const
}

//-------------------------------------------------------------------------------------------------
AudioRequest *AudioManager::allocateAudioRequest( Bool useAudioEvent )
AudioRequest *AudioManager::allocateAudioRequest()
{
AudioRequest *audioReq = newInstance(AudioRequest);
audioReq->m_usePendingEvent = useAudioEvent;
audioReq->m_requiresCheckForSample = false;
return audioReq;
}
Expand All @@ -801,21 +801,20 @@ void AudioManager::releaseAudioRequest( AudioRequest *requestToRelease )
}

//-------------------------------------------------------------------------------------------------
void AudioManager::appendAudioRequest( AudioRequest *m_request )
void AudioManager::appendAudioRequest( AudioRequest *request )
{
m_audioRequests.push_back(m_request);
m_audioRequests.push_back(request);
}

//-------------------------------------------------------------------------------------------------
// Remove all pending audio requests
void AudioManager::removeAllAudioRequests()
{
std::list<AudioRequest*>::iterator it;
for ( it = m_audioRequests.begin(); it != m_audioRequests.end(); it++ ) {
releaseAudioRequest( *it );
}

m_audioRequests.clear();
std::list<AudioRequest*>::iterator it;
for ( it = m_audioRequests.begin(); it != m_audioRequests.end(); ++it ) {
releaseAudioRequest( *it );
}
m_audioRequests.clear();
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1043,17 +1042,10 @@ Bool AudioManager::shouldPlayLocally(const AudioEventRTS *audioEvent)
//-------------------------------------------------------------------------------------------------
AudioHandle AudioManager::allocateNewHandle()
{
// note, intenionally a post increment rather than a pre increment.
// note, intentionally a post increment rather than a pre increment.
return theAudioHandlePool++;
}

//-------------------------------------------------------------------------------------------------
void AudioManager::releaseAudioEventRTS( AudioEventRTS *&eventToRelease )
{
delete eventToRelease;
eventToRelease = nullptr;
}

//-------------------------------------------------------------------------------------------------
void AudioManager::muteAudio( MuteAudioReason reason )
{
Expand Down
10 changes: 5 additions & 5 deletions Core/GameEngine/Source/Common/Audio/GameMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,25 @@ MusicManager::~MusicManager()
}

//-------------------------------------------------------------------------------------------------
void MusicManager::playTrack( AudioEventRTS *eventToUse )
void MusicManager::playTrack( DynamicAudioEventRTS *eventToUse )
{
AudioRequest *audioRequest = TheAudio->allocateAudioRequest( true );
audioRequest->m_pendingEvent = eventToUse;
AudioRequest *audioRequest = TheAudio->allocateAudioRequest();
audioRequest->m_pendingEvent = RefCountPtr<DynamicAudioEventRTS>::Create_AddRef(eventToUse);
audioRequest->m_request = AR_Play;
TheAudio->appendAudioRequest( audioRequest );
}

//-------------------------------------------------------------------------------------------------
void MusicManager::stopTrack( AudioHandle eventToRemove )
{
AudioRequest *audioRequest = TheAudio->allocateAudioRequest( false );
AudioRequest *audioRequest = TheAudio->allocateAudioRequest();
audioRequest->m_handleToInteractOn = eventToRemove;
audioRequest->m_request = AR_Stop;
TheAudio->appendAudioRequest( audioRequest );
}

//-------------------------------------------------------------------------------------------------
void MusicManager::addAudioEvent( AudioEventRTS *eventToAdd )
void MusicManager::addAudioEvent( DynamicAudioEventRTS *eventToAdd )
{
playTrack( eventToAdd );
}
Expand Down
11 changes: 6 additions & 5 deletions Core/GameEngine/Source/Common/Audio/GameSounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Real SoundManager::getCameraAudibleDistance()
}

//-------------------------------------------------------------------------------------------------
void SoundManager::addAudioEvent(AudioEventRTS *&eventToAdd)
Bool SoundManager::addAudioEvent(DynamicAudioEventRTS *eventToAdd)
{
if (m_num2DSamples == 0 && m_num3DSamples == 0) {
m_num2DSamples = TheAudio->getNum2DSamples();
Expand All @@ -144,13 +144,14 @@ void SoundManager::addAudioEvent(AudioEventRTS *&eventToAdd)
#ifdef INTENSIVE_AUDIO_DEBUG
DEBUG_LOG((" - appended to request list with handle '%d'.", (UnsignedInt) eventToAdd->getPlayingHandle()));
#endif
AudioRequest *audioRequest = TheAudio->allocateAudioRequest( true );
audioRequest->m_pendingEvent = eventToAdd;
AudioRequest *audioRequest = TheAudio->allocateAudioRequest();
audioRequest->m_pendingEvent = RefCountPtr<DynamicAudioEventRTS>::Create_AddRef(eventToAdd);
audioRequest->m_request = AR_Play;
TheAudio->appendAudioRequest(audioRequest);
} else {
TheAudio->releaseAudioEventRTS(eventToAdd);
return true;
}

return false;
}

//-------------------------------------------------------------------------------------------------
Expand Down
11 changes: 5 additions & 6 deletions Core/GameEngine/Source/Common/INI/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,23 +1167,22 @@ void INI::parseICoord2D( INI* ini, void * /*instance*/, void *store, const void*
void INI::parseDynamicAudioEventRTS( INI *ini, void * /*instance*/, void *store, const void* userData )
{
const char *token = ini->getNextToken();
DynamicAudioEventRTS** theSound = (DynamicAudioEventRTS**)store;
RefCountPtr<DynamicAudioEventRTS>* theSound = (RefCountPtr<DynamicAudioEventRTS>*)store;

// translate the string into a sound
if (stricmp(token, "NoSound") == 0)
{
deleteInstance(*theSound);
*theSound = nullptr;
theSound->Clear();
}
else
{
if (*theSound == nullptr)
*theSound = newInstance(DynamicAudioEventRTS);
(*theSound)->m_event.setEventName(AsciiString(token));
*theSound = RefCountPtr<DynamicAudioEventRTS>::Create_NoAddRef(newInstance(DynamicAudioEventRTS));
(*theSound)->setEventName(AsciiString(token));
}

if (*theSound)
TheAudio->getInfoForAudioEvent(&(*theSound)->m_event);
TheAudio->getInfoForAudioEvent(theSound->Peek());
}

//-------------------------------------------------------------------------------------------------
Expand Down
Loading
Loading