From 3cd2b92dd1f605597045155faf9ac54aaeacd940 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 16 Feb 2020 20:08:04 +0100 Subject: [PATCH] - pause all game sounds while the menu or console are open and marked SW's UI sounds as such. --- source/common/console/c_console.cpp | 3 +++ source/common/menu/menu.cpp | 3 ++- .../rendering/gl/system/gl_framebuffer.cpp | 2 +- source/common/sound/backend/i_sound.h | 6 ++++++ source/sw/src/d_menu.cpp | 18 +++++++++--------- source/sw/src/game.cpp | 2 +- source/sw/src/game.h | 19 ++++++++++--------- source/sw/src/sounds.cpp | 4 ++-- 8 files changed, 34 insertions(+), 23 deletions(-) diff --git a/source/common/console/c_console.cpp b/source/common/console/c_console.cpp index d73a12e89..cd0cb164c 100644 --- a/source/common/console/c_console.cpp +++ b/source/common/console/c_console.cpp @@ -57,6 +57,7 @@ #include "gamecvars.h" #include "baselayer.h" #include "i_system.h" +#include "s_soundinternal.h" #define LEFTMARGIN 8 @@ -1028,6 +1029,7 @@ void C_Ticker() ConBottom += (consoletic - lasttic) * (screen->GetHeight() * 2 / 25); if (ConBottom >= screen->GetHeight() / 2) { + GSnd->SetSfxPaused(true, PAUSESFX_CONSOLE); ConBottom = screen->GetHeight() / 2; ConsoleState = c_down; } @@ -1037,6 +1039,7 @@ void C_Ticker() ConBottom -= (consoletic - lasttic) * (screen->GetHeight() * 2 / 25); if (ConBottom <= 0) { + GSnd->SetSfxPaused(false, PAUSESFX_CONSOLE); ConsoleState = c_up; ConBottom = 0; } diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index bda47be84..5e884eed4 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -366,7 +366,7 @@ void M_StartControlPanel (bool makeSound) created = true; M_CreateMenus(); } - soundEngine->StopAllChannels(); + GSnd->SetSfxPaused(true, PAUSESFX_MENU); gi->MenuOpened(); if (makeSound) gi->MenuSound(ActivateSound); @@ -936,6 +936,7 @@ void M_ClearMenus (bool final) } DMenu::CurrentMenu = nullptr; menuactive = MENU_Off; + GSnd->SetSfxPaused(false, PAUSESFX_MENU); if (!final) { mouseGrabInput(true); diff --git a/source/common/rendering/gl/system/gl_framebuffer.cpp b/source/common/rendering/gl/system/gl_framebuffer.cpp index 6cc90b407..9f487d931 100644 --- a/source/common/rendering/gl/system/gl_framebuffer.cpp +++ b/source/common/rendering/gl/system/gl_framebuffer.cpp @@ -162,7 +162,7 @@ void OpenGLFrameBuffer::InitializeState() glDisable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); glEnable(GL_BLEND); - glEnable(GL_DEPTH_CLAMP); + //glEnable(GL_DEPTH_CLAMP); glDisable(GL_DEPTH_TEST); glDisable(GL_LINE_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/source/common/sound/backend/i_sound.h b/source/common/sound/backend/i_sound.h index 3968fbdd0..f1c03c599 100644 --- a/source/common/sound/backend/i_sound.h +++ b/source/common/sound/backend/i_sound.h @@ -169,4 +169,10 @@ extern ReverbContainer *DefaultEnvironments[26]; bool IsOpenALPresent(); +enum +{ + PAUSESFX_MENU = 1, + PAUSESFX_CONSOLE = 2 +}; + #endif diff --git a/source/sw/src/d_menu.cpp b/source/sw/src/d_menu.cpp index f725c8d8c..db85089a6 100644 --- a/source/sw/src/d_menu.cpp +++ b/source/sw/src/d_menu.cpp @@ -108,9 +108,9 @@ public: DidOrderSound = true; int choose_snd = STD_RANDOM_RANGE(1000); if (choose_snd > 500) - PlaySound(DIGI_WANGORDER1, v3df_dontpan); + PlaySound(DIGI_WANGORDER1, v3df_dontpan, CHAN_BODY, CHANF_UI); else - PlaySound(DIGI_WANGORDER2, v3df_dontpan); + PlaySound(DIGI_WANGORDER2, v3df_dontpan, CHAN_BODY, CHANF_UI); } } }; @@ -178,15 +178,15 @@ void GameInterface::MenuSound(EMenuSounds snd) switch (snd) { case CursorSound: - PlaySound(DIGI_STAR, v3df_dontpan); + PlaySound(DIGI_STAR, v3df_dontpan, CHAN_BODY, CHANF_UI); break; case AdvanceSound: - PlaySound(DIGI_SWORDSWOOSH, v3df_dontpan); + PlaySound(DIGI_SWORDSWOOSH, v3df_dontpan, CHAN_BODY, CHANF_UI); break; case CloseSound: - PlaySound(DIGI_STARCLINK, v3df_dontpan); + PlaySound(DIGI_STARCLINK, v3df_dontpan, CHAN_BODY, CHANF_UI); break; default: @@ -237,13 +237,13 @@ void GameInterface::StartGame(FGameStartup& gs) //InitNewGame(); if (Skill == 0) - PlaySound(DIGI_TAUNTAI3, v3df_none, CHAN_VOICE); + PlaySound(DIGI_TAUNTAI3, v3df_none, CHAN_VOICE, CHANF_UI); else if (Skill == 1) - PlaySound(DIGI_NOFEAR, v3df_none, CHAN_VOICE); + PlaySound(DIGI_NOFEAR, v3df_none, CHAN_VOICE, CHANF_UI); else if (Skill == 2) - PlaySound(DIGI_WHOWANTSWANG, v3df_none, CHAN_VOICE); + PlaySound(DIGI_WHOWANTSWANG, v3df_none, CHAN_VOICE, CHANF_UI); else if (Skill == 3) - PlaySound(DIGI_NOPAIN, v3df_none, CHAN_VOICE); + PlaySound(DIGI_NOPAIN, v3df_none, CHAN_VOICE, CHANF_UI); while (soundEngine->IsSourcePlayingSomething(SOURCE_None, nullptr, CHAN_VOICE)) { diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 4875eb944..df410702b 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -1525,7 +1525,7 @@ void CreditsLevel(void) inputState.ClearAllInput(); // Lo Wang feel like singing! - PlaySound(DIGI_JG95012, v3df_none, CHAN_VOICE); + PlaySound(DIGI_JG95012, v3df_none, CHAN_VOICE, CHANF_UI); while (soundEngine->IsSourcePlayingSomething(SOURCE_None, nullptr, CHAN_VOICE)) { DoUpdateSounds(); diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 0fbd730c6..4560ca6fc 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -45,6 +45,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #include "settings.h" #include "pragmas.h" #include "gamecvars.h" +#include "s_soundinternal.h" BEGIN_SW_NS @@ -2092,23 +2093,23 @@ enum short SoundDist(int x, int y, int z, int basedist); short SoundAngle(int x, int y); //void PlaySound(int num, short angle, short vol); -int _PlaySound(int num, SPRITEp sprite, PLAYERp player, vec3_t *pos, Voc3D_Flags flags, int channel); +int _PlaySound(int num, SPRITEp sprite, PLAYERp player, vec3_t *pos, Voc3D_Flags flags, int channel, EChanFlags sndflags); void InitAmbient(int num, SPRITEp sprite); -inline void PlaySound(int num, SPRITEp sprite, Voc3D_Flags flags, int channel = 8) +inline void PlaySound(int num, SPRITEp sprite, Voc3D_Flags flags, int channel = 8, EChanFlags sndflags = CHANF_NONE) { - _PlaySound(num, sprite, nullptr, nullptr, flags, channel); + _PlaySound(num, sprite, nullptr, nullptr, flags, channel, sndflags); } -inline void PlaySound(int num, PLAYERp player, Voc3D_Flags flags, int channel = 8) +inline void PlaySound(int num, PLAYERp player, Voc3D_Flags flags, int channel = 8, EChanFlags sndflags = CHANF_NONE) { - _PlaySound(num, nullptr, player, nullptr, flags, channel); + _PlaySound(num, nullptr, player, nullptr, flags, channel, sndflags); } -inline void PlaySound(int num, Voc3D_Flags flags, int channel = 8) +inline void PlaySound(int num, Voc3D_Flags flags, int channel = 8, EChanFlags sndflags = CHANF_NONE) { - _PlaySound(num, nullptr, nullptr, nullptr, flags, channel); + _PlaySound(num, nullptr, nullptr, nullptr, flags, channel, sndflags); } -inline void PlaySound(int num, vec3_t *pos, Voc3D_Flags flags, int channel = 8) +inline void PlaySound(int num, vec3_t *pos, Voc3D_Flags flags, int channel = 8, EChanFlags sndflags = CHANF_NONE) { - _PlaySound(num, nullptr, nullptr, pos, flags, channel); + _PlaySound(num, nullptr, nullptr, pos, flags, channel, sndflags); } int _PlayerSound(int num, PLAYERp pp); diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index c87487544..009536a7d 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -608,7 +608,7 @@ void DoUpdateSounds(void) // //========================================================================== -int _PlaySound(int num, SPRITEp sp, PLAYERp pp, vec3_t* pos, Voc3D_Flags flags, int channel) +int _PlaySound(int num, SPRITEp sp, PLAYERp pp, vec3_t* pos, Voc3D_Flags flags, int channel, EChanFlags cflags) { if (Prediction || !SoundEnabled() || !soundEngine->isValidSoundId(num)) return -1; @@ -625,7 +625,7 @@ int _PlaySound(int num, SPRITEp sp, PLAYERp pp, vec3_t* pos, Voc3D_Flags flags, auto vp = &voc[num]; int sourcetype = SOURCE_None; - EChanFlags cflags = channel == 8 ? CHANF_OVERLAP : CHANF_NONE; // for the default channel we do not want to have sounds stopping each other. + cflags |= channel == 8 ? CHANF_OVERLAP : CHANF_NONE; // for the default channel we do not want to have sounds stopping each other. void* source = nullptr; // If the sound is not supposd to be positioned, it may not be linked to the launching actor. if (!(flags & v3df_follow))