IOQ3 commit 2326

This commit is contained in:
Richard Allen 2012-12-12 19:38:04 +00:00
parent e7569e8956
commit 71b38430cc
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
// =======================================================================
/*
=================
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;
@ -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 {

View file

@ -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;

View file

@ -684,9 +684,6 @@ static void _S_AL_SanitiseVector( vec3_t v, int line )
}
}
#define AL_THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f)
/*
=================
S_AL_Gain
@ -747,6 +744,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 )
@ -765,7 +764,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