From d8dfe752b5cf2f37d7addf8e74a538f17efbc865 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 26 Dec 2019 13:04:29 +0100 Subject: [PATCH] - fixed handling of music in Redneck Rampage and Shadow Warrior. After merging the CD enabling CVAR they had the same default (off) as Blood which is wrong. This also addresses other music related issues, like not properly cycling through the RR music. --- source/blood/src/loadsave.cpp | 2 +- source/common/gamecontrol.cpp | 9 ++++++++- source/common/gamecvars.cpp | 2 +- source/common/music/music.cpp | 9 +++++++-- source/common/music/z_music.h | 3 ++- source/duke3d/src/savegame.cpp | 2 +- source/duke3d/src/screens.cpp | 4 ++-- source/rr/src/premap.cpp | 7 ++++--- source/rr/src/savegame.cpp | 2 +- source/rr/src/screens.cpp | 6 +++--- source/rr/src/sounds.cpp | 27 +++++++++++++++++---------- source/sw/src/save.cpp | 2 +- source/sw/src/scrip2.cpp | 7 +++---- source/sw/src/sounds.cpp | 12 ++++++++---- 14 files changed, 59 insertions(+), 35 deletions(-) diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 9f3773db7..085afc05f 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -177,7 +177,7 @@ bool GameInterface::LoadGame(FSaveGameNode* node) gGameStarted = 1; bVanilla = false; - MUS_ResumeSaved(); + Mus_ResumeSaved(); netBroadcastPlayerInfo(myconnectindex); return true; diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index 5a4263a1a..3e5d30e16 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -544,6 +544,13 @@ int RunGame() InitFileSystem(usedgroups); if (usedgroups.Size() == 0) return 0; + if (g_gameType & GAMEFLAG_BLOOD) + { + UCVarValue v; + v.Bool = false; + mus_redbook.SetGenericRepDefault(v, CVAR_Bool); // Blood should default to CD Audio off - all other games must default to on. + } + G_ReadConfig(currentGame); V_InitFontColors(); @@ -682,7 +689,7 @@ CCMD(snd_reset) { Mus_Stop(); if (soundEngine) soundEngine->Reset(); - MUS_ResumeSaved(); + Mus_ResumeSaved(); } //========================================================================== diff --git a/source/common/gamecvars.cpp b/source/common/gamecvars.cpp index 910b80b3e..5fd247310 100644 --- a/source/common/gamecvars.cpp +++ b/source/common/gamecvars.cpp @@ -134,7 +134,7 @@ CVARD(Bool, snd_tryformats, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enables/disab CVARD(Bool, snd_doppler, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enable/disable 3d sound") CVARD(Bool, mus_restartonload, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "restart the music when loading a saved game with the same map or not") // only implemented for Blood - todo: generalize -CVARD(Bool, mus_redbook, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_FRONTEND_BLOOD, "enables/disables redbook audio (Blood only!)") // only Blood has assets for this. +CVARD(Bool, mus_redbook, true, CVAR_ARCHIVE, "enables/disables redbook audio") CUSTOM_CVARD(Int, snd_fxvolume, 255, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "controls volume for sound effects") { diff --git a/source/common/music/music.cpp b/source/common/music/music.cpp index 340b03124..30e34ec88 100644 --- a/source/common/music/music.cpp +++ b/source/common/music/music.cpp @@ -536,7 +536,7 @@ CCMD (stopmus) static FString lastMusicLevel, lastMusic; int Mus_Play(const char *mapname, const char *fn, bool loop) { - if (mus_blocked) return 0; + if (mus_blocked) return 1; // Caller should believe it succeeded. // Store the requested names for resuming. lastMusicLevel = mapname; lastMusic = fn; @@ -579,6 +579,11 @@ int Mus_Play(const char *mapname, const char *fn, bool loop) return mus_playing.handle != nullptr; } +bool Mus_IsPlaying() +{ + return mus_playing.handle != nullptr; +} + void Mus_Stop() { if (mus_blocked) return; @@ -654,7 +659,7 @@ bool MUS_Restore() return true; } -void MUS_ResumeSaved() +void Mus_ResumeSaved() { S_RestartMusic(); } diff --git a/source/common/music/z_music.h b/source/common/music/z_music.h index e2dff877a..735661f65 100644 --- a/source/common/music/z_music.h +++ b/source/common/music/z_music.h @@ -5,6 +5,7 @@ void Mus_Init(); int Mus_Play(const char *mapname, const char *fn, bool loop); void Mus_Stop(); +bool Mus_IsPlaying(); void Mus_Fade(double seconds); void Mus_SetPaused(bool on); -void MUS_ResumeSaved(); +void Mus_ResumeSaved(); diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index 626846a65..814f2ba6a 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -1929,7 +1929,7 @@ static void postloadplayer(int32_t savegamep) Bmemset(gotpic, 0, sizeof(gotpic)); S_ClearSoundLocks(); G_CacheMapData(); - MUS_ResumeSaved(); + Mus_ResumeSaved(); g_player[myconnectindex].ps->gm = MODE_GAME; ud.recstat = 0; diff --git a/source/duke3d/src/screens.cpp b/source/duke3d/src/screens.cpp index eae273ae9..899235086 100644 --- a/source/duke3d/src/screens.cpp +++ b/source/duke3d/src/screens.cpp @@ -1994,7 +1994,7 @@ void G_BonusScreen(int32_t bonusonly) videoClearScreen(0); G_DisplayMPResultsScreen(); - if (MusicEnabled()) + if (MusicEnabled() && mus_enabled) S_PlaySound(BONUSMUSIC); videoNextPage(); @@ -2033,7 +2033,7 @@ void G_BonusScreen(int32_t bonusonly) gametext_center_shade(192, GStrings("PRESSKEY"), quotepulseshade); - if (MusicEnabled()) + if (MusicEnabled() && mus_enabled) S_PlaySound(BONUSMUSIC); videoNextPage(); diff --git a/source/rr/src/premap.cpp b/source/rr/src/premap.cpp index d3605feb1..c3717bb17 100644 --- a/source/rr/src/premap.cpp +++ b/source/rr/src/premap.cpp @@ -2413,6 +2413,10 @@ int G_EnterLevel(int gameMode) G_CacheMapData(); // G_FadeLoad(0,0,0, 0,252, 28, 4, -2); + // Try this first so that it can disable the CD player if no tracks are found. + if (RR && !(gameMode & MODE_DEMO)) + S_PlayRRMusic(); + if (ud.recstat != 2) { if (Menu_HaveUserMap()) @@ -2422,9 +2426,6 @@ int G_EnterLevel(int gameMode) else S_PlayLevelMusicOrNothing(mii); } - if (RR && !(gameMode & MODE_DEMO)) - S_PlayRRMusic(); - if (gameMode & (MODE_GAME|MODE_EOL)) { for (TRAVERSE_CONNECT(i)) diff --git a/source/rr/src/savegame.cpp b/source/rr/src/savegame.cpp index 60c7e8990..6bc0fd587 100644 --- a/source/rr/src/savegame.cpp +++ b/source/rr/src/savegame.cpp @@ -1543,7 +1543,7 @@ static void postloadplayer(int32_t savegamep) Bmemset(gotpic, 0, sizeof(gotpic)); S_ClearSoundLocks(); G_CacheMapData(); - MUS_ResumeSaved(); + Mus_ResumeSaved(); Mus_SetPaused(false); g_player[myconnectindex].ps->gm = MODE_GAME; diff --git a/source/rr/src/screens.cpp b/source/rr/src/screens.cpp index 10a5a6649..f5523176a 100644 --- a/source/rr/src/screens.cpp +++ b/source/rr/src/screens.cpp @@ -2000,7 +2000,7 @@ void G_BonusScreen(int32_t bonusonly) videoClearScreen(0); G_DisplayMPResultsScreen(); - if (MusicEnabled()) + if (MusicEnabled() && mus_enabled) S_PlaySound(BONUSMUSIC); videoNextPage(); @@ -2042,7 +2042,7 @@ void G_BonusScreen(int32_t bonusonly) gametext_center_shade(192, GStrings("PRESSKEY"), quotepulseshade); - if (MusicEnabled()) + if (MusicEnabled() && mus_enabled) S_PlaySound(BONUSMUSIC); } else @@ -2579,7 +2579,7 @@ void G_BonusScreenRRRA(int32_t bonusonly) videoClearScreen(0); G_DisplayMPResultsScreen(); - if (MusicEnabled()) + if (MusicEnabled() && mus_enabled) S_PlaySound(BONUSMUSIC); videoNextPage(); diff --git a/source/rr/src/sounds.cpp b/source/rr/src/sounds.cpp index 3dcba9cff..252d6f592 100644 --- a/source/rr/src/sounds.cpp +++ b/source/rr/src/sounds.cpp @@ -314,10 +314,8 @@ void S_Update(void) vec3_t* c; int32_t ca, cs; -#if 0 - if (RR /*&& todo: fix the conditions here */ ) + if (RR && Mus_IsPlaying()) S_PlayRRMusic(); -#endif S_GetCamera(&c, &ca, &cs); @@ -552,6 +550,8 @@ void S_MenuSound(void) // //========================================================================== +static bool cd_disabled = false; // This is in case mus_redbook is enabled but no tracks found so that the regular music system can be switched on. + static void S_SetMusicIndex(unsigned int m) { ud.music_episode = m / MAXLEVELS; @@ -560,6 +560,7 @@ static void S_SetMusicIndex(unsigned int m) void S_PlayLevelMusicOrNothing(unsigned int m) { + if (RR && mus_redbook && !cd_disabled) return; auto& mr = m == USERMAPMUSICFAKESLOT ? userMapRecord : mapList[m]; Mus_Play(mr.labelName, mr.music, true); S_SetMusicIndex(m); @@ -567,6 +568,7 @@ void S_PlayLevelMusicOrNothing(unsigned int m) int S_TryPlaySpecialMusic(unsigned int m) { + if (RR) return 0; // Can only be MUS_LOADING, RR does not use it. auto& musicfn = mapList[m].music; if (musicfn.IsNotEmpty()) { @@ -590,16 +592,21 @@ void S_PlaySpecialMusicOrNothing(unsigned int m) void S_PlayRRMusic(int newTrack) { - char fileName[16]; - if (!RR || !mus_redbook) + if (!RR || !mus_redbook || cd_disabled) return; Mus_Stop(); - g_cdTrack = newTrack != -1 ? newTrack : g_cdTrack + 1; - if (newTrack != 10 && (g_cdTrack > 9 || g_cdTrack < 2)) - g_cdTrack = 2; - Bsprintf(fileName, "track%.2d.ogg", g_cdTrack); - Mus_Play(fileName, 0, true); + for (int i = 0; i < 10; i++) + { + g_cdTrack = newTrack != -1 ? newTrack : g_cdTrack + 1; + if (newTrack != 10 && (g_cdTrack > 9 || g_cdTrack < 2)) + g_cdTrack = 2; + + FStringf filename("track%02d.ogg", g_cdTrack); + if (Mus_Play(nullptr, 0, false)) return; + } + // If none of the tracks managed to start, disable the CD music for this session so that regular music can play if defined. + cd_disabled = true; } diff --git a/source/sw/src/save.cpp b/source/sw/src/save.cpp index 2faa576e6..204c0163d 100644 --- a/source/sw/src/save.cpp +++ b/source/sw/src/save.cpp @@ -1209,7 +1209,7 @@ bool GameInterface::LoadGame(FSaveGameNode* sv) screenpeek = myconnectindex; PlayingLevel = Level; - MUS_ResumeSaved(); + Mus_ResumeSaved(); if (snd_ambience) StartAmbientSound(); diff --git a/source/sw/src/scrip2.cpp b/source/sw/src/scrip2.cpp index 80dcddc2d..b1aad0ae2 100644 --- a/source/sw/src/scrip2.cpp +++ b/source/sw/src/scrip2.cpp @@ -616,25 +616,24 @@ void LoadCustomInfoFromScript(const char *filename) case CM_BESTTIME: { int n; - char s[10]; if (scriptfile_getnumber(script, &n)) break; - mapList[curmap].designerTime = (int)strtoll(s, nullptr, 0); + mapList[curmap].designerTime = n; break; } case CM_PARTIME: { int n; - char s[10]; if (scriptfile_getnumber(script, &n)) break; - mapList[curmap].parTime = (int)strtoll(s, nullptr, 0); + mapList[curmap].parTime = n; break; } case CM_CDATRACK: { int n; if (scriptfile_getnumber(script, &n)) break; + mapList[curmap].cdSongId = n; break; } default: diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index 5e386707c..0a30cece2 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -922,7 +922,6 @@ int PlayerYellVocs[] = //========================================================================== extern short Level; -CVAR(Bool, sw_nothememidi, false, CVAR_ARCHIVE) SWBOOL PlaySong(const char* mapname, const char* song_file_name, int cdaudio_track, bool isThemeTrack) //(nullptr, nullptr, -1, false) starts the normal level music. { @@ -935,13 +934,18 @@ SWBOOL PlaySong(const char* mapname, const char* song_file_name, int cdaudio_tra if (cdaudio_track >= 0 && mus_redbook) { FStringf trackname("track%02d.ogg", cdaudio_track); - if (!Mus_Play(nullptr, trackname, true)) + if (!Mus_Play(mapname, trackname, true)) { buildprintf("Can't find CD track %i!\n", cdaudio_track); } } - else if (isThemeTrack && sw_nothememidi) return false; // The original SW source only used CD Audio for theme tracks, so this is optional. - return Mus_Play(nullptr, song_file_name, true); + if (!Mus_Play(mapname, song_file_name, true)) + { + // try the CD track anyway if no MIDI could be found (the original game doesn't have any MIDI, it was CD Audio only, this avoids no music playing id mus_redbook is off.) + FStringf trackname("track%02d.ogg", cdaudio_track); + if (!Mus_Play(nullptr, trackname, true)) return false; + } + return true; } void StopSound(void)