summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2014-10-07 21:48:08 -0400
committerSimon Howard2014-10-07 21:48:08 -0400
commit2afa4144dbb898e3e746a5aeb0af562958fbc27a (patch)
tree39f9f287bd72cdcc3f95c250ace57f6ae480378e
parent056bd10f6e6206fcb875e8601572e54ed216d4f1 (diff)
downloadchocolate-doom-2afa4144dbb898e3e746a5aeb0af562958fbc27a.tar.gz
chocolate-doom-2afa4144dbb898e3e746a5aeb0af562958fbc27a.tar.bz2
chocolate-doom-2afa4144dbb898e3e746a5aeb0af562958fbc27a.zip
Allow multiple substitute mappings for music tracks.
For the Hexen substitute mapping configuration file, it's desirable to be able to include two mappings for each music lump: a straight high quality recording of that lump, and the recording that was included on the Hexen CD audio tracks. So allow multiple mappings so that we can fall back to try other filenames if the first choice file doesn't appear to exist.
-rw-r--r--src/i_sdlmusic.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index cf4a6b8b..cca41322 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -414,6 +414,7 @@ static char *GetSubstituteMusicFile(void *data, size_t data_len)
{
sha1_context_t context;
sha1_digest_t hash;
+ char *filename;
int i;
// Don't bother doing a hash if we're never going to find anything.
@@ -427,16 +428,30 @@ static char *GetSubstituteMusicFile(void *data, size_t data_len)
SHA1_Final(hash, &context);
// Look for a hash that matches.
+ // The substitute mapping list can (intentionally) contain multiple
+ // filename mappings for the same hash. This allows us to try
+ // different files and fall back if our first choice isn't found.
+
+ filename = NULL;
for (i = 0; i < subst_music_len; ++i)
{
if (memcmp(hash, subst_music[i].hash, sizeof(hash)) == 0)
{
- return subst_music[i].filename;
+ filename = subst_music[i].filename;
+
+ // If the file exists, then use this file in preference to
+ // any fallbacks. But we always return a filename if it's
+ // in the list, even if it's just so we can print an error
+ // message to the user saying it doesn't exist.
+ if (M_FileExists(filename))
+ {
+ break;
+ }
}
}
- return NULL;
+ return filename;
}
// Add a substitute music file to the lookup list.