mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-26 22:31:17 +00:00
Properly pause sounds when entering menu, fixes #330
Otherwise especially looped sounds continue playing while the menu is open, especially noticeable when opening the menu while firing the chaingun (the whirring sound continues playing).
This commit is contained in:
parent
1b61053c53
commit
954ff88759
4 changed files with 70 additions and 0 deletions
|
@ -186,6 +186,7 @@ void idSoundChannel::Clear( void ) {
|
|||
memset( &parms, 0, sizeof(parms) );
|
||||
|
||||
triggered = false;
|
||||
paused = false;
|
||||
openalSource = 0;
|
||||
openalStreamingOffset = 0;
|
||||
openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0;
|
||||
|
@ -962,6 +963,49 @@ void idSoundEmitterLocal::StopSound( const s_channelType channel ) {
|
|||
Sys_LeaveCriticalSection();
|
||||
}
|
||||
|
||||
// DG: to pause active OpenAL sources when entering menu etc
|
||||
void idSoundEmitterLocal::PauseAll( void ) {
|
||||
|
||||
Sys_EnterCriticalSection();
|
||||
|
||||
for( int i = 0; i < SOUND_MAX_CHANNELS; i++ ) {
|
||||
idSoundChannel *chan = &channels[i];
|
||||
|
||||
if ( !chan->triggerState ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( alIsSource( chan->openalSource ) ) {
|
||||
alSourcePause( chan->openalSource );
|
||||
chan->paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
Sys_LeaveCriticalSection();
|
||||
}
|
||||
|
||||
|
||||
// DG: to resume active OpenAL sources when leaving menu etc
|
||||
void idSoundEmitterLocal::UnPauseAll( void ) {
|
||||
|
||||
Sys_EnterCriticalSection();
|
||||
|
||||
for( int i = 0; i < SOUND_MAX_CHANNELS; i++ ) {
|
||||
idSoundChannel *chan = &channels[i];
|
||||
|
||||
if ( !chan->triggerState ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( alIsSource( chan->openalSource ) && chan->paused ) {
|
||||
alSourcePlay( chan->openalSource );
|
||||
chan->paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
Sys_LeaveCriticalSection();
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
idSoundEmitterLocal::FadeSound
|
||||
|
|
|
@ -387,6 +387,8 @@ public:
|
|||
ALuint lastopenalStreamingBuffer[3];
|
||||
bool stopped;
|
||||
|
||||
bool paused; // DG: currently paused, but generally still playing - for when menu is open etc
|
||||
|
||||
bool disallowSlow;
|
||||
|
||||
};
|
||||
|
@ -429,6 +431,9 @@ public:
|
|||
|
||||
void Clear( void );
|
||||
|
||||
void PauseAll( void ); // DG: to pause active OpenAL sources when entering menu etc
|
||||
void UnPauseAll( void ); // DG: to resume active OpenAL sources when leaving menu etc
|
||||
|
||||
void OverrideParms( const soundShaderParms_t *base, const soundShaderParms_t *over, soundShaderParms_t *out );
|
||||
void CheckForCompletion( int current44kHzTime );
|
||||
void Spatialize( idVec3 listenerPos, int listenerArea, idRenderWorld *rw );
|
||||
|
|
|
@ -1482,6 +1482,16 @@ void idSoundWorldLocal::Pause( void ) {
|
|||
}
|
||||
|
||||
pause44kHz = soundSystemLocal.GetCurrent44kHzTime();
|
||||
|
||||
for ( int i = 0; i < emitters.Num(); i++ ) {
|
||||
idSoundEmitterLocal * emitter = emitters[i];
|
||||
|
||||
// if no channels are active, do nothing
|
||||
if ( emitter == NULL || !emitter->playing ) {
|
||||
continue;
|
||||
}
|
||||
emitter->PauseAll();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1501,6 +1511,16 @@ void idSoundWorldLocal::UnPause( void ) {
|
|||
OffsetSoundTime( offset44kHz );
|
||||
|
||||
pause44kHz = -1;
|
||||
|
||||
for ( int i = 0; i < emitters.Num(); i++ ) {
|
||||
idSoundEmitterLocal * emitter = emitters[i];
|
||||
|
||||
// if no channels are active, do nothing
|
||||
if ( emitter == NULL || !emitter->playing ) {
|
||||
continue;
|
||||
}
|
||||
emitter->UnPauseAll();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -143,5 +143,6 @@ AL_API void AL_APIENTRY alSourcef( ALuint sid, ALenum param, ALfloat value ) { }
|
|||
AL_API void AL_APIENTRY alSourceUnqueueBuffers( ALuint sid, ALsizei numEntries, ALuint *bids ) { }
|
||||
|
||||
AL_API void AL_APIENTRY alSourcePlay( ALuint sid ) { }
|
||||
AL_API void AL_APIENTRY alSourcePause( ALuint source ) {}
|
||||
|
||||
} // extern "C"
|
||||
|
|
Loading…
Reference in a new issue