Skip to content

Commit

Permalink
engine: client: fix sound mute when losing focus
Browse files Browse the repository at this point in the history
  • Loading branch information
a1batross committed Mar 3, 2024
1 parent 505b6cc commit 7584bbe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
8 changes: 7 additions & 1 deletion engine/client/s_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CVAR_DEFINE_AUTO( s_lerping, "0", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "apply interpo
static CVAR_DEFINE( s_ambient_level, "ambient_level", "0.3", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "volume of environment noises (water and wind)" );
static CVAR_DEFINE( s_ambient_fade, "ambient_fade", "1000", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "rate of volume fading when client is moving" );
static CVAR_DEFINE_AUTO( s_combine_sounds, "0", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "combine channels with same sounds" );
CVAR_DEFINE_AUTO( snd_mute_losefocus, "1", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "silence the audio when game window loses focus" );
static CVAR_DEFINE_AUTO( snd_mute_losefocus, "1", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "silence the audio when game window loses focus" );
CVAR_DEFINE_AUTO( s_test, "0", 0, "engine developer cvar for quick testing new features" );
CVAR_DEFINE_AUTO( s_samplecount, "0", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "sample count (0 for default value)" );
CVAR_DEFINE_AUTO( s_warn_late_precache, "0", FCVAR_ARCHIVE|FCVAR_FILTERABLE, "warn about late precached sounds on client-side" );
Expand All @@ -64,6 +64,12 @@ float S_GetMasterVolume( void )
{
float scale = 1.0f;

if( host.status == HOST_NOFOCUS && snd_mute_losefocus.value != 0.0f )
{
// we return zero volume to keep sounds running
return 0.0f;
}

if( !s_listener.inmenu && soundfade.percent != 0 )
{
scale = bound( 0.0f, soundfade.percent / 100.0f, 1.0f );
Expand Down
1 change: 0 additions & 1 deletion engine/client/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ extern convar_t s_musicvolume;
extern convar_t s_lerping;
extern convar_t s_test; // cvar to testify new effects
extern convar_t s_samplecount;
extern convar_t snd_mute_losefocus;
extern convar_t s_warn_late_precache;

void S_InitScaletable( void );
Expand Down
12 changes: 0 additions & 12 deletions engine/platform/sdl/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,8 @@ static void SDLash_ActiveEvent( int gain )
{
host.status = HOST_FRAME;
if( cls.key_dest == key_game )
{
IN_ActivateMouse( );
}

if( dma.initialized && snd_mute_losefocus.value )
{
SNDDMA_Activate( true );
}
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
if( vid_fullscreen.value == WINDOW_MODE_FULLSCREEN )
VID_SetMode();
Expand All @@ -397,14 +391,8 @@ static void SDLash_ActiveEvent( int gain )
#endif
host.status = HOST_NOFOCUS;
if( cls.key_dest == key_game )
{
IN_DeactivateMouse();
}

if( dma.initialized && snd_mute_losefocus.value )
{
SNDDMA_Activate( false );
}
host.force_draw_version_time = host.realtime + 2.0;
VID_RestoreScreenResolution();
}
Expand Down

0 comments on commit 7584bbe

Please sign in to comment.