From d49d0753eb13c9fc618e8ef4a07ea145f13b570f Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Wed, 17 Oct 2012 20:39:45 +0000 Subject: [PATCH] When in third person, don't play player's sounds as full volume in Base sound system. OpenAL already does this. (Related to bug 5741.) --- code/client/snd_dma.c | 68 ++++++++++++++++++++++++++++++++++++---- code/client/snd_local.h | 3 ++ code/client/snd_openal.c | 7 ++--- 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/code/client/snd_dma.c b/code/client/snd_dma.c index 594fdcfb..83da804f 100644 --- a/code/client/snd_dma.c +++ b/code/client/snd_dma.c @@ -471,20 +471,59 @@ void S_SpatializeOrigin (vec3_t origin, int master_vol, int *left_vol, int *righ // Start a sound effect // ======================================================================= +/* +================= +S_Base_HearingThroughEntity + +Also see S_AL_HearingThroughEntity +================= +*/ +static qboolean S_Base_HearingThroughEntity( int entityNum, vec3_t origin ) +{ + float distanceSq; + vec3_t sorigin; + + if (origin) + VectorCopy(origin, sorigin); + else + VectorCopy(loopSounds[entityNum].origin, sorigin); + + if( listener_number == entityNum ) + { + // FIXME: 28/02/06 This is an outrageous hack to detect + // whether or not the player is rendering in third person or not. We can't + // ask the renderer because the renderer has no notion of entities and we + // can't ask cgame since that would involve changing the API and hence mod + // compatibility. I don't think there is any way around this, but I'll leave + // the FIXME just in case anyone has a bright idea. + distanceSq = DistanceSquared( + sorigin, + listener_origin ); + + if( distanceSq > THIRD_PERSON_THRESHOLD_SQ ) + return qfalse; //we're the player, but third person + else + return qtrue; //we're the player + } + else + return qfalse; //not the player +} + /* ==================== -S_StartSound +S_Base_StartSoundEx Validates the parms and ques the sound up -if pos is NULL, the sound will be dynamically sourced from the entity +if origin is NULL, the sound will be dynamically sourced from the entity Entchannel 0 will never override a playing sound ==================== */ -void S_Base_StartSound(vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle ) { +static void S_Base_StartSoundEx( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle, qboolean localSound ) { channel_t *ch; sfx_t *sfx; int i, oldest, chosen, time; int inplay, allowed; + qboolean fullVolume; if ( !s_soundStarted || s_soundMuted ) { return; @@ -519,6 +558,11 @@ void S_Base_StartSound(vec3_t origin, int entityNum, int entchannel, sfxHandle_t allowed = 8; } + fullVolume = qfalse; + if (localSound || S_Base_HearingThroughEntity(entityNum, origin)) { + fullVolume = qtrue; + } + ch = s_channels; inplay = 0; for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) { @@ -594,8 +638,19 @@ void S_Base_StartSound(vec3_t origin, int entityNum, int entchannel, sfxHandle_t ch->leftvol = ch->master_vol; // these will get calced at next spatialize ch->rightvol = ch->master_vol; // unless the game isn't running ch->doppler = qfalse; + ch->fullVolume = fullVolume; } +/* +==================== +S_StartSound + +if origin is NULL, the sound will be dynamically sourced from the entity +==================== +*/ +void S_Base_StartSound( vec3_t origin, int entityNum, int entchannel, sfxHandle_t sfxHandle ) { + S_Base_StartSoundEx( origin, entityNum, entchannel, sfxHandle, qfalse ); +} /* ================== @@ -612,7 +667,7 @@ void S_Base_StartLocalSound( sfxHandle_t sfxHandle, int channelNum ) { return; } - S_Base_StartSound (NULL, listener_number, channelNum, sfxHandle ); + S_Base_StartSoundEx( NULL, listener_number, channelNum, sfxHandle, qtrue ); } @@ -872,6 +927,7 @@ void S_AddLoopSounds (void) { ch->doppler = loop->doppler; ch->dopplerScale = loop->dopplerScale; ch->oldDopplerScale = loop->oldDopplerScale; + ch->fullVolume = qfalse; numLoopChannels++; if (numLoopChannels == MAX_CHANNELS) { return; @@ -1071,8 +1127,8 @@ void S_Base_Respatialize( int entityNum, const vec3_t head, vec3_t axis[3], int if ( !ch->thesfx ) { continue; } - // anything coming from the view entity will always be full volume - if (ch->entnum == listener_number) { + // local and first person sounds will always be full volume + if (ch->fullVolume) { ch->leftvol = ch->master_vol; ch->rightvol = ch->master_vol; } else { diff --git a/code/client/snd_local.h b/code/client/snd_local.h index 29783c1c..66f3bcde 100644 --- a/code/client/snd_local.h +++ b/code/client/snd_local.h @@ -74,6 +74,8 @@ typedef struct { #define MAX_DOPPLER_SCALE 50.0f //arbitrary +#define THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f) + typedef struct loopSound_s { vec3_t origin; vec3_t velocity; @@ -102,6 +104,7 @@ typedef struct qboolean fixed_origin; // use origin instead of fetching entnum's origin sfx_t *thesfx; // sfx structure qboolean doppler; + qboolean fullVolume; } channel_t; diff --git a/code/client/snd_openal.c b/code/client/snd_openal.c index 9b307d5f..4b25d69f 100644 --- a/code/client/snd_openal.c +++ b/code/client/snd_openal.c @@ -574,9 +574,6 @@ static void _S_AL_SanitiseVector( vec3_t v, int line ) } } - -#define AL_THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f) - /* ================= S_AL_Gain @@ -635,6 +632,8 @@ static void S_AL_ScaleGain(src_t *chksrc, vec3_t origin) /* ================= S_AL_HearingThroughEntity + +Also see S_Base_HearingThroughEntity ================= */ static qboolean S_AL_HearingThroughEntity( int entityNum ) @@ -653,7 +652,7 @@ static qboolean S_AL_HearingThroughEntity( int entityNum ) entityList[ entityNum ].origin, lastListenerOrigin ); - if( distanceSq > AL_THIRD_PERSON_THRESHOLD_SQ ) + if( distanceSq > THIRD_PERSON_THRESHOLD_SQ ) return qfalse; //we're the player, but third person else return qtrue; //we're the player