[quake3-commits] r2326 - trunk/code/client

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Oct 17 16:39:45 EDT 2012


Author: ztm
Date: 2012-10-17 16:39:45 -0400 (Wed, 17 Oct 2012)
New Revision: 2326

Modified:
   trunk/code/client/snd_dma.c
   trunk/code/client/snd_local.h
   trunk/code/client/snd_openal.c
Log:
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.)

Modified: trunk/code/client/snd_dma.c
===================================================================
--- trunk/code/client/snd_dma.c	2012-10-17 19:30:41 UTC (rev 2325)
+++ trunk/code/client/snd_dma.c	2012-10-17 20:39:45 UTC (rev 2326)
@@ -472,19 +472,58 @@
 // =======================================================================
 
 /*
+=================
+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 at 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 @@
 		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,9 +638,20 @@
 	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 );
+}
+
 /*
 ==================
 S_StartLocalSound
@@ -612,7 +667,7 @@
 		return;
 	}
 
-	S_Base_StartSound (NULL, listener_number, channelNum, sfxHandle );
+	S_Base_StartSoundEx( NULL, listener_number, channelNum, sfxHandle, qtrue );
 }
 
 
@@ -872,6 +927,7 @@
 		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 @@
 		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 {

Modified: trunk/code/client/snd_local.h
===================================================================
--- trunk/code/client/snd_local.h	2012-10-17 19:30:41 UTC (rev 2325)
+++ trunk/code/client/snd_local.h	2012-10-17 20:39:45 UTC (rev 2326)
@@ -74,6 +74,8 @@
 
 #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 @@
 	qboolean	fixed_origin;	// use origin instead of fetching entnum's origin
 	sfx_t		*thesfx;		// sfx structure
 	qboolean	doppler;
+	qboolean	fullVolume;
 } channel_t;
 
 

Modified: trunk/code/client/snd_openal.c
===================================================================
--- trunk/code/client/snd_openal.c	2012-10-17 19:30:41 UTC (rev 2325)
+++ trunk/code/client/snd_openal.c	2012-10-17 20:39:45 UTC (rev 2326)
@@ -574,9 +574,6 @@
 	}
 }
 
-
-#define AL_THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f)
-
 /*
 =================
 S_AL_Gain
@@ -635,6 +632,8 @@
 /*
 =================
 S_AL_HearingThroughEntity
+
+Also see S_Base_HearingThroughEntity
 =================
 */
 static qboolean S_AL_HearingThroughEntity( int entityNum )
@@ -653,7 +652,7 @@
 				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



More information about the quake3-commits mailing list