mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-26 11:40:44 +00:00
Duke3D/Sound: Restructure S_OpenAudio to check in more paths. For each path, it performs the filename transformations and checks it does currently.
First, it will try the local path (as previously). Second, it will check to see if the filename originally requested exists inside a GRP or SSI file (its parent), and if it does, it will check in "music/<parent's name sans extension>/". Third, it will check in "music/". Do not rely on this when distributing mods: These checks are hacks and may potentially be removed. git-svn-id: https://svn.eduke32.com/eduke32@5445 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
fcd7b2e0b1
commit
26aca9b291
1 changed files with 86 additions and 37 deletions
|
@ -1034,63 +1034,112 @@ void G_LoadLookups(void)
|
||||||
kclose(fp);
|
kclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t S_OpenAudio(const char *fn, char searchfirst)
|
//////////
|
||||||
|
|
||||||
|
static int32_t S_TryFormats(char const * const testfn, char * const fn_suffix, char const searchfirst)
|
||||||
{
|
{
|
||||||
char *testfn, *extension;
|
#ifdef HAVE_FLAC
|
||||||
int32_t fp = -1;
|
{
|
||||||
|
Bstrcpy(fn_suffix, ".flac");
|
||||||
|
int32_t const fp = kopen4loadfrommod(testfn, searchfirst);
|
||||||
|
if (fp >= 0)
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
testfn = (char *)Xmalloc(Bstrlen(fn) + 6);
|
#ifdef HAVE_VORBIS
|
||||||
Bstrcpy(testfn, fn);
|
{
|
||||||
extension = Bstrrchr(testfn, '.');
|
Bstrcpy(fn_suffix, ".ogg");
|
||||||
|
int32_t const fp = kopen4loadfrommod(testfn, searchfirst);
|
||||||
|
if (fp >= 0)
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t S_TryExtensionReplacements(char const * const testfn, char const searchfirst)
|
||||||
|
{
|
||||||
|
char * extension = Bstrrchr(testfn, '.');
|
||||||
|
char * const fn_end = Bstrchr(testfn, '\0');
|
||||||
|
|
||||||
|
// ex: grabbag.voc --> grabbag_voc.*
|
||||||
if (extension != NULL)
|
if (extension != NULL)
|
||||||
{
|
{
|
||||||
char * const fn_end = Bstrrchr(testfn, '\0');
|
|
||||||
*extension = '_';
|
*extension = '_';
|
||||||
|
|
||||||
#ifdef HAVE_FLAC
|
int32_t const fp = S_TryFormats(testfn, fn_end, searchfirst);
|
||||||
char const * const extFLAC = ".flac";
|
if (fp >= 0)
|
||||||
Bstrcpy(fn_end, extFLAC);
|
return fp;
|
||||||
fp = kopen4loadfrommod(testfn, searchfirst);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extension = fn_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ex: grabbag.mid --> grabbag.*
|
||||||
|
{
|
||||||
|
int32_t const fp = S_TryFormats(testfn, extension, searchfirst);
|
||||||
|
if (fp >= 0)
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t S_OpenAudio(const char *fn, char searchfirst)
|
||||||
|
{
|
||||||
|
int32_t const origfp = kopen4loadfrommod(fn, searchfirst);
|
||||||
|
char const * const origparent = origfp != -1 ? kfileparent(origfp) : NULL;
|
||||||
|
uint32_t const origparentlength = origparent != NULL ? Bstrlen(origparent) : 0;
|
||||||
|
|
||||||
|
char * const testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + origparentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
|
||||||
|
|
||||||
|
// look in ./
|
||||||
|
// ex: ./grabbag.mid
|
||||||
|
{
|
||||||
|
Bstrcpy(testfn, fn);
|
||||||
|
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst);
|
||||||
if (fp >= 0)
|
if (fp >= 0)
|
||||||
{
|
{
|
||||||
Bfree(testfn);
|
Bfree(testfn);
|
||||||
|
kclose(origfp);
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
#ifdef HAVE_VORBIS
|
// look in ./music/<file's parent GRP name>/
|
||||||
char const * const extOGG = ".ogg";
|
// ex: ./music/duke3d/grabbag.mid
|
||||||
Bstrcpy(fn_end, extOGG);
|
// ex: ./music/nwinter/grabbag.mid
|
||||||
fp = kopen4loadfrommod(testfn, searchfirst);
|
if (origparent != NULL)
|
||||||
|
{
|
||||||
|
char const * const origparentextension = Bstrrchr(origparent, '.');
|
||||||
|
uint32_t namelength = origparentextension != NULL ? origparentextension - origparent : origparentlength;
|
||||||
|
|
||||||
|
Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn);
|
||||||
|
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst);
|
||||||
if (fp >= 0)
|
if (fp >= 0)
|
||||||
{
|
{
|
||||||
Bfree(testfn);
|
Bfree(testfn);
|
||||||
|
kclose(origfp);
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
#ifdef HAVE_FLAC
|
// look in ./music/
|
||||||
Bstrcpy(extension, extFLAC);
|
// ex: ./music/grabbag.mid
|
||||||
fp = kopen4loadfrommod(testfn, searchfirst);
|
{
|
||||||
|
Bsprintf(testfn, "music/%s", fn);
|
||||||
|
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst);
|
||||||
if (fp >= 0)
|
if (fp >= 0)
|
||||||
{
|
{
|
||||||
Bfree(testfn);
|
Bfree(testfn);
|
||||||
|
kclose(origfp);
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_VORBIS
|
|
||||||
Bstrcpy(extension, extOGG);
|
|
||||||
fp = kopen4loadfrommod(testfn, searchfirst);
|
|
||||||
if (fp >= 0)
|
|
||||||
{
|
|
||||||
Bfree(testfn);
|
|
||||||
return fp;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bfree(testfn);
|
Bfree(testfn);
|
||||||
return kopen4loadfrommod(fn, searchfirst);
|
return origfp;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue