From 2d450b05f810af0fbb03e17a7233083674f8720b Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 01:12:03 -0800 Subject: [PATCH 01/11] TuneManager: clear current song if music is disabled, so music can resume later --- src/music.cpp | 5 +++++ src/music.h | 5 +++++ src/music_manager.hpp | 2 ++ src/s_sound.c | 1 + 4 files changed, 13 insertions(+) diff --git a/src/music.cpp b/src/music.cpp index 00b200a21..95ee9f12c 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -183,6 +183,11 @@ void Music_Tick(void) g_tunes.tick(); } +void Music_Flip(void) +{ + g_tunes.flip(); +} + void Music_Play(const char* id) { Tune* tune = g_tunes.find(id); diff --git a/src/music.h b/src/music.h index a85b1913f..5b53b4ba1 100644 --- a/src/music.h +++ b/src/music.h @@ -144,6 +144,11 @@ void Music_Init(void); // Call this every tic to update the music. void Music_Tick(void); +// Flips the internal state so music is reloaded next tick. +// This is required when disabling music during runtime so +// the music plays again when re-enabled. +void Music_Flip(void); + #ifdef __cplusplus } // extern "C" diff --git a/src/music_manager.hpp b/src/music_manager.hpp index 38110d46c..c3e742e00 100644 --- a/src/music_manager.hpp +++ b/src/music_manager.hpp @@ -53,6 +53,8 @@ public: return res.first->second; } + void flip() { current_song_ = {}; } + void tick(); void pause_unpause() const; diff --git a/src/s_sound.c b/src/s_sound.c index 2757b913f..bee22e443 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2515,6 +2515,7 @@ void GameDigiMusic_OnChange(void) { digital_disabled = true; I_UnloadSong(); + Music_Flip(); } } From 164e97cff465fbf2eeb6bb60c49dd371b48f0434 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 03:51:36 -0800 Subject: [PATCH 02/11] menus/options-sound.c -> menus/options-sound.cpp --- src/menus/CMakeLists.txt | 2 +- src/menus/{options-sound.c => options-sound.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/menus/{options-sound.c => options-sound.cpp} (100%) diff --git a/src/menus/CMakeLists.txt b/src/menus/CMakeLists.txt index 4e024fc55..f0d8dc4f0 100644 --- a/src/menus/CMakeLists.txt +++ b/src/menus/CMakeLists.txt @@ -25,7 +25,7 @@ target_sources(SRB2SDL2 PRIVATE options-profiles-edit-controls.c options-server-1.c options-server-advanced.c - options-sound.c + options-sound.cpp options-video-1.c options-video-gl.c options-video-modes.c diff --git a/src/menus/options-sound.c b/src/menus/options-sound.cpp similarity index 100% rename from src/menus/options-sound.c rename to src/menus/options-sound.cpp From c11c7bcbbd94cd8fccb38dce2f47893adebb87d3 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 05:59:15 -0800 Subject: [PATCH 03/11] Sound options: draw custom sliders - Greyed out when music/sounds are disabled. --- src/menus/options-sound.cpp | 161 ++++++++++++++++++++++++++++++++++-- 1 file changed, 155 insertions(+), 6 deletions(-) diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index 4137afe1e..ade008c79 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -1,24 +1,173 @@ /// \file menus/options-sound.c /// \brief Sound Options +#include +#include + +#include "../v_draw.hpp" + +#include "../console.h" #include "../k_menu.h" #include "../s_sound.h" // sounds consvars #include "../g_game.h" // cv_chatnotifications +using srb2::Draw; + +namespace +{ + +int flip_delay = 0; + +struct Slider +{ + enum Id + { + kMusicVolume, + kSfxVolume, + kNumSliders + }; + + Slider(bool(*toggle)(bool), consvar_t& volume) : toggle_(toggle), volume_(volume) {} + + bool(*toggle_)(bool); + consvar_t& volume_; + + int shake_ = 0; + + void draw(int x, int y, bool selected) + { + constexpr int kWidth = 111; + + Draw h(320 - x - kWidth, y); + + if (selected) + { + int ofs = skullAnimCounter / 5; + Draw arrows = h.font(Draw::Font::kConsole).align(Draw::Align::kLeft).flags(highlightflags); + + arrows.x(-10 - ofs).text("\x1C"); + arrows.x(kWidth + 2 + ofs).text("\x1D"); + } + + h = h.y(1); + h.size(kWidth, 7).fill(31); + + Draw s = h.xy(1, 2).size(10, 4); + int color = toggle_(false) ? aquamap[0] : 15; + + int n = volume_.value / 10; + for (int i = 0; i < n; ++i) + { + s.fill(color); + s = s.x(11); + } + + s.width(volume_.value % 10).fill(color); + + n = std::atoi(volume_.defaultvalue); + h.x(1 + shake_ + n + (n / 10)).size(1, 7).fill(35); + + if (!toggle_(false)) + { + h + .x(kWidth / 2) + .font(Draw::Font::kConsole) + .align(Draw::Align::kCenter) + .flags(V_40TRANS) + .text("S I L E N T"); + } + } + + void input(INT32 c) + { + M_ChangeCvarDirect(c, &volume_); + + shake_ = !shake_; + flip_delay = 2; + } +}; + +std::array sliders{{ + { + [](bool toggle) -> bool + { + if (toggle) + { + CV_AddValue(&cv_gamedigimusic, 1); + } + + return !S_MusicDisabled(); + }, + cv_digmusicvolume, + }, + { + [](bool toggle) -> bool + { + if (toggle) + { + CV_AddValue(&cv_gamesounds, 1); + } + + return !S_SoundDisabled(); + }, + cv_soundvolume, + }, +}}; + +void slider_routine(INT32 c) +{ + sliders.at(currentMenu->menuitems[itemOn].mvar2).input(c); +} + +void draw_routine() +{ + int x = currentMenu->x - (menutransition.tics * 48); + int y = currentMenu->y; + + M_DrawGenericOptions(); + + for (int i = 0; i < currentMenu->numitems; ++i) + { + const menuitem_t& it = currentMenu->menuitems[i]; + + if ((it.status & IT_TYPE) == IT_ARROWS) + { + sliders.at(it.mvar2).draw(x, y, i == itemOn); + } + + y += 8; + } +} + +void tick_routine(void) +{ + M_OptionsTick(); + + if (flip_delay && !--flip_delay) + { + for (Slider& slider : sliders) + { + slider.shake_ = 0; + } + } +} + +}; // namespace + menuitem_t OPTIONS_Sound[] = { {IT_STRING | IT_CVAR, "SFX", "Enable or disable sound effect playback.", NULL, {.cvar = &cv_gamesounds}, 0, 0}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, "SFX Volume", "Adjust the volume of sound effects.", - NULL, {.cvar = &cv_soundvolume}, 0, 0}, + {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "SFX Volume", "Adjust the volume of sound effects.", + NULL, {.routine = slider_routine}, 0, Slider::kSfxVolume}, {IT_STRING | IT_CVAR, "Music", "Enable or disable music playback.", NULL, {.cvar = &cv_gamedigimusic}, 0, 0}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, "Music Volume", "Adjust the volume of music playback.", - NULL, {.cvar = &cv_digmusicvolume}, 0, 0}, + {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "Music Volume", "Adjust the volume of music playback.", + NULL, {.routine = slider_routine}, 0, Slider::kMusicVolume}, {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, @@ -57,9 +206,9 @@ menu_t OPTIONS_SoundDef = { MBF_DRAWBGWHILEPLAYING, NULL, 2, 5, - M_DrawGenericOptions, + draw_routine, M_DrawOptionsCogs, - M_OptionsTick, + tick_routine, NULL, NULL, NULL, From 375d87255e55a1f6d11b003c26d5f62d2ef87973 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 08:25:10 -0800 Subject: [PATCH 04/11] Re-enable music/sounds when volume cvars are changed --- src/cvars.cpp | 6 ++++-- src/s_sound.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cvars.cpp b/src/cvars.cpp index 994a9ee4a..76f9ddbf0 100644 --- a/src/cvars.cpp +++ b/src/cvars.cpp @@ -318,8 +318,10 @@ consvar_t cv_controlperkey = Player("controlperkey", "One").values({{1, "One"}, // actual general (maximum) sound & music volume, saved into the config // Volume scale is 0-100 in new mixer. 100 is treated as -0dB or 100% gain. No more weirdness to work around SDL_mixer // problems -consvar_t cv_digmusicvolume = Player("musicvolume", "80").min_max(0, 100); -consvar_t cv_soundvolume = Player("soundvolume", "80").min_max(0, 100); +void DigMusicVolume_OnChange(void); +void SoundVolume_OnChange(void); +consvar_t cv_digmusicvolume = Player("musicvolume", "80").min_max(0, 100).onchange_noinit(DigMusicVolume_OnChange); +consvar_t cv_soundvolume = Player("soundvolume", "80").min_max(0, 100).onchange_noinit(SoundVolume_OnChange); #ifdef HAVE_DISCORDRPC void DRPC_UpdatePresence(void); diff --git a/src/s_sound.c b/src/s_sound.c index bee22e443..5b72f4fa4 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2540,3 +2540,21 @@ void PlaySoundIfUnfocused_OnChange(void) if (window_notinfocus && !cv_playsoundifunfocused.value) S_StopSounds(); } + +void DigMusicVolume_OnChange(void); +void DigMusicVolume_OnChange(void) +{ + if (!cv_gamedigimusic.value) + { + CV_SetValue(&cv_gamedigimusic, 1); + } +} + +void SoundVolume_OnChange(void); +void SoundVolume_OnChange(void) +{ + if (!cv_gamesounds.value) + { + CV_SetValue(&cv_gamesounds, 1); + } +} From 8780edda6d39a717591a355950c306745c03752a Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 08:27:07 -0800 Subject: [PATCH 05/11] Sound options: merge volume slider with toggle via Z button prompt --- src/menus/options-sound.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index ade008c79..fe13eca61 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -47,6 +47,8 @@ struct Slider arrows.x(-10 - ofs).text("\x1C"); arrows.x(kWidth + 2 + ofs).text("\x1D"); + + h.xy(kWidth + 9, -3).small_button(Draw::Button::z, false); } h = h.y(1); @@ -152,20 +154,30 @@ void tick_routine(void) } } +boolean input_routine(INT32) +{ + UINT8 pid = 0; // todo: Add ability for any splitscreen player to bring up the menu. + + const menuitem_t& it = currentMenu->menuitems[itemOn]; + + if (M_MenuButtonPressed(pid, MBT_Z) && (it.status & IT_TYPE) == IT_ARROWS) + { + sliders.at(it.mvar2).toggle_(true); + return true; + } + + return false; +} + }; // namespace menuitem_t OPTIONS_Sound[] = { - {IT_STRING | IT_CVAR, "SFX", "Enable or disable sound effect playback.", - NULL, {.cvar = &cv_gamesounds}, 0, 0}, {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "SFX Volume", "Adjust the volume of sound effects.", NULL, {.routine = slider_routine}, 0, Slider::kSfxVolume}, - {IT_STRING | IT_CVAR, "Music", "Enable or disable music playback.", - NULL, {.cvar = &cv_gamedigimusic}, 0, 0}, - {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "Music Volume", "Adjust the volume of music playback.", NULL, {.routine = slider_routine}, 0, Slider::kMusicVolume}, @@ -211,5 +223,5 @@ menu_t OPTIONS_SoundDef = { tick_routine, NULL, NULL, - NULL, + input_routine, }; From 0c251ee643c3a9c08784ae9cd6fe83fffd3f344c Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 08:30:10 -0800 Subject: [PATCH 06/11] Sound options: add master volume slider - Updates music and sound volumes simultaneously - Changing music/sound volumes separately sets master volume to highest of the two - Visually distinct slider --- src/cvars.cpp | 2 ++ src/menus/options-sound.cpp | 47 +++++++++++++++++++++++++++++++++---- src/s_sound.c | 12 ++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/cvars.cpp b/src/cvars.cpp index 76f9ddbf0..a4236908f 100644 --- a/src/cvars.cpp +++ b/src/cvars.cpp @@ -318,8 +318,10 @@ consvar_t cv_controlperkey = Player("controlperkey", "One").values({{1, "One"}, // actual general (maximum) sound & music volume, saved into the config // Volume scale is 0-100 in new mixer. 100 is treated as -0dB or 100% gain. No more weirdness to work around SDL_mixer // problems +void MasterVolume_OnChange(void); void DigMusicVolume_OnChange(void); void SoundVolume_OnChange(void); +consvar_t cv_mastervolume = Player("volume", "80").min_max(0, 100).onchange_noinit(MasterVolume_OnChange); consvar_t cv_digmusicvolume = Player("musicvolume", "80").min_max(0, 100).onchange_noinit(DigMusicVolume_OnChange); consvar_t cv_soundvolume = Player("soundvolume", "80").min_max(0, 100).onchange_noinit(SoundVolume_OnChange); diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index fe13eca61..27c545f24 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -11,6 +11,8 @@ #include "../s_sound.h" // sounds consvars #include "../g_game.h" // cv_chatnotifications +extern "C" consvar_t cv_mastervolume; + using srb2::Draw; namespace @@ -22,6 +24,7 @@ struct Slider { enum Id { + kMasterVolume, kMusicVolume, kSfxVolume, kNumSliders @@ -34,7 +37,7 @@ struct Slider int shake_ = 0; - void draw(int x, int y, bool selected) + void draw(int x, int y, bool shaded, bool selected) { constexpr int kWidth = 111; @@ -54,7 +57,7 @@ struct Slider h = h.y(1); h.size(kWidth, 7).fill(31); - Draw s = h.xy(1, 2).size(10, 4); + Draw s = shaded ? h.xy(1, 5).size(10, 1) : h.xy(1, 2).size(10, 4); int color = toggle_(false) ? aquamap[0] : 15; int n = volume_.value / 10; @@ -82,7 +85,20 @@ struct Slider void input(INT32 c) { - M_ChangeCvarDirect(c, &volume_); + if (c == -1 && &volume_ == &cv_mastervolume) + { + // Master volume does not necessarily change when + // music or sound volumes change separately. So + // cv_mastervolume could still have its default + // value, and M_ChangeCvarDirect would do + // nothing. + CV_Set(&cv_digmusicvolume, cv_mastervolume.defaultvalue); + CV_Set(&cv_soundvolume, cv_mastervolume.defaultvalue); + } + else + { + M_ChangeCvarDirect(c, &volume_); + } shake_ = !shake_; flip_delay = 2; @@ -90,6 +106,22 @@ struct Slider }; std::array sliders{{ + { + [](bool toggle) -> bool + { + bool n = !S_MusicDisabled() || !S_SoundDisabled(); + + if (toggle) + { + n = !n; + CV_SetValue(&cv_gamedigimusic, n); + CV_SetValue(&cv_gamesounds, n); + } + + return n; + }, + cv_mastervolume, + }, { [](bool toggle) -> bool { @@ -134,7 +166,12 @@ void draw_routine() if ((it.status & IT_TYPE) == IT_ARROWS) { - sliders.at(it.mvar2).draw(x, y, i == itemOn); + sliders.at(it.mvar2).draw( + x, + y, + it.mvar2 == Slider::kMasterVolume, + i == itemOn + ); } y += 8; @@ -174,6 +211,8 @@ boolean input_routine(INT32) menuitem_t OPTIONS_Sound[] = { + {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "Volume", "Adjust the volume of game audio.", + NULL, {.routine = slider_routine}, 0, Slider::kMasterVolume}, {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "SFX Volume", "Adjust the volume of sound effects.", NULL, {.routine = slider_routine}, 0, Slider::kSfxVolume}, diff --git a/src/s_sound.c b/src/s_sound.c index 5b72f4fa4..5c1dfef0c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -37,6 +37,8 @@ #include "v_video.h" // V_ThinStringWidth #include "music.h" +extern consvar_t cv_mastervolume; + static boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); static void Command_Tunes_f(void); @@ -2541,6 +2543,14 @@ void PlaySoundIfUnfocused_OnChange(void) S_StopSounds(); } +void MasterVolume_OnChange(void); +void MasterVolume_OnChange(void) +{ + INT32 vol = cv_mastervolume.value; + CV_SetValue(&cv_digmusicvolume, vol); + CV_SetValue(&cv_soundvolume, vol); +} + void DigMusicVolume_OnChange(void); void DigMusicVolume_OnChange(void) { @@ -2548,6 +2558,7 @@ void DigMusicVolume_OnChange(void) { CV_SetValue(&cv_gamedigimusic, 1); } + CV_StealthSetValue(&cv_mastervolume, max(cv_digmusicvolume.value, cv_soundvolume.value)); } void SoundVolume_OnChange(void); @@ -2557,4 +2568,5 @@ void SoundVolume_OnChange(void) { CV_SetValue(&cv_gamesounds, 1); } + CV_StealthSetValue(&cv_mastervolume, max(cv_digmusicvolume.value, cv_soundvolume.value)); } From 79012d00e8ec8531a278a1f250dcf911daefd3a0 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 08:33:49 -0800 Subject: [PATCH 07/11] 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) From 0f6feae0007a52edb2d1516c3f3eb6a0f9d5ad43 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 08:34:26 -0800 Subject: [PATCH 08/11] Sound options: move stereo reverse to bottom group --- src/menus/options-sound.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index 3b6d2a819..60c52bd91 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -223,12 +223,6 @@ menuitem_t OPTIONS_Sound[] = {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, - {IT_STRING | IT_CVAR, "Reverse L/R Channels", "Reverse left & right channels for Stereo playback.", - NULL, {.cvar = &stereoreverse}, 0, 0}, - - {IT_SPACE | IT_NOTHING, NULL, NULL, - NULL, {NULL}, 0, 0}, - {IT_STRING | IT_CVAR, "Chat Notifications", "Set when to play notification sounds when chat messages are received.", NULL, {.cvar = &cv_chatnotifications}, 0, 0}, @@ -238,10 +232,11 @@ menuitem_t OPTIONS_Sound[] = {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, + {IT_STRING | IT_CVAR, "Reverse L/R Channels", "Reverse left & right channels for Stereo playback.", + NULL, {.cvar = &stereoreverse}, 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?) }; menu_t OPTIONS_SoundDef = { From b9d571e14bc0238eb02e6792bd28f01fd88ac6d3 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 13:07:36 -0800 Subject: [PATCH 09/11] Sound options: disable and hide Z button during Goner, until profile is set --- src/menus/options-sound.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index 60c52bd91..63528fab9 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -6,8 +6,10 @@ #include "../v_draw.hpp" +#include "../doomstat.h" #include "../console.h" #include "../k_menu.h" +#include "../m_cond.h" #include "../s_sound.h" // sounds consvars #include "../g_game.h" // cv_chatnotifications @@ -18,6 +20,12 @@ using srb2::Draw; namespace { +bool basic_options() +{ + // M_GameTrulyStarted + return gamedata && gamestartchallenge < MAXUNLOCKABLES && !netgame && gamedata->gonerlevel <= GDGONER_PROFILE; +} + int flip_delay = 0; struct Slider @@ -51,7 +59,10 @@ struct Slider arrows.x(-10 - ofs).text("\x1C"); arrows.x(kWidth + 2 + ofs).text("\x1D"); - h.xy(kWidth + 9, -3).small_button(Draw::Button::z, false); + if (!basic_options()) + { + h.xy(kWidth + 9, -3).small_button(Draw::Button::z, false); + } } h = h.y(1); @@ -197,7 +208,7 @@ boolean input_routine(INT32) const menuitem_t& it = currentMenu->menuitems[itemOn]; - if (M_MenuButtonPressed(pid, MBT_Z) && (it.status & IT_TYPE) == IT_ARROWS) + if (M_MenuButtonPressed(pid, MBT_Z) && (it.status & IT_TYPE) == IT_ARROWS && !basic_options()) { sliders.at(it.mvar2).toggle_(true); return true; From f7accbb2756f30797afa3dba5e6d534059bc1f32 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 13:15:39 -0800 Subject: [PATCH 10/11] Sound options: add restart audio button --- src/menus/options-sound.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index 63528fab9..2887be4b9 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -164,6 +164,11 @@ void slider_routine(INT32 c) sliders.at(currentMenu->menuitems[itemOn].mvar2).input(c); } +void restartaudio_routine(INT32) +{ + COM_ImmedExecute("restartaudio"); +} + void draw_routine() { int x = currentMenu->x - (menutransition.tics * 48); @@ -248,6 +253,12 @@ menuitem_t OPTIONS_Sound[] = {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}, + + {IT_SPACE | IT_NOTHING, NULL, NULL, + NULL, {NULL}, 0, 0}, + + {IT_STRING | IT_CALL, "\x85" "Restart Audio", "Reboot the game's audio system.", + NULL, {.routine = restartaudio_routine}, 0, 0}, }; menu_t OPTIONS_SoundDef = { From a2abbdefde53127c95980fc8d0e300cf778a0446 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 23 Dec 2023 13:38:15 -0800 Subject: [PATCH 11/11] Master volume: alter both music/sound volume without changing balance --- src/s_sound.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index f765669d2..c201f4cc5 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2524,9 +2524,24 @@ void GameDigiMusic_OnChange(void) void MasterVolume_OnChange(void); void MasterVolume_OnChange(void) { - INT32 vol = cv_mastervolume.value; - CV_SetValue(&cv_digmusicvolume, vol); - CV_SetValue(&cv_soundvolume, vol); + INT32 adj = cv_mastervolume.value - max(cv_digmusicvolume.value, cv_soundvolume.value); + + if (adj < 0) + { + INT32 under = min(cv_digmusicvolume.value, cv_soundvolume.value) + adj; + + if (under < 0) + { + // Ensure balance between music/sound volume does + // not change at lower bound. (This is already + // guaranteed at upper bound.) + adj -= under; + CV_StealthSetValue(&cv_mastervolume, cv_mastervolume.value - under); + } + } + + CV_SetValue(&cv_digmusicvolume, cv_digmusicvolume.value + adj); + CV_SetValue(&cv_soundvolume, cv_soundvolume.value + adj); } void DigMusicVolume_OnChange(void);