diff options
author | Zack Middleton <zturtleman@gmail.com> | 2012-10-17 20:39:45 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-12 20:48:53 +0000 |
commit | 7dd5613627371177d89b4807e6be1a0a93600a8f (patch) | |
tree | 748aa3433b12691045c8fcbefd1156940d40025f /src | |
parent | dcefbc80d07e9453dc8f1109687f6325960a6b48 (diff) |
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.)
Diffstat (limited to 'src')
-rw-r--r-- | src/client/snd_dma.c | 68 | ||||
-rw-r--r-- | src/client/snd_local.h | 3 | ||||
-rw-r--r-- | src/client/snd_openal.c | 7 |
3 files changed, 68 insertions, 10 deletions
diff --git a/src/client/snd_dma.c b/src/client/snd_dma.c index 4eb94e4c..5a333526 100644 --- a/src/client/snd_dma.c +++ b/src/client/snd_dma.c @@ -488,19 +488,58 @@ void S_SpatializeOrigin (vec3_t origin, int master_vol, int *left_vol, int *righ // ======================================================================= /* +================= +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: <tim@ngus.net> 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; @@ -535,6 +574,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++ ) { @@ -610,8 +654,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 ); +} /* ================== @@ -628,7 +683,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 ); } @@ -888,6 +943,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; @@ -1087,8 +1143,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/src/client/snd_local.h b/src/client/snd_local.h index f139fa5e..0c404cf2 100644 --- a/src/client/snd_local.h +++ b/src/client/snd_local.h @@ -76,6 +76,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; @@ -104,6 +106,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/src/client/snd_openal.c b/src/client/snd_openal.c index ce669f1d..bded5184 100644 --- a/src/client/snd_openal.c +++ b/src/client/snd_openal.c @@ -593,9 +593,6 @@ static void _S_AL_SanitiseVector( vec3_t v, int line ) } } - -#define AL_THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f) - /* ================= S_AL_Gain @@ -654,6 +651,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 ) @@ -672,7 +671,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 |