From 7c2b418761c948a2aad1ffe3e704d69ffa93fbb5 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 30 Jun 2020 17:08:37 -0700 Subject: [PATCH] Account for extra tracks in musicclass::play() Since each soundtrack is no longer guaranteed to be 16, we'll have to account for their different lengths when playing music. --- desktop_version/src/Music.cpp | 32 ++++++++++++++++++++++++-------- desktop_version/src/Music.h | 2 ++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index e96508bb..69b348d0 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -57,6 +57,9 @@ void musicclass::init() musicWriteBlob.writeBinaryBlob("data/BinaryMusic.vvv"); #endif + num_mmmmmm_tracks = 0; + num_pppppp_tracks = 0; + if (!musicReadBlob.unPackBinary("mmmmmm.vvv")) { mmmmmm = false; @@ -78,12 +81,16 @@ void musicclass::init() TRACK_NAMES + num_mmmmmm_tracks += 16; + const std::vector extra = musicReadBlob.getExtra(); for (size_t i = 0; i < extra.size(); i++) { const int& index = extra[i]; rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index)); musicTracks.push_back(MusicTrack( rw )); + + num_mmmmmm_tracks++; } bool ohCrap = musicReadBlob.unPackBinary("vvvvvvmusic.vvv"); @@ -97,12 +104,16 @@ void musicclass::init() #undef FOREACH_TRACK + num_pppppp_tracks += 16; + const std::vector extra = musicReadBlob.getExtra(); for (size_t i = 0; i < extra.size(); i++) { const int& index = extra[i]; rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index)); musicTracks.push_back(MusicTrack( rw )); + + num_pppppp_tracks++; } safeToProcessMusic= false; @@ -131,14 +142,19 @@ void songend() void musicclass::play(int t, const double position_sec /*= 0.0*/, const int fadein_ms /*= 3000*/) { - t = (t % 16); - - if(mmmmmm) + // No need to check if num_tracks is greater than 0, we wouldn't be here if it wasn't + if (mmmmmm && usingmmmmmm) { - if(!usingmmmmmm) - { - t += 16; - } + t %= num_mmmmmm_tracks; + } + else + { + t %= num_pppppp_tracks; + } + + if(mmmmmm && !usingmmmmmm) + { + t += num_mmmmmm_tracks; } safeToProcessMusic = true; Mix_VolumeMusic(128); @@ -147,7 +163,7 @@ void musicclass::play(int t, const double position_sec /*= 0.0*/, const int fade if (t != -1) { currentsong = t; - if (currentsong == 0 || currentsong == 7 || (!map.custommode && (currentsong == 16 || currentsong == 23))) + if (currentsong == 0 || currentsong == 7 || (!map.custommode && (currentsong == 0+num_pppppp_tracks || currentsong == 7+num_pppppp_tracks))) { // Level Complete theme, no fade in or repeat if(Mix_FadeInMusicPos(musicTracks[t].m_music, 0, 0, position_sec)==-1) diff --git a/desktop_version/src/Music.h b/desktop_version/src/Music.h index b3b1eeab..f7bee414 100644 --- a/desktop_version/src/Music.h +++ b/desktop_version/src/Music.h @@ -51,6 +51,8 @@ public: bool usingmmmmmm; binaryBlob musicReadBlob; + int num_pppppp_tracks; + int num_mmmmmm_tracks; Uint64 songStart; Uint64 songEnd;