diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 438cdcd5..401344fd 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -807,6 +807,8 @@ void D_RegisterClientCommands(void) //CV_RegisterVar(&cv_alwaysfreelook2); //CV_RegisterVar(&cv_chasefreelook); //CV_RegisterVar(&cv_chasefreelook2); + CV_RegisterVar(&cv_showfocuslost); + CV_RegisterVar(&cv_pauseifunfocused); // g_input.c CV_RegisterVar(&cv_turnaxis); diff --git a/src/g_game.c b/src/g_game.c index f0d221ff..cf877664 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -437,6 +437,9 @@ consvar_t cv_chatbacktint = {"chatbacktint", "On", CV_SAVE, CV_OnOff, NULL, 0, N static CV_PossibleValue_t consolechat_cons_t[] = {{0, "Window"}, {1, "Console"}, {2, "Window (Hidden)"}, {0, NULL}}; consvar_t cv_consolechat = {"chatmode", "Window", CV_SAVE, consolechat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +// Pause game upon window losing focus +consvar_t cv_pauseifunfocused = {"pauseifunfocused", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + // Display song credits consvar_t cv_songcredits = {"songcredits", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/g_game.h b/src/g_game.h index fc7a4a4f..eea149c9 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -56,6 +56,7 @@ extern INT16 rw_maximums[NUM_WEAPONS]; // used in game menu extern consvar_t cv_chatwidth, cv_chatnotifications, cv_chatheight, cv_chattime, cv_consolechat, cv_chatbacktint, cv_chatspamprotection/*, cv_compactscoreboard*/; extern consvar_t cv_songcredits; +extern consvar_t cv_pauseifunfocused; //extern consvar_t cv_crosshair, cv_crosshair2, cv_crosshair3, cv_crosshair4; extern consvar_t cv_invertmouse/*, cv_alwaysfreelook, cv_chasefreelook, cv_mousemove*/; extern consvar_t cv_invertmouse2/*, cv_alwaysfreelook2, cv_chasefreelook2, cv_mousemove2*/; diff --git a/src/m_menu.c b/src/m_menu.c index f919451a..a6ca7c4d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1318,6 +1318,9 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Powerup Warning", &cv_kartinvinsfx, 95}, {IT_KEYHANDLER|IT_STRING, NULL, "Sound Test", M_HandleSoundTest, 110}, + + {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, + {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, }; /*static menuitem_t OP_DataOptionsMenu[] = @@ -3166,8 +3169,6 @@ void M_Init(void) COM_AddCommand("manual", Command_Manual_f); - CV_RegisterVar(&cv_showfocuslost); - CV_RegisterVar(&cv_nextmap); CV_RegisterVar(&cv_newgametype); CV_RegisterVar(&cv_chooseskin); diff --git a/src/m_menu.h b/src/m_menu.h index 864f4cac..21b48f33 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -211,6 +211,7 @@ typedef struct extern description_t description[32]; +extern consvar_t cv_showfocuslost; extern consvar_t cv_newgametype, cv_nextmap, cv_chooseskin, cv_serversort; extern CV_PossibleValue_t gametype_cons_t[]; diff --git a/src/p_user.c b/src/p_user.c index e26acdfd..5d8f35e2 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -172,7 +172,7 @@ boolean P_AutoPause(void) if (netgame || modeattacking) return false; - return (menuactive || window_notinfocus); + return (menuactive || ( window_notinfocus && cv_pauseifunfocused.value )); } // diff --git a/src/s_sound.c b/src/s_sound.c index 856aa045..e8478844 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -57,6 +57,9 @@ static void GameMIDIMusic_OnChange(void); static void GameSounds_OnChange(void); static void GameDigiMusic_OnChange(void); +static void PlayMusicIfUnfocused_OnChange(void); +static void PlaySoundIfUnfocused_OnChange(void); + // commands for music and sound servers #ifdef MUSSERV consvar_t musserver_cmd = {"musserver_cmd", "musserver", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -110,6 +113,9 @@ consvar_t cv_gamemidimusic = {"midimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_O #endif consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameSounds_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlayMusicIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, PlaySoundIfUnfocused_OnChange, 0, NULL, NULL, 0, 0, NULL}; + #define S_MAX_VOLUME 127 // when to clip out sounds @@ -270,6 +276,9 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_gamemidimusic); #endif + CV_RegisterVar(&cv_playmusicifunfocused); + CV_RegisterVar(&cv_playsoundifunfocused); + COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); @@ -1978,6 +1987,24 @@ void S_ResumeAudio(void) I_ResumeCD(); } +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, INT32 seqvolume) { if (digvolume < 0) @@ -2156,15 +2183,11 @@ void GameSounds_OnChange(void) if (sound_disabled) { - sound_disabled = false; - S_InitSfxChannels(cv_soundvolume.value); - S_StartSound(NULL, sfx_strpst); + if (!( cv_playsoundifunfocused.value && window_notinfocus )) + S_EnableSound(); } else - { - sound_disabled = true; - S_StopSounds(); - } + S_DisableSound(); } void GameDigiMusic_OnChange(void) @@ -2251,3 +2274,28 @@ void GameMIDIMusic_OnChange(void) } } #endif + +static void PlayMusicIfUnfocused_OnChange(void) +{ + if (window_notinfocus) + { + if (cv_playmusicifunfocused.value) + I_PauseSong(); + else + I_ResumeSong(); + } +} + +static void PlaySoundIfUnfocused_OnChange(void) +{ + if (!cv_gamesounds.value) + return; + + if (window_notinfocus) + { + if (cv_playsoundifunfocused.value) + S_DisableSound(); + else + S_EnableSound(); + } +} diff --git a/src/s_sound.h b/src/s_sound.h index 1ad519c2..1c938681 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -33,6 +33,8 @@ extern consvar_t cv_gamedigimusic; extern consvar_t cv_gamemidimusic; #endif extern consvar_t cv_gamesounds; +extern consvar_t cv_playmusicifunfocused; +extern consvar_t cv_playsoundifunfocused; #ifdef SNDSERV extern consvar_t sndserver_cmd, sndserver_arg; @@ -169,6 +171,10 @@ void S_StopMusic(void); void S_PauseAudio(void); void S_ResumeAudio(void); +// Enable and disable sound effects +void S_EnableSound(void); +void S_DisableSound(void); + // // Updates music & sounds // diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f64a429a..2c5bf994 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -616,7 +616,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) // Tell game we got focus back, resume music if necessary window_notinfocus = false; if (!paused) + { I_ResumeSong(); //resume it + if (cv_gamesounds.value) + S_EnableSound(); + } if (!firsttimeonmouse) { @@ -630,7 +634,10 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { // Tell game we lost focus, pause music window_notinfocus = true; - I_PauseSong(); + if (!cv_playmusicifunfocused.value) + I_PauseSong(); + if (!cv_playsoundifunfocused.value) + S_DisableSound(); if (!disable_mouse) {