diff --git a/src/m_menu.c b/src/m_menu.c index 2bd0c3e44..da1309de1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1327,22 +1327,25 @@ static menuitem_t OP_OpenGLColorMenu[] = static menuitem_t OP_SoundOptionsMenu[] = { - {IT_HEADER, NULL, "Game Audio", NULL, 0}, // 0 // ScrollMenu offsets - {IT_STRING | IT_CVAR, NULL, "Sound Effects", &cv_gamesounds, 13}, // 6 - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Sound Volume", &cv_soundvolume, 23}, // 11 + {IT_HEADER, NULL, "Game Audio", NULL, 0}, + {IT_STRING | IT_CVAR, NULL, "Sound Effects", &cv_gamesounds, 6}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Sound Volume", &cv_soundvolume, 11}, - {IT_STRING | IT_CVAR, NULL, "Digital Music", &cv_gamedigimusic, 43}, // 21 - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Digital Music Volume", &cv_digmusicvolume, 53}, // 26 + {IT_STRING | IT_CVAR, NULL, "Digital Music", &cv_gamedigimusic, 21}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Digital Music Volume", &cv_digmusicvolume, 26}, - {IT_STRING | IT_CVAR, NULL, "MIDI Music", &cv_gamemidimusic, 73}, // 36 - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "MIDI Music Volume", &cv_midimusicvolume, 83}, // 41 + {IT_STRING | IT_CVAR, NULL, "MIDI Music", &cv_gamemidimusic, 36}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "MIDI Music Volume", &cv_midimusicvolume, 41}, - {IT_HEADER, NULL, "Accessibility", NULL, 103}, // 50 - {IT_STRING | IT_CVAR, NULL, "Closed Captioning", &cv_closedcaptioning, 115}, // 56 - {IT_STRING | IT_CVAR, NULL, "Reset Music Upon Dying", &cv_resetmusic, 125}, // 62 + {IT_HEADER, NULL, "Accessibility", NULL, 50}, + {IT_STRING | IT_CVAR, NULL, "Closed Captioning", &cv_closedcaptioning, 56}, + {IT_STRING | IT_CVAR, NULL, "Reset Music Upon Dying", &cv_resetmusic, 61}, + + {IT_STRING | IT_CVAR, NULL, "Play Sound Effects if Unfocused", &cv_playsoundsifunfocused, 71}, + {IT_STRING | IT_CVAR, NULL, "Play Music if Unfocused", &cv_playmusicifunfocused, 76}, #ifdef HAVE_MIXERX - {IT_STRING | IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 143}, + {IT_STRING | IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 94}, #endif }; @@ -1965,18 +1968,9 @@ menu_t OP_ColorOptionsDef = 0, NULL }; -menu_t OP_SoundOptionsDef = -{ +menu_t OP_SoundOptionsDef = DEFAULTSCROLLMENUSTYLE( MN_OP_MAIN + (MN_OP_SOUND << 6), - "M_SOUND", - sizeof (OP_SoundOptionsMenu)/sizeof (menuitem_t), - &OP_MainDef, - OP_SoundOptionsMenu, - M_DrawGenericMenu, - 30, 30, - 0, - NULL -}; + "M_SOUND", OP_SoundOptionsMenu, &OP_MainDef, 30, 30); #ifdef HAVE_MIXERX menu_t OP_SoundAdvancedDef = DEFAULTMENUSTYLE(MN_OP_MAIN + (MN_OP_SOUND << 6), "M_SOUND", OP_SoundAdvancedMenu, &OP_SoundOptionsDef, 30, 30); #endif diff --git a/src/s_sound.c b/src/s_sound.c index 1a719d972..00576ff55 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -117,6 +117,10 @@ consvar_t cv_gamedigimusic = {"digimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_O consvar_t cv_gamemidimusic = {"midimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameMIDIMusic_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameSounds_OnChange, 0, NULL, NULL, 0, 0, NULL}; +// Window focus sound sytem toggles +consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE, CV_YesNo}; +consvar_t cv_playsoundsifunfocused = {"playsoundsifunfocused", "No", CV_SAVE, CV_YesNo}; + #ifdef HAVE_OPENMPT static CV_PossibleValue_t interpolationfilter_cons_t[] = {{0, "Default"}, {1, "None"}, {2, "Linear"}, {4, "Cubic"}, {8, "Windowed sinc"}, {0, NULL}}; consvar_t cv_modfilter = {"modfilter", "0", CV_SAVE|CV_CALL, interpolationfilter_cons_t, ModFilter_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -278,6 +282,8 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_samplerate); CV_RegisterVar(&cv_resetmusic); CV_RegisterVar(&cv_resetmusicbyheader); + CV_RegisterVar(&cv_playsoundsifunfocused); + CV_RegisterVar(&cv_playmusicifunfocused); CV_RegisterVar(&cv_gamesounds); CV_RegisterVar(&cv_gamedigimusic); CV_RegisterVar(&cv_gamemidimusic); @@ -373,6 +379,18 @@ lumpnum_t S_GetSfxLumpNum(sfxinfo_t *sfx) return W_GetNumForName("dsthok"); } +// +// Sound Status +// + +boolean S_SoundDisabled(void) +{ + return ( + sound_disabled || + ( window_notinfocus && ! cv_playsoundsifunfocused.value ) + ); +} + // Stop all sounds, load level info, THEN start sounds. void S_StopSounds(void) { @@ -540,7 +558,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) mobj_t *listenmobj = players[displayplayer].mo; mobj_t *listenmobj2 = NULL; - if (sound_disabled || !sound_started) + if (S_SoundDisabled() || !sound_started) return; // Don't want a sound? Okay then... @@ -730,7 +748,7 @@ dontplay: void S_StartSound(const void *origin, sfxenum_t sfx_id) { - if (sound_disabled) + if (S_SoundDisabled()) return; if (mariomode) // Sounds change in Mario mode! @@ -1434,6 +1452,13 @@ boolean S_MusicPaused(void) return I_SongPaused(); } +boolean S_MusicNotInFocus(void) +{ + return ( + ( window_notinfocus && ! cv_playmusicifunfocused.value ) + ); +} + musictype_t S_MusicType(void) { return I_SongType(); @@ -1867,6 +1892,10 @@ static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) } S_InitMusicVolume(); // switch between digi and sequence volume + + if (S_MusicNotInFocus()) + S_PauseAudio(); + return true; } @@ -2009,6 +2038,9 @@ void S_PauseAudio(void) void S_ResumeAudio(void) { + if (S_MusicNotInFocus()) + return; + if (I_SongPlaying() && I_SongPaused()) I_ResumeSong(); diff --git a/src/s_sound.h b/src/s_sound.h index 48128527c..20b2489a5 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -45,6 +45,9 @@ extern consvar_t cv_gamedigimusic; extern consvar_t cv_gamemidimusic; extern consvar_t cv_gamesounds; +extern consvar_t cv_playmusicifunfocused; +extern consvar_t cv_playsoundsifunfocused; + #ifdef HAVE_OPENMPT extern consvar_t cv_modfilter; #endif @@ -144,6 +147,12 @@ void S_StartEx(boolean reset); // lumpnum_t S_GetSfxLumpNum(sfxinfo_t *sfx); +// +// Sound Status +// + +boolean S_SoundDisabled(void); + // // Start sound for thing at using from sounds.h // @@ -164,6 +173,7 @@ boolean S_MIDIMusicDisabled(void); boolean S_MusicDisabled(void); boolean S_MusicPlaying(void); boolean S_MusicPaused(void); +boolean S_MusicNotInFocus(void); musictype_t S_MusicType(void); const char *S_MusicName(void); boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index be6017aa9..57591af10 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -595,7 +595,10 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { // Tell game we lost focus, pause music window_notinfocus = true; - S_PauseAudio(); + if (! cv_playmusicifunfocused.value) + S_PauseAudio(); + if (! cv_playsoundsifunfocused.value) + S_StopSounds(); if (!disable_mouse) {