diff options
author | Tim Angus <tim@ngus.net> | 2006-02-28 23:11:58 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2006-02-28 23:11:58 +0000 |
commit | 3ced489436f10c94c37a02103c3be535bf65a14a (patch) | |
tree | b123b483be5806eadbbdcc4dff786c95eb23f5c9 | |
parent | b3cd0a8f2b4610787ff5f8cf0147d36b6eb52c18 (diff) |
* Merged ioq3-r594
- OpenAL fixes
- SV_Shutdown message fixes
-rw-r--r-- | src/client/cl_main.c | 2 | ||||
-rw-r--r-- | src/client/snd_openal.c | 113 | ||||
-rw-r--r-- | src/qcommon/common.c | 8 | ||||
-rw-r--r-- | src/server/sv_init.c | 2 | ||||
-rw-r--r-- | src/server/sv_main.c | 2 |
5 files changed, 96 insertions, 31 deletions
diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 093cbc58..78ff243b 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -1015,7 +1015,7 @@ void CL_Connect_f( void ) { if ( com_sv_running->integer && !strcmp( server, "localhost" ) ) { // if running a local server, kill it - SV_Shutdown( "Server quit\n" ); + SV_Shutdown( "Server quit" ); } // make sure a local server is killed diff --git a/src/client/snd_openal.c b/src/client/snd_openal.c index fa1aaad0..c44f1e0a 100644 --- a/src/client/snd_openal.c +++ b/src/client/snd_openal.c @@ -40,7 +40,6 @@ cvar_t *s_alMinDistance; cvar_t *s_alRolloff; cvar_t *s_alDriver; cvar_t *s_alMaxSpeakerDistance; -cvar_t *s_alSpatEntOrigin; /* ================= @@ -504,6 +503,39 @@ static void _S_AL_SanitiseVector( vec3_t v, int line ) } } + +#define AL_THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f) + +/* +================= +S_AL_HearingThroughEntity +================= +*/ +static qboolean S_AL_HearingThroughEntity( int entityNum ) +{ + float distanceSq; + + if( clc.clientNum == 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( + entityList[ entityNum ].origin, + lastListenerOrigin ); + + if( distanceSq > AL_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_AL_SrcInit @@ -579,7 +611,6 @@ static void S_AL_SrcSetup(srcHandle_t src, sfxHandle_t sfx, alSrcPriority_t prio int entity, int channel, qboolean local) { ALuint buffer; - float null_vector[] = {0, 0, 0}; // Mark the SFX as used, and grab the raw AL buffer S_AL_BufferUse(sfx); @@ -601,15 +632,15 @@ static void S_AL_SrcSetup(srcHandle_t src, sfxHandle_t sfx, alSrcPriority_t prio qalSourcei(srcList[src].alSource, AL_BUFFER, buffer); qalSourcef(srcList[src].alSource, AL_PITCH, 1.0f); qalSourcef(srcList[src].alSource, AL_GAIN, s_alGain->value * s_volume->value); - qalSourcefv(srcList[src].alSource, AL_POSITION, null_vector); - qalSourcefv(srcList[src].alSource, AL_VELOCITY, null_vector); + qalSourcefv(srcList[src].alSource, AL_POSITION, vec3_origin); + qalSourcefv(srcList[src].alSource, AL_VELOCITY, vec3_origin); qalSourcei(srcList[src].alSource, AL_LOOPING, AL_FALSE); qalSourcef(srcList[src].alSource, AL_REFERENCE_DISTANCE, s_alMinDistance->value); if(local) { qalSourcei(srcList[src].alSource, AL_SOURCE_RELATIVE, AL_TRUE); - qalSourcef(srcList[src].alSource, AL_ROLLOFF_FACTOR, 0); + qalSourcef(srcList[src].alSource, AL_ROLLOFF_FACTOR, 0.0f); } else { @@ -655,6 +686,7 @@ static void S_AL_SrcKill(srcHandle_t src) srcList[src].isLocked = qfalse; srcList[src].isLooping = qfalse; srcList[src].isTracking = qfalse; + srcList[src].local = qfalse; } /* @@ -827,17 +859,30 @@ void S_AL_StartSound( vec3_t origin, int entnum, int entchannel, sfxHandle_t sfx return; // Set up the effect - S_AL_SrcSetup(src, sfx, SRCPRI_ONESHOT, entnum, entchannel, qfalse); - - if(origin == NULL) + if( origin == NULL ) { - srcList[src].isTracking = qtrue; - VectorCopy( entityList[entnum].origin, sorigin ); + srcList[ src ].isTracking = qtrue; + + if( S_AL_HearingThroughEntity( entnum ) ) + { + // Where the entity is the local player, play a local sound + S_AL_SrcSetup( src, sfx, SRCPRI_ONESHOT, entnum, entchannel, qtrue ); + VectorClear( sorigin ); + } + else + { + S_AL_SrcSetup( src, sfx, SRCPRI_ONESHOT, entnum, entchannel, qfalse ); + VectorCopy( entityList[ entnum ].origin, sorigin ); + } } else + { + S_AL_SrcSetup( src, sfx, SRCPRI_ONESHOT, entnum, entchannel, qfalse ); VectorCopy( origin, sorigin ); + } + S_AL_SanitiseVector( sorigin ); - qalSourcefv(srcList[src].alSource, AL_POSITION, sorigin); + qalSourcefv( srcList[ src ].alSource, AL_POSITION, sorigin ); // Start it playing qalSourcePlay(srcList[src].alSource); @@ -904,9 +949,20 @@ static void S_AL_SrcLoop( alSrcPriority_t priority, sfxHandle_t sfx, srcList[ src ].isLooping = qtrue; srcList[ src ].isActive = qtrue; - // Set up the position and velocity - qalSourcefv( srcList[ src ].alSource, AL_POSITION, (ALfloat *)sent->origin ); - qalSourcefv( srcList[ src ].alSource, AL_VELOCITY, (ALfloat *)velocity ); + if( S_AL_HearingThroughEntity( entityNum ) ) + { + srcList[ src ].local = qtrue; + + qalSourcefv( srcList[ src ].alSource, AL_POSITION, vec3_origin ); + qalSourcefv( srcList[ src ].alSource, AL_VELOCITY, vec3_origin ); + } + else + { + srcList[ src ].local = qfalse; + + qalSourcefv( srcList[ src ].alSource, AL_POSITION, (ALfloat *)sent->origin ); + qalSourcefv( srcList[ src ].alSource, AL_VELOCITY, (ALfloat *)velocity ); + } } /* @@ -1007,13 +1063,25 @@ void S_AL_SrcUpdate( void ) if( sent->startLoopingSound ) { S_AL_SrcSetup( i, sent->loopSfx, sent->loopPriority, - entityNum, -1, qfalse ); + entityNum, -1, srcList[ i ].local ); srcList[ i ].isLooping = qtrue; qalSourcei( srcList[ i ].alSource, AL_LOOPING, AL_TRUE ); qalSourcePlay( srcList[ i ].alSource ); sent->startLoopingSound = qfalse; } + + // Update locality + if( srcList[ i ].local) + { + qalSourcei( srcList[ i ].alSource, AL_SOURCE_RELATIVE, AL_TRUE ); + qalSourcef( srcList[ i ].alSource, AL_ROLLOFF_FACTOR, 0.0f ); + } + else + { + qalSourcei( srcList[ i ].alSource, AL_SOURCE_RELATIVE, AL_FALSE ); + qalSourcef( srcList[ i ].alSource, AL_ROLLOFF_FACTOR, s_alRolloff->value ); + } } else S_AL_SrcKill( i ); @@ -1021,8 +1089,11 @@ void S_AL_SrcUpdate( void ) continue; } + // Query relativity of source, don't move if it's true + qalGetSourcei( srcList[ i ].alSource, AL_SOURCE_RELATIVE, &state ); + // See if it needs to be moved - if(srcList[i].isTracking) + if( srcList[ i ].isTracking && !state ) qalSourcefv(srcList[i].alSource, AL_POSITION, entityList[entityNum].origin); // Check if it's done, and flag it @@ -1482,13 +1553,8 @@ void S_AL_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int float orientation[6]; vec3_t sorigin; - if( s_alSpatEntOrigin->integer && entityNum >= 0 ) - VectorCopy( entityList[ entityNum ].origin, sorigin ); - else - { - VectorCopy( origin, sorigin ); - S_AL_SanitiseVector( sorigin ); - } + VectorCopy( origin, sorigin ); + S_AL_SanitiseVector( sorigin ); S_AL_SanitiseVector( axis[ 0 ] ); S_AL_SanitiseVector( axis[ 1 ] ); @@ -1657,7 +1723,6 @@ qboolean S_AL_Init( soundInterface_t *si ) s_alMinDistance = Cvar_Get( "s_alMinDistance", "120", CVAR_CHEAT ); s_alRolloff = Cvar_Get( "s_alRolloff", "0.8", CVAR_CHEAT ); s_alMaxSpeakerDistance = Cvar_Get( "s_alMaxSpeakerDistance", "1024", CVAR_ARCHIVE ); - s_alSpatEntOrigin = Cvar_Get( "s_alSpatEntOrigin", "0", CVAR_ARCHIVE ); s_alDriver = Cvar_Get( "s_alDriver", ALDRIVER_DEFAULT, CVAR_ARCHIVE ); diff --git a/src/qcommon/common.c b/src/qcommon/common.c index 15f36f00..5c3726ff 100644 --- a/src/qcommon/common.c +++ b/src/qcommon/common.c @@ -283,13 +283,13 @@ void QDECL Com_Error( int code, const char *fmt, ... ) { longjmp (abortframe, -1); } else if ( code == ERR_DROP || code == ERR_DISCONNECT ) { Com_Printf ("********************\nERROR: %s\n********************\n", com_errorMessage); - SV_Shutdown (va("Server crashed: %s\n", com_errorMessage)); + SV_Shutdown (va("Server crashed: %s", com_errorMessage)); CL_Disconnect( qtrue ); CL_FlushMemory( ); com_errorEntered = qfalse; longjmp (abortframe, -1); } else if ( code == ERR_NEED_CD ) { - SV_Shutdown( "Server didn't have CD\n" ); + SV_Shutdown( "Server didn't have CD" ); if ( com_cl_running && com_cl_running->integer ) { CL_Disconnect( qtrue ); CL_FlushMemory( ); @@ -301,7 +301,7 @@ void QDECL Com_Error( int code, const char *fmt, ... ) { longjmp (abortframe, -1); } else { CL_Shutdown (); - SV_Shutdown (va("Server fatal crashed: %s\n", com_errorMessage)); + SV_Shutdown (va("Server fatal crashed: %s", com_errorMessage)); } Com_Shutdown (); @@ -321,7 +321,7 @@ do the apropriate things. void Com_Quit_f( void ) { // don't try to shutdown if we are in a recursive error if ( !com_errorEntered ) { - SV_Shutdown ("Server quit\n"); + SV_Shutdown ("Server quit"); CL_Shutdown (); Com_Shutdown (); FS_Shutdown(qtrue); diff --git a/src/server/sv_init.c b/src/server/sv_init.c index 4adff6f2..251dfcac 100644 --- a/src/server/sv_init.c +++ b/src/server/sv_init.c @@ -639,7 +639,7 @@ void SV_FinalMessage( char *message ) { if (cl->state >= CS_CONNECTED) { // don't send a disconnect to a local client if ( cl->netchan.remoteAddress.type != NA_LOOPBACK ) { - SV_SendServerCommand( cl, "print \"%s\"", message ); + SV_SendServerCommand( cl, "print \"%s\"\n", message ); SV_SendServerCommand( cl, "disconnect" ); } // force a snapshot to be sent diff --git a/src/server/sv_main.c b/src/server/sv_main.c index adc472ed..f6d5a7c4 100644 --- a/src/server/sv_main.c +++ b/src/server/sv_main.c @@ -787,7 +787,7 @@ void SV_Frame( int msec ) { // the menu kills the server with this cvar if ( sv_killserver->integer ) { - SV_Shutdown ("Server was killed.\n"); + SV_Shutdown ("Server was killed"); Cvar_Set( "sv_killserver", "0" ); return; } |