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.)
This commit is contained in:
James R 2019-03-11 14:57:11 -07:00
parent bb187c1d27
commit 0f9648eac0
9 changed files with 80 additions and 11 deletions

View file

@ -807,6 +807,8 @@ void D_RegisterClientCommands(void)
//CV_RegisterVar(&cv_alwaysfreelook2); //CV_RegisterVar(&cv_alwaysfreelook2);
//CV_RegisterVar(&cv_chasefreelook); //CV_RegisterVar(&cv_chasefreelook);
//CV_RegisterVar(&cv_chasefreelook2); //CV_RegisterVar(&cv_chasefreelook2);
CV_RegisterVar(&cv_showfocuslost);
CV_RegisterVar(&cv_pauseifunfocused);
// g_input.c // g_input.c
CV_RegisterVar(&cv_turnaxis); CV_RegisterVar(&cv_turnaxis);

View file

@ -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}}; 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}; 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 // Display song credits
consvar_t cv_songcredits = {"songcredits", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_songcredits = {"songcredits", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};

View file

@ -56,6 +56,7 @@ extern INT16 rw_maximums[NUM_WEAPONS];
// used in game menu // 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_chatwidth, cv_chatnotifications, cv_chatheight, cv_chattime, cv_consolechat, cv_chatbacktint, cv_chatspamprotection/*, cv_compactscoreboard*/;
extern consvar_t cv_songcredits; 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_crosshair, cv_crosshair2, cv_crosshair3, cv_crosshair4;
extern consvar_t cv_invertmouse/*, cv_alwaysfreelook, cv_chasefreelook, cv_mousemove*/; extern consvar_t cv_invertmouse/*, cv_alwaysfreelook, cv_chasefreelook, cv_mousemove*/;
extern consvar_t cv_invertmouse2/*, cv_alwaysfreelook2, cv_chasefreelook2, cv_mousemove2*/; extern consvar_t cv_invertmouse2/*, cv_alwaysfreelook2, cv_chasefreelook2, cv_mousemove2*/;

View file

@ -1318,6 +1318,9 @@ static menuitem_t OP_SoundOptionsMenu[] =
{IT_STRING|IT_CVAR, NULL, "Powerup Warning", &cv_kartinvinsfx, 95}, {IT_STRING|IT_CVAR, NULL, "Powerup Warning", &cv_kartinvinsfx, 95},
{IT_KEYHANDLER|IT_STRING, NULL, "Sound Test", M_HandleSoundTest, 110}, {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[] = /*static menuitem_t OP_DataOptionsMenu[] =
@ -3166,8 +3169,6 @@ void M_Init(void)
COM_AddCommand("manual", Command_Manual_f); COM_AddCommand("manual", Command_Manual_f);
CV_RegisterVar(&cv_showfocuslost);
CV_RegisterVar(&cv_nextmap); CV_RegisterVar(&cv_nextmap);
CV_RegisterVar(&cv_newgametype); CV_RegisterVar(&cv_newgametype);
CV_RegisterVar(&cv_chooseskin); CV_RegisterVar(&cv_chooseskin);

View file

@ -211,6 +211,7 @@ typedef struct
extern description_t description[32]; extern description_t description[32];
extern consvar_t cv_showfocuslost;
extern consvar_t cv_newgametype, cv_nextmap, cv_chooseskin, cv_serversort; extern consvar_t cv_newgametype, cv_nextmap, cv_chooseskin, cv_serversort;
extern CV_PossibleValue_t gametype_cons_t[]; extern CV_PossibleValue_t gametype_cons_t[];

View file

@ -172,7 +172,7 @@ boolean P_AutoPause(void)
if (netgame || modeattacking) if (netgame || modeattacking)
return false; return false;
return (menuactive || window_notinfocus); return (menuactive || ( window_notinfocus && cv_pauseifunfocused.value ));
} }
// //

View file

@ -57,6 +57,9 @@ static void GameMIDIMusic_OnChange(void);
static void GameSounds_OnChange(void); static void GameSounds_OnChange(void);
static void GameDigiMusic_OnChange(void); static void GameDigiMusic_OnChange(void);
static void PlayMusicIfUnfocused_OnChange(void);
static void PlaySoundIfUnfocused_OnChange(void);
// commands for music and sound servers // commands for music and sound servers
#ifdef MUSSERV #ifdef MUSSERV
consvar_t musserver_cmd = {"musserver_cmd", "musserver", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; 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 #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_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 #define S_MAX_VOLUME 127
// when to clip out sounds // when to clip out sounds
@ -270,6 +276,9 @@ void S_RegisterSoundStuff(void)
CV_RegisterVar(&cv_gamemidimusic); CV_RegisterVar(&cv_gamemidimusic);
#endif #endif
CV_RegisterVar(&cv_playmusicifunfocused);
CV_RegisterVar(&cv_playsoundifunfocused);
COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("tunes", Command_Tunes_f);
COM_AddCommand("restartaudio", Command_RestartAudio_f); COM_AddCommand("restartaudio", Command_RestartAudio_f);
@ -1978,6 +1987,24 @@ void S_ResumeAudio(void)
I_ResumeCD(); 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) void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume)
{ {
if (digvolume < 0) if (digvolume < 0)
@ -2156,15 +2183,11 @@ void GameSounds_OnChange(void)
if (sound_disabled) if (sound_disabled)
{ {
sound_disabled = false; if (!( cv_playsoundifunfocused.value && window_notinfocus ))
S_InitSfxChannels(cv_soundvolume.value); S_EnableSound();
S_StartSound(NULL, sfx_strpst);
} }
else else
{ S_DisableSound();
sound_disabled = true;
S_StopSounds();
}
} }
void GameDigiMusic_OnChange(void) void GameDigiMusic_OnChange(void)
@ -2251,3 +2274,28 @@ void GameMIDIMusic_OnChange(void)
} }
} }
#endif #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();
}
}

View file

@ -33,6 +33,8 @@ extern consvar_t cv_gamedigimusic;
extern consvar_t cv_gamemidimusic; extern consvar_t cv_gamemidimusic;
#endif #endif
extern consvar_t cv_gamesounds; extern consvar_t cv_gamesounds;
extern consvar_t cv_playmusicifunfocused;
extern consvar_t cv_playsoundifunfocused;
#ifdef SNDSERV #ifdef SNDSERV
extern consvar_t sndserver_cmd, sndserver_arg; extern consvar_t sndserver_cmd, sndserver_arg;
@ -169,6 +171,10 @@ void S_StopMusic(void);
void S_PauseAudio(void); void S_PauseAudio(void);
void S_ResumeAudio(void); void S_ResumeAudio(void);
// Enable and disable sound effects
void S_EnableSound(void);
void S_DisableSound(void);
// //
// Updates music & sounds // Updates music & sounds
// //

View file

@ -616,7 +616,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
// Tell game we got focus back, resume music if necessary // Tell game we got focus back, resume music if necessary
window_notinfocus = false; window_notinfocus = false;
if (!paused) if (!paused)
{
I_ResumeSong(); //resume it I_ResumeSong(); //resume it
if (cv_gamesounds.value)
S_EnableSound();
}
if (!firsttimeonmouse) if (!firsttimeonmouse)
{ {
@ -630,7 +634,10 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{ {
// Tell game we lost focus, pause music // Tell game we lost focus, pause music
window_notinfocus = true; window_notinfocus = true;
I_PauseSong(); if (!cv_playmusicifunfocused.value)
I_PauseSong();
if (!cv_playsoundifunfocused.value)
S_DisableSound();
if (!disable_mouse) if (!disable_mouse)
{ {