mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 11:10:47 +00:00
Slightly simplify S_OpenAudio()...
git-svn-id: https://svn.eduke32.com/eduke32@7210 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
871207294e
commit
bb8e441d0d
1 changed files with 22 additions and 33 deletions
|
@ -1121,57 +1121,46 @@ static int32_t S_TryExtensionReplacements(char * const testfn, char const search
|
|||
int32_t S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
|
||||
{
|
||||
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 *const origparent = origfp != -1 ? kfileparent(origfp) : NULL;
|
||||
uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0;
|
||||
|
||||
char * const testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + origparentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
|
||||
auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
|
||||
|
||||
// look in ./
|
||||
// ex: ./grabbag.mid
|
||||
{
|
||||
Bstrcpy(testfn, fn);
|
||||
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
||||
int32_t fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
||||
if (fp >= 0)
|
||||
{
|
||||
Bfree(testfn);
|
||||
kclose(origfp);
|
||||
return fp;
|
||||
}
|
||||
}
|
||||
goto success;
|
||||
|
||||
// look in ./music/<file's parent GRP name>/
|
||||
// ex: ./music/duke3d/grabbag.mid
|
||||
// ex: ./music/nwinter/grabbag.mid
|
||||
if (origparent != NULL)
|
||||
{
|
||||
char const * const origparentextension = Bstrrchr(origparent, '.');
|
||||
uint32_t namelength = origparentextension != NULL ? (unsigned)(origparentextension - origparent) : origparentlength;
|
||||
char const * const parentextension = Bstrrchr(origparent, '.');
|
||||
uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength;
|
||||
|
||||
Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn);
|
||||
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
||||
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
||||
if (fp >= 0)
|
||||
{
|
||||
Bfree(testfn);
|
||||
kclose(origfp);
|
||||
return fp;
|
||||
}
|
||||
goto success;
|
||||
}
|
||||
|
||||
// look in ./music/
|
||||
// ex: ./music/grabbag.mid
|
||||
{
|
||||
Bsprintf(testfn, "music/%s", fn);
|
||||
int32_t const fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
||||
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
||||
if (fp >= 0)
|
||||
{
|
||||
Bfree(testfn);
|
||||
kclose(origfp);
|
||||
return fp;
|
||||
}
|
||||
}
|
||||
goto success;
|
||||
|
||||
fp = origfp;
|
||||
success:
|
||||
Bfree(testfn);
|
||||
return origfp;
|
||||
if (fp != origfp)
|
||||
kclose(origfp);
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
void Duke_CommonCleanup(void)
|
||||
|
|
Loading…
Reference in a new issue