From bb187c1d2712d1bd11d90d5d375956c67ec534b4 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 11 Mar 2019 12:50:01 -0700 Subject: [PATCH 1/3] Make "Focus lost" HUD overlay optional --- src/m_menu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index fef2a5c7..f919451a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -399,6 +399,8 @@ static void Dummystaff_OnChange(void); // CONSOLE VARIABLES AND THEIR POSSIBLE VALUES GO HERE. // ========================================================================== +consvar_t cv_showfocuslost = {"showfocuslost", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; + static CV_PossibleValue_t map_cons_t[] = { {0,"MIN"}, {NUMMAPS, "MAX"}, @@ -1402,6 +1404,8 @@ static menuitem_t OP_HUDOptionsMenu[] = // highlight info - (GOOD HIGHLIGHT, WARNING HIGHLIGHT) - 105 (see M_DrawHUDOptions) {IT_STRING | IT_CVAR, NULL, "Console Text Size", &cv_constextsize, 120}, + + {IT_STRING | IT_CVAR, NULL, "Show \"FOCUS LOST\"", &cv_showfocuslost, 135}, }; static menuitem_t OP_ChatOptionsMenu[] = @@ -2880,7 +2884,7 @@ void M_Drawer(void) } // focus lost notification goes on top of everything, even the former everything - if (window_notinfocus) + if (window_notinfocus && cv_showfocuslost.value) { M_DrawTextBox((BASEVIDWIDTH/2) - (60), (BASEVIDHEIGHT/2) - (16), 13, 2); if (gamestate == GS_LEVEL && (P_AutoPause() || paused)) @@ -3162,6 +3166,8 @@ 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); From 0f9648eac04bbad17a7f6b7523a138ddb0f2bbc8 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 11 Mar 2019 14:57:11 -0700 Subject: [PATCH 2/3] Miscellaneous window de-focus options Music pausing is now optional. Sounds may be paused--on by default. The game itself being paused in off-line mode is now optional. (showfocuslost now loads from config.) --- src/d_netcmd.c | 2 ++ src/g_game.c | 3 +++ src/g_game.h | 1 + src/m_menu.c | 5 ++-- src/m_menu.h | 1 + src/p_user.c | 2 +- src/s_sound.c | 62 +++++++++++++++++++++++++++++++++++++++++------ src/s_sound.h | 6 +++++ src/sdl/i_video.c | 9 ++++++- 9 files changed, 80 insertions(+), 11 deletions(-) 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) { From 1975a9b8855bef88d5fb7a2fd8597ccca41e0ff6 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Mon, 11 Mar 2019 21:48:29 -0500 Subject: [PATCH 3/3] Prevent music changes from playing when unfocused --- src/s_sound.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/s_sound.c b/src/s_sound.c index e8478844..2ddffa3f 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1906,6 +1906,10 @@ static boolean S_PlayMusic(boolean looping) } S_InitMusicVolume(); // switch between digi and sequence volume + + if (window_notinfocus && !cv_playmusicifunfocused.value) + I_PauseSong(); + return true; }