diff --git a/codemp/client/snd_dma.cpp b/codemp/client/snd_dma.cpp index d6c303cdc0..771b4cb88a 100644 --- a/codemp/client/snd_dma.cpp +++ b/codemp/client/snd_dma.cpp @@ -194,6 +194,8 @@ cvar_t *s_debugdynamic; cvar_t *s_doppler; +cvar_t *snd_mute_losefocus; + typedef struct { unsigned char volume; @@ -475,6 +477,8 @@ void S_Init( void ) { s_doppler = Cvar_Get("s_doppler", "1", CVAR_ARCHIVE_ND); + snd_mute_losefocus = Cvar_Get("snd_mute_losefocus", "1", CVAR_ARCHIVE, "Mute sound when game window is unfocused/minimized"); + MP3_InitCvars(); cv = Cvar_Get ("s_initsound", "1", 0); @@ -805,6 +809,7 @@ sfx_t *S_FindName( const char *name ) { sfx_t *sfx; +#if 0 if (!name) { Com_Error (ERR_FATAL, "S_FindName: NULL"); } @@ -815,6 +820,21 @@ sfx_t *S_FindName( const char *name ) { if (strlen(name) >= MAX_QPATH) { Com_Error (ERR_FATAL, "Sound name too long: %s", name); } +#else + if (!name) { + Com_Printf("^1S_FindName: NULL\n"); + name = "sound/null.wav"; + } + if (!name[0]) { + Com_Printf("^1S_FindName: empty name\n"); + name = "sound/null.wav"; + } + + if (strlen(name) >= MAX_QPATH) { + Com_Printf ("^1Sound name too long: %s\n", name); + name = "sound/null.wav"; + } +#endif char sSoundNameNoExt[MAX_QPATH]; COM_StripExtension(name,sSoundNameNoExt, sizeof( sSoundNameNoExt )); @@ -1558,7 +1578,7 @@ void S_StartSound(const vec3_t origin, int entityNum, int entchannel, sfxHandle_ return; } - if ( com_minimized->integer || com_unfocused->integer ) { //entchannel != CHAN_MUSIC ? + if ( (com_minimized->integer || com_unfocused->integer) && snd_mute_losefocus->integer ) { //entchannel != CHAN_MUSIC ? return; } diff --git a/codemp/client/snd_local.h b/codemp/client/snd_local.h index 62da98fc85..b217e371ca 100644 --- a/codemp/client/snd_local.h +++ b/codemp/client/snd_local.h @@ -208,6 +208,8 @@ extern cvar_t *s_separation; extern cvar_t *s_doppler; +extern cvar_t *snd_mute_losefocus; + wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength); qboolean S_LoadSound( sfx_t *sfx ); diff --git a/shared/sdl/sdl_input.cpp b/shared/sdl/sdl_input.cpp index c550318441..cec787945c 100644 --- a/shared/sdl/sdl_input.cpp +++ b/shared/sdl/sdl_input.cpp @@ -41,6 +41,8 @@ static cvar_t *in_joystickThreshold = NULL; static cvar_t *in_joystickNo = NULL; static cvar_t *in_joystickUseAnalog = NULL; +extern cvar_t *snd_mute_losefocus; + static SDL_Window *SDL_window = NULL; #define CTRL(a) ((a)-'a'+1) @@ -918,23 +920,25 @@ static void IN_ProcessEvents( int eventTime ) case SDL_WINDOWEVENT_FOCUS_LOST: { Cvar_SetValue( "com_unfocused", 1 ); - SNDDMA_Activate( qfalse ); cl_unfocusedTime = cls.realtime; #ifdef _WIN32 con_alert = qfalse; #endif + if (snd_mute_losefocus->integer) + SNDDMA_Activate(qfalse); break; } case SDL_WINDOWEVENT_FOCUS_GAINED: { Cvar_SetValue( "com_unfocused", 0 ); - SNDDMA_Activate( qtrue ); cl_unfocusedTime = 0; if (cl_afkName && cls.realtime - cl_nameModifiedTime > 5000) { CL_Afk_f(); cls.afkTime = cls.realtime; } + if (snd_mute_losefocus->integer) + SNDDMA_Activate(qtrue); break; } }