From f86a67456b21cc5cdc9069c11784ffa0b98acf79 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Thu, 30 Jul 2020 17:06:07 -0400 Subject: [PATCH] Remove data/ from track name list, refactor music loading, and support loose ogg music (these should be separate commits but they're annoying to split after the fact, oh well) --- desktop_version/src/BinaryBlob.cpp | 3 +- desktop_version/src/BinaryBlob.h | 32 ++++++++++----------- desktop_version/src/Music.cpp | 46 +++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/desktop_version/src/BinaryBlob.cpp b/desktop_version/src/BinaryBlob.cpp index 59e67600..b36b7b48 100644 --- a/desktop_version/src/BinaryBlob.cpp +++ b/desktop_version/src/BinaryBlob.cpp @@ -134,9 +134,8 @@ bool binaryBlob::nextExtra(size_t* start) for (idx = start; *idx < SDL_arraysize(m_headers); *idx += 1) { if (m_headers[*idx].valid -#define FOREACH_TRACK(_, track_name) && SDL_strcmp(m_headers[*idx].name, track_name) != 0 +#define FOREACH_TRACK(_, track_name) && SDL_strcmp(m_headers[*idx].name, "data/" track_name) != 0 TRACK_NAMES(_) -#undef FOREACH_TRACK ) { return true; } diff --git a/desktop_version/src/BinaryBlob.h b/desktop_version/src/BinaryBlob.h index 2907f82b..034b80cb 100644 --- a/desktop_version/src/BinaryBlob.h +++ b/desktop_version/src/BinaryBlob.h @@ -7,22 +7,22 @@ // #define VVV_COMPILEMUSIC #define TRACK_NAMES(blob) \ - FOREACH_TRACK(blob, "data/music/0levelcomplete.ogg") \ - FOREACH_TRACK(blob, "data/music/1pushingonwards.ogg") \ - FOREACH_TRACK(blob, "data/music/2positiveforce.ogg") \ - FOREACH_TRACK(blob, "data/music/3potentialforanything.ogg") \ - FOREACH_TRACK(blob, "data/music/4passionforexploring.ogg") \ - FOREACH_TRACK(blob, "data/music/5intermission.ogg") \ - FOREACH_TRACK(blob, "data/music/6presentingvvvvvv.ogg") \ - FOREACH_TRACK(blob, "data/music/7gamecomplete.ogg") \ - FOREACH_TRACK(blob, "data/music/8predestinedfate.ogg") \ - FOREACH_TRACK(blob, "data/music/9positiveforcereversed.ogg") \ - FOREACH_TRACK(blob, "data/music/10popularpotpourri.ogg") \ - FOREACH_TRACK(blob, "data/music/11pipedream.ogg") \ - FOREACH_TRACK(blob, "data/music/12pressurecooker.ogg") \ - FOREACH_TRACK(blob, "data/music/13pacedenergy.ogg") \ - FOREACH_TRACK(blob, "data/music/14piercingthesky.ogg") \ - FOREACH_TRACK(blob, "data/music/predestinedfatefinallevel.ogg") + FOREACH_TRACK(blob, "music/0levelcomplete.ogg") \ + FOREACH_TRACK(blob, "music/1pushingonwards.ogg") \ + FOREACH_TRACK(blob, "music/2positiveforce.ogg") \ + FOREACH_TRACK(blob, "music/3potentialforanything.ogg") \ + FOREACH_TRACK(blob, "music/4passionforexploring.ogg") \ + FOREACH_TRACK(blob, "music/5intermission.ogg") \ + FOREACH_TRACK(blob, "music/6presentingvvvvvv.ogg") \ + FOREACH_TRACK(blob, "music/7gamecomplete.ogg") \ + FOREACH_TRACK(blob, "music/8predestinedfate.ogg") \ + FOREACH_TRACK(blob, "music/9positiveforcereversed.ogg") \ + FOREACH_TRACK(blob, "music/10popularpotpourri.ogg") \ + FOREACH_TRACK(blob, "music/11pipedream.ogg") \ + FOREACH_TRACK(blob, "music/12pressurecooker.ogg") \ + FOREACH_TRACK(blob, "music/13pacedenergy.ogg") \ + FOREACH_TRACK(blob, "music/14piercingthesky.ogg") \ + FOREACH_TRACK(blob, "music/predestinedfatefinallevel.ogg") struct resourceheader { diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 7fdcbadd..57782a8d 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "BinaryBlob.h" #include "Game.h" @@ -62,7 +63,7 @@ void musicclass::init(void) #ifdef VVV_COMPILEMUSIC binaryBlob musicWriteBlob; -#define FOREACH_TRACK(blob, track_name) blob.AddFileToBinaryBlob(track_name); +#define FOREACH_TRACK(blob, track_name) blob.AddFileToBinaryBlob("data/" track_name); TRACK_NAMES(musicWriteBlob) #undef FOREACH_TRACK @@ -75,19 +76,46 @@ void musicclass::init(void) if (!mmmmmm_blob.unPackBinary("mmmmmm.vvv")) { - mmmmmm = false; - usingmmmmmm=false; - bool ohCrap = pppppp_blob.unPackBinary("vvvvvvmusic.vvv"); - SDL_assert(ohCrap && "Music not found!"); + if (pppppp_blob.unPackBinary("vvvvvvmusic.vvv")) { + puts("Loading music from PPPPPP blob..."); + + mmmmmm = false; + usingmmmmmm=false; + + int index; + SDL_RWops* rw; + +#define FOREACH_TRACK(blob, track_name) \ + index = blob.getIndex("data/" track_name); \ + rw = SDL_RWFromMem(blob.getAddress(index), blob.getSize(index)); \ + musicTracks.push_back(MusicTrack( rw )); + + TRACK_NAMES(pppppp_blob) + +#undef FOREACH_TRACK + } else { + puts("Loading music from loose files..."); + + SDL_RWops* rw; +#define FOREACH_TRACK(_, track_name) \ + rw = PHYSFSRWOPS_openRead(track_name); \ + musicTracks.push_back(MusicTrack( rw )); + + TRACK_NAMES(_) + +#undef FOREACH_TRACK + } } else { + puts("Loading PPPPPP and MMMMMM blobs..."); + mmmmmm = true; int index; SDL_RWops *rw; #define FOREACH_TRACK(blob, track_name) \ - index = blob.getIndex(track_name); \ + index = blob.getIndex("data/" track_name); \ if (index >= 0 && index < blob.max_headers) \ { \ rw = SDL_RWFromConstMem(blob.getAddress(index), blob.getSize(index)); \ @@ -117,17 +145,15 @@ void musicclass::init(void) bool ohCrap = pppppp_blob.unPackBinary("vvvvvvmusic.vvv"); SDL_assert(ohCrap && "Music not found!"); - } - - int index; - SDL_RWops *rw; TRACK_NAMES(pppppp_blob) #undef FOREACH_TRACK + } num_pppppp_tracks += musicTracks.size() - num_mmmmmm_tracks; + SDL_RWops* rw; size_t index_ = 0; while (pppppp_blob.nextExtra(&index_)) {