From 79012d00e8ec8531a278a1f250dcf911daefd3a0 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 08:33:49 -0800 Subject: [PATCH] Sound options: merge playmusicifunfocused/playsoundifunfocused into one cvar --- src/cvars.cpp | 12 ++++++---- src/menus/options-sound.cpp | 7 ++---- src/s_sound.c | 44 +++++++++++++++++-------------------- src/s_sound.h | 3 +-- src/sdl/i_video.cpp | 4 ++-- 5 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/cvars.cpp b/src/cvars.cpp index a4236908f..e90ad1f86 100644 --- a/src/cvars.cpp +++ b/src/cvars.cpp @@ -406,10 +406,14 @@ extern CV_PossibleValue_t perfstats_cons_t[]; consvar_t cv_perfstats = Player("perfstats", "Off").dont_save().values(perfstats_cons_t); // Window focus sound sytem toggles -void PlayMusicIfUnfocused_OnChange(void); -void PlaySoundIfUnfocused_OnChange(void); -consvar_t cv_playmusicifunfocused = Player("playmusicifunfocused", "No").yes_no().onchange_noinit(PlayMusicIfUnfocused_OnChange); -consvar_t cv_playsoundifunfocused = Player("playsoundsifunfocused", "No").yes_no().onchange_noinit(PlaySoundIfUnfocused_OnChange); +void BGAudio_OnChange(void); +void BGAudio_OnChange(void); +consvar_t cv_bgaudio = Player("bgaudio", "Nothing").onchange_noinit(BGAudio_OnChange).values({ + {0, "Nothing"}, + {1, "Music"}, + {2, "Sounds"}, + {3, "Music&Sounds"}, +}); // Pause game upon window losing focus consvar_t cv_pauseifunfocused = Player("pauseifunfocused", "Yes").yes_no(); diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index 27c545f24..3b6d2a819 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -238,11 +238,8 @@ menuitem_t OPTIONS_Sound[] = {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, - {IT_STRING | IT_CVAR, "Play Music While Unfocused", "Keeps playing music even if the game is not the active window.", - NULL, {.cvar = &cv_playmusicifunfocused}, 0, 0}, - - {IT_STRING | IT_CVAR, "Play SFX While Unfocused", "Keeps playing sound effects even if the game is not the active window.", - NULL, {.cvar = &cv_playsoundifunfocused}, 0, 0}, + {IT_STRING | IT_CVAR, "Hear Tabbed-out", "Keep playing game audio when the window is out of focus (FOCUS LOST).", + NULL, {.cvar = &cv_bgaudio}, 0, 0}, // @TODO: Sound test (there's currently no space on this menu, might be better to throw it in extras?) }; diff --git a/src/s_sound.c b/src/s_sound.c index 5c1dfef0c..f765669d2 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -248,7 +248,7 @@ boolean S_SoundDisabled(void) { return ( sound_disabled || - ( window_notinfocus && ! cv_playsoundifunfocused.value ) + ( window_notinfocus && ! (cv_bgaudio.value & 2) ) ); } @@ -2168,7 +2168,7 @@ boolean S_MusicDisabled(void) boolean S_MusicNotInFocus(void) { return ( - ( window_notinfocus && ! cv_playmusicifunfocused.value ) + ( window_notinfocus && ! (cv_bgaudio.value & 1) ) ); } @@ -2521,28 +2521,6 @@ void GameDigiMusic_OnChange(void) } } -void PlayMusicIfUnfocused_OnChange(void); -void PlayMusicIfUnfocused_OnChange(void) -{ - if (window_notinfocus) - { - if (cv_playmusicifunfocused.value) - I_SetMusicVolume(0); - else - S_SetMusicVolume(); - } -} - -void PlaySoundIfUnfocused_OnChange(void); -void PlaySoundIfUnfocused_OnChange(void) -{ - if (!cv_gamesounds.value) - return; - - if (window_notinfocus && !cv_playsoundifunfocused.value) - S_StopSounds(); -} - void MasterVolume_OnChange(void); void MasterVolume_OnChange(void) { @@ -2570,3 +2548,21 @@ void SoundVolume_OnChange(void) } CV_StealthSetValue(&cv_mastervolume, max(cv_digmusicvolume.value, cv_soundvolume.value)); } + +void BGAudio_OnChange(void); +void BGAudio_OnChange(void) +{ + if (window_notinfocus) + { + if (cv_bgaudio.value & 1) + I_SetMusicVolume(0); + else + S_SetMusicVolume(); + } + + if (!cv_gamesounds.value) + return; + + if (window_notinfocus && !(cv_bgaudio.value & 2)) + S_StopSounds(); +} diff --git a/src/s_sound.h b/src/s_sound.h index 216dc1a55..5d6b17ecf 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -41,8 +41,7 @@ extern consvar_t cv_numChannels; extern consvar_t cv_gamedigimusic; extern consvar_t cv_gamesounds; -extern consvar_t cv_playmusicifunfocused; -extern consvar_t cv_playsoundifunfocused; +extern consvar_t cv_bgaudio; typedef enum { diff --git a/src/sdl/i_video.cpp b/src/sdl/i_video.cpp index c2d42f009..2d9d4b2c1 100644 --- a/src/sdl/i_video.cpp +++ b/src/sdl/i_video.cpp @@ -538,9 +538,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { // Tell game we lost focus, pause music window_notinfocus = true; - if (!cv_playmusicifunfocused.value) + if (!(cv_bgaudio.value & 1)) I_SetMusicVolume(0); - if (!cv_playsoundifunfocused.value) + if (!(cv_bgaudio.value & 2)) S_StopSounds(); if (!disable_mouse)