From eb8d03f4793882c5c0e945c1a6b1fc9989536b48 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 11 Jan 2023 18:22:06 -0800 Subject: [PATCH] Do not disable and reenable sounds entirely when window focus changes Sounds are not started if the window is unfocused, regardless of sound_disabled. Fixes -nosound not working (sounds would always be reenabled if window comes into focus). --- src/s_sound.c | 27 ++------------------------- src/sdl/i_video.cpp | 5 +---- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 0d3746d33..d45a3fd7d 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2331,24 +2331,6 @@ void S_ResumeAudio(void) S_AdjustMusicStackTics(); } -void S_DisableSound(void) -{ - if (sound_started && !sound_disabled) - { - sound_disabled = true; - S_StopSounds(); - } -} - -void S_EnableSound(void) -{ - if (sound_started && sound_disabled) - { - sound_disabled = false; - S_InitSfxChannels(cv_soundvolume.value); - } -} - void S_SetMusicVolume(INT32 digvolume) { if (digvolume < 0) @@ -2698,13 +2680,8 @@ static void PlaySoundIfUnfocused_OnChange(void) if (!cv_gamesounds.value) return; - if (window_notinfocus) - { - if (cv_playsoundifunfocused.value) - S_DisableSound(); - else - S_EnableSound(); - } + if (window_notinfocus && cv_playsoundifunfocused.value) + S_StopSounds(); } #ifdef HAVE_OPENMPT diff --git a/src/sdl/i_video.cpp b/src/sdl/i_video.cpp index 715c9ebf9..a3bb4d18b 100644 --- a/src/sdl/i_video.cpp +++ b/src/sdl/i_video.cpp @@ -614,9 +614,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) S_InitMusicVolume(); - if (cv_gamesounds.value) - S_EnableSound(); - if (!firsttimeonmouse) { if (cv_usemouse.value) I_StartupMouse(); @@ -633,7 +630,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (!cv_playmusicifunfocused.value) I_SetMusicVolume(0); if (!cv_playsoundifunfocused.value) - S_DisableSound(); + S_StopSounds(); if (!disable_mouse) {