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.)

This commit is contained in:
Zack Middleton 2012-10-17 20:39:45 +00:00
parent ce9f2ee5f9
commit d49d0753eb
3 changed files with 68 additions and 10 deletions

View file

@ -471,20 +471,59 @@ void S_SpatializeOrigin (vec3_t origin, int master_vol, int *left_vol, int *righ
// Start a sound effect // 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: <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 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 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; channel_t *ch;
sfx_t *sfx; sfx_t *sfx;
int i, oldest, chosen, time; int i, oldest, chosen, time;
int inplay, allowed; int inplay, allowed;
qboolean fullVolume;
if ( !s_soundStarted || s_soundMuted ) { if ( !s_soundStarted || s_soundMuted ) {
return; return;
@ -519,6 +558,11 @@ void S_Base_StartSound(vec3_t origin, int entityNum, int entchannel, sfxHandle_t
allowed = 8; allowed = 8;
} }
fullVolume = qfalse;
if (localSound || S_Base_HearingThroughEntity(entityNum, origin)) {
fullVolume = qtrue;
}
ch = s_channels; ch = s_channels;
inplay = 0; inplay = 0;
for ( i = 0; i < MAX_CHANNELS ; i++, ch++ ) { 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->leftvol = ch->master_vol; // these will get calced at next spatialize
ch->rightvol = ch->master_vol; // unless the game isn't running ch->rightvol = ch->master_vol; // unless the game isn't running
ch->doppler = qfalse; 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; 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->doppler = loop->doppler;
ch->dopplerScale = loop->dopplerScale; ch->dopplerScale = loop->dopplerScale;
ch->oldDopplerScale = loop->oldDopplerScale; ch->oldDopplerScale = loop->oldDopplerScale;
ch->fullVolume = qfalse;
numLoopChannels++; numLoopChannels++;
if (numLoopChannels == MAX_CHANNELS) { if (numLoopChannels == MAX_CHANNELS) {
return; return;
@ -1071,8 +1127,8 @@ void S_Base_Respatialize( int entityNum, const vec3_t head, vec3_t axis[3], int
if ( !ch->thesfx ) { if ( !ch->thesfx ) {
continue; continue;
} }
// anything coming from the view entity will always be full volume // local and first person sounds will always be full volume
if (ch->entnum == listener_number) { if (ch->fullVolume) {
ch->leftvol = ch->master_vol; ch->leftvol = ch->master_vol;
ch->rightvol = ch->master_vol; ch->rightvol = ch->master_vol;
} else { } else {

View file

@ -74,6 +74,8 @@ typedef struct {
#define MAX_DOPPLER_SCALE 50.0f //arbitrary #define MAX_DOPPLER_SCALE 50.0f //arbitrary
#define THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f)
typedef struct loopSound_s { typedef struct loopSound_s {
vec3_t origin; vec3_t origin;
vec3_t velocity; vec3_t velocity;
@ -102,6 +104,7 @@ typedef struct
qboolean fixed_origin; // use origin instead of fetching entnum's origin qboolean fixed_origin; // use origin instead of fetching entnum's origin
sfx_t *thesfx; // sfx structure sfx_t *thesfx; // sfx structure
qboolean doppler; qboolean doppler;
qboolean fullVolume;
} channel_t; } channel_t;

View file

@ -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 S_AL_Gain
@ -635,6 +632,8 @@ static void S_AL_ScaleGain(src_t *chksrc, vec3_t origin)
/* /*
================= =================
S_AL_HearingThroughEntity S_AL_HearingThroughEntity
Also see S_Base_HearingThroughEntity
================= =================
*/ */
static qboolean S_AL_HearingThroughEntity( int entityNum ) static qboolean S_AL_HearingThroughEntity( int entityNum )
@ -653,7 +652,7 @@ static qboolean S_AL_HearingThroughEntity( int entityNum )
entityList[ entityNum ].origin, entityList[ entityNum ].origin,
lastListenerOrigin ); lastListenerOrigin );
if( distanceSq > AL_THIRD_PERSON_THRESHOLD_SQ ) if( distanceSq > THIRD_PERSON_THRESHOLD_SQ )
return qfalse; //we're the player, but third person return qfalse; //we're the player, but third person
else else
return qtrue; //we're the player return qtrue; //we're the player