From 981a1192fbc44dfaf2c482a92b41f1656a588d88 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 25 Nov 2018 14:22:52 -0500 Subject: [PATCH 1/4] Save sound toggles to config --- src/m_menu.c | 108 ++------------------------------------------------ src/s_sound.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++ src/s_sound.h | 3 ++ 3 files changed, 107 insertions(+), 105 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 72c4564d..dfe8bbec 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -287,9 +287,6 @@ menu_t OP_VideoOptionsDef, OP_VideoModeDef; menu_t OP_OpenGLOptionsDef, OP_OpenGLFogDef, OP_OpenGLColorDef; #endif menu_t OP_SoundOptionsDef; -static void M_ToggleSFX(void); -static void M_ToggleDigital(void); -static void M_ToggleMIDI(void); //Misc menu_t OP_DataOptionsDef, OP_ScreenshotOptionsDef, OP_EraseDataDef; @@ -1227,9 +1224,9 @@ static menuitem_t OP_SoundOptionsMenu[] = NULL, "CD Volume" , &cd_volume, 40}, #endif - {IT_STRING | IT_CALL, NULL, "Toggle SFX" , M_ToggleSFX, 50}, - {IT_STRING | IT_CALL, NULL, "Toggle Digital Music", M_ToggleDigital, 60}, - {IT_STRING | IT_CALL, NULL, "Toggle MIDI Music", M_ToggleMIDI, 70}, + {IT_STRING | IT_CVAR, NULL, "SFX" , &cv_gamesounds, 50}, + {IT_STRING | IT_CVAR, NULL, "Digital Music", &cv_gamedigimusic, 60}, + {IT_STRING | IT_CVAR, NULL, "MIDI Music", &cv_gamemidimusic, 70}, }; static menuitem_t OP_DataOptionsMenu[] = @@ -6943,105 +6940,6 @@ static void M_ChangeControl(INT32 choice) M_StartMessage(tmp, M_ChangecontrolResponse, MM_EVENTHANDLER); } -// ===== -// SOUND -// ===== - -// Toggles sound systems in-game. -static void M_ToggleSFX(void) -{ - if (sound_disabled) - { - sound_disabled = false; - S_InitSfxChannels(cv_soundvolume.value); - S_StartSound(NULL, sfx_strpst); - M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); - } - else - { - sound_disabled = true; - S_StopSounds(); - M_StartMessage(M_GetText("SFX Disabled\n"), NULL, MM_NOTHING); - } -} - -static void M_ToggleDigital(void) -{ - if (digital_disabled) - { - digital_disabled = false; - I_InitMusic(); - S_StopMusic(); - if (Playing()) - P_RestoreMusic(&players[consoleplayer]); - else - S_ChangeMusicInternal("lclear", false); - M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); - } - else - { - digital_disabled = true; - if (S_MusicType() != MU_MID) - { - if (midi_disabled) - S_StopMusic(); - else - { - char mmusic[7]; - UINT16 mflags; - boolean looping; - - if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic)) - { - S_StopMusic(); - S_ChangeMusic(mmusic, mflags, looping); - } - else - S_StopMusic(); - } - } - M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); - } -} - -static void M_ToggleMIDI(void) -{ - if (midi_disabled) - { - midi_disabled = false; - I_InitMusic(); - if (Playing()) - P_RestoreMusic(&players[consoleplayer]); - else - S_ChangeMusicInternal("lclear", false); - M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); - } - else - { - midi_disabled = true; - if (S_MusicType() == MU_MID) - { - if (digital_disabled) - S_StopMusic(); - else - { - char mmusic[7]; - UINT16 mflags; - boolean looping; - - if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic)) - { - S_StopMusic(); - S_ChangeMusic(mmusic, mflags, looping); - } - else - S_StopMusic(); - } - } - M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); - } -} - // =============== // VIDEO MODE MENU // =============== diff --git a/src/s_sound.c b/src/s_sound.c index d6e6dd51..27281f2e 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -50,6 +50,11 @@ static void SetChannelsNum(void); static void Command_Tunes_f(void); static void Command_RestartAudio_f(void); +// Sound system toggles +static void GameMIDIMusic_OnChange(void); +static void GameSounds_OnChange(void); +static void GameDigiMusic_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}; @@ -94,6 +99,11 @@ consvar_t cv_numChannels = {"snd_channels", "32", CV_SAVE|CV_CALL, CV_Unsigned, static consvar_t surround = {"surround", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +// Sound system toggles, saved into the config +consvar_t cv_gamedigimusic = {"gamedigimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameDigiMusic_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_gamemidimusic = {"gamemidimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameMIDIMusic_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_gamesounds = {"gamesounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameSounds_OnChange, 0, NULL, NULL, 0, 0, NULL}; + #define S_MAX_VOLUME 127 // when to clip out sounds @@ -248,6 +258,9 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&surround); CV_RegisterVar(&cv_samplerate); CV_RegisterVar(&cv_resetmusic); + CV_RegisterVar(&cv_gamesounds); + CV_RegisterVar(&cv_gamedigimusic); + CV_RegisterVar(&cv_gamemidimusic); COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); @@ -1597,3 +1610,91 @@ static void Command_RestartAudio_f(void) if (Playing()) // Gotta make sure the player is in a level P_RestoreMusic(&players[consoleplayer]); } + +void GameSounds_OnChange(void) +{ + if (sound_disabled) + { + sound_disabled = false; + S_InitSfxChannels(cv_soundvolume.value); + S_StartSound(NULL, sfx_strpst); + } + else + { + sound_disabled = true; + S_StopSounds(); + } +} + +void GameDigiMusic_OnChange(void) +{ + if (digital_disabled) + { + digital_disabled = false; + I_InitMusic(); + S_StopMusic(); + if (Playing()) + P_RestoreMusic(&players[consoleplayer]); + else + S_ChangeMusicInternal("lclear", false); + } + else + { + digital_disabled = true; + if (S_MusicType() != MU_MID) + { + if (midi_disabled) + S_StopMusic(); + else + { + char mmusic[7]; + UINT16 mflags; + boolean looping; + + if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic)) + { + S_StopMusic(); + S_ChangeMusic(mmusic, mflags, looping); + } + else + S_StopMusic(); + } + } + } +} + +void GameMIDIMusic_OnChange(void) +{ + if (midi_disabled) + { + midi_disabled = false; + I_InitMusic(); + if (Playing()) + P_RestoreMusic(&players[consoleplayer]); + else + S_ChangeMusicInternal("lclear", false); + } + else + { + midi_disabled = true; + if (S_MusicType() == MU_MID) + { + if (digital_disabled) + S_StopMusic(); + else + { + char mmusic[7]; + UINT16 mflags; + boolean looping; + + if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic)) + { + S_StopMusic(); + S_ChangeMusic(mmusic, mflags, looping); + } + else + S_StopMusic(); + } + } + } +} \ No newline at end of file diff --git a/src/s_sound.h b/src/s_sound.h index d4858299..82174607 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -27,6 +27,9 @@ extern consvar_t stereoreverse; extern consvar_t cv_soundvolume, cv_digmusicvolume, cv_midimusicvolume; extern consvar_t cv_numChannels; extern consvar_t cv_resetmusic; +extern consvar_t cv_gamedigimusic; +extern consvar_t cv_gamemidimusic; +extern consvar_t cv_gamesounds; #ifdef SNDSERV extern consvar_t sndserver_cmd, sndserver_arg; From 7d4c9dda911a32fe5893429b640b5860c0a1aac4 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 25 Nov 2018 14:24:50 -0500 Subject: [PATCH 2/4] Add newline to end of file --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 27281f2e..6c1e3f2c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1697,4 +1697,4 @@ void GameMIDIMusic_OnChange(void) } } } -} \ No newline at end of file +} From cf01e820c45a9b680f61771cbbca991787fd6a9c Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 25 Nov 2018 22:39:11 -0500 Subject: [PATCH 3/4] Take the command line params into account Really I'm just making it return early if either of the parms are used. --- src/d_main.c | 2 +- src/s_sound.c | 13 +++++++++++++ src/sdl/i_system.c | 7 +++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 9b34ed94..23835136 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1235,7 +1235,7 @@ void D_SRB2Main(void) else { if (M_CheckParm("-nomidimusic")) - midi_disabled = true; ; // WARNING: DOS version initmusic in I_StartupSound + midi_disabled = true; // WARNING: DOS version initmusic in I_StartupSound if (M_CheckParm("-nodigmusic")) digital_disabled = true; // WARNING: DOS version initmusic in I_StartupSound } diff --git a/src/s_sound.c b/src/s_sound.c index 6c1e3f2c..2ecd4725 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1613,6 +1613,9 @@ static void Command_RestartAudio_f(void) void GameSounds_OnChange(void) { + if (M_CheckParm("-nosound")) + return; + if (sound_disabled) { sound_disabled = false; @@ -1628,6 +1631,11 @@ void GameSounds_OnChange(void) void GameDigiMusic_OnChange(void) { + if (M_CheckParm("-nomusic")) + return; + else if (M_CheckParm("-nodigmusic")) + return; + if (digital_disabled) { digital_disabled = false; @@ -1665,6 +1673,11 @@ void GameDigiMusic_OnChange(void) void GameMIDIMusic_OnChange(void) { + if (M_CheckParm("-nomusic")) + return; + else if (M_CheckParm("-nomidimusic")) + return; + if (midi_disabled) { midi_disabled = false; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 2b35ce8b..e7cb28f2 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2076,8 +2076,11 @@ void I_StartupTimer(void) void I_Sleep(void) { - if (cv_sleep.value != -1) - SDL_Delay(cv_sleep.value); + if (dedicated) + SDL_Delay(15); + else + if (cv_sleep.value != -1) + SDL_Delay(cv_sleep.value); } INT32 I_StartupSystem(void) From ba111d42ca01570c63fb9aa32c9ab06dcda89589 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 26 Nov 2018 00:24:11 -0500 Subject: [PATCH 4/4] Last minute changes. --- src/s_sound.c | 6 +++--- src/sdl/i_system.c | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 2ecd4725..0961a442 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -100,9 +100,9 @@ static consvar_t surround = {"surround", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; // Sound system toggles, saved into the config -consvar_t cv_gamedigimusic = {"gamedigimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameDigiMusic_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_gamemidimusic = {"gamemidimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameMIDIMusic_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_gamesounds = {"gamesounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameSounds_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_gamedigimusic = {"digimusic", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, GameDigiMusic_OnChange, 0, NULL, NULL, 0, 0, NULL}; +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}; #define S_MAX_VOLUME 127 diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e7cb28f2..2b35ce8b 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2076,11 +2076,8 @@ void I_StartupTimer(void) void I_Sleep(void) { - if (dedicated) - SDL_Delay(15); - else - if (cv_sleep.value != -1) - SDL_Delay(cv_sleep.value); + if (cv_sleep.value != -1) + SDL_Delay(cv_sleep.value); } INT32 I_StartupSystem(void)