Skip to content

Commit

Permalink
snd_mute_losefocus
Browse files Browse the repository at this point in the history
  • Loading branch information
Bucky21659 committed Mar 21, 2019
1 parent c903375 commit ba0a05b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
22 changes: 21 additions & 1 deletion codemp/client/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ cvar_t *s_debugdynamic;

cvar_t *s_doppler;

cvar_t *snd_mute_losefocus;

typedef struct
{
unsigned char volume;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand All @@ -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 ));
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions codemp/client/snd_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 6 additions & 2 deletions shared/sdl/sdl_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit ba0a05b

Please sign in to comment.