2019-09-19 22:42:45 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 Nuke.YKT
|
|
|
|
|
|
|
|
This file is part of NBlood.
|
|
|
|
|
|
|
|
NBlood is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//
|
|
|
|
// Common non-engine code/data for EDuke32 and Mapster32
|
|
|
|
//
|
|
|
|
|
2019-09-21 18:59:54 +00:00
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "baselayer.h"
|
2019-10-26 11:41:42 +00:00
|
|
|
#include "cmdlib.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "palette.h"
|
2019-10-27 08:38:55 +00:00
|
|
|
#include "gamecvars.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define NEED_SHLWAPI_H
|
|
|
|
# include "windows_inc.h"
|
2019-09-25 20:38:47 +00:00
|
|
|
# include "win32/winbits.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
# ifndef KEY_WOW64_64KEY
|
|
|
|
# define KEY_WOW64_64KEY 0x0100
|
|
|
|
# endif
|
|
|
|
# ifndef KEY_WOW64_32KEY
|
|
|
|
# define KEY_WOW64_32KEY 0x0200
|
|
|
|
# endif
|
|
|
|
#elif defined __APPLE__
|
|
|
|
# include "osxbits.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "common_game.h"
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
|
2019-06-27 04:33:22 +00:00
|
|
|
void G_SetupGlobalPsky(void)
|
|
|
|
{
|
|
|
|
int skyIdx = 0;
|
|
|
|
|
|
|
|
// NOTE: Loop must be running backwards for the same behavior as the game
|
|
|
|
// (greatest sector index with matching parallaxed sky takes precedence).
|
|
|
|
for (bssize_t i = numsectors - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (sector[i].ceilingstat & 1)
|
|
|
|
{
|
|
|
|
skyIdx = getpskyidx(sector[i].ceilingpicnum);
|
|
|
|
if (skyIdx > 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_pskyidx = skyIdx;
|
|
|
|
}
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
//////////
|
|
|
|
|
|
|
|
#ifdef FORMAT_UPGRADE_ELIGIBLE
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
static FileReader S_TryFormats(char * const testfn, char * const fn_suffix, char const searchfirst)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_FLAC
|
|
|
|
{
|
|
|
|
Bstrcpy(fn_suffix, ".flac");
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = kopenFileReader(testfn, searchfirst);
|
|
|
|
if (fp.isOpen())
|
2019-09-19 22:42:45 +00:00
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_VORBIS
|
|
|
|
{
|
|
|
|
Bstrcpy(fn_suffix, ".ogg");
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = kopenFileReader(testfn, searchfirst);
|
|
|
|
if (fp.isOpen())
|
|
|
|
return fp;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
#endif
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
return FileReader();
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
static FileReader S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
char * extension = Bstrrchr(testfn, '.');
|
|
|
|
char * const fn_end = Bstrchr(testfn, '\0');
|
|
|
|
|
|
|
|
// ex: grabbag.voc --> grabbag_voc.*
|
|
|
|
if (extension != NULL)
|
|
|
|
{
|
|
|
|
*extension = '_';
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = S_TryFormats(testfn, fn_end, searchfirst);
|
|
|
|
if (fp.isOpen())
|
2019-09-19 22:42:45 +00:00
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
extension = fn_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ex: grabbag.mid --> grabbag.*
|
|
|
|
if (ismusic)
|
|
|
|
{
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = S_TryFormats(testfn, extension, searchfirst);
|
|
|
|
if (fp.isOpen())
|
|
|
|
return fp;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
return FileReader();
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2019-10-20 21:37:07 +00:00
|
|
|
auto origfp = kopenFileReader(fn, searchfirst);
|
|
|
|
char const* const origparent = origfp.isOpen() ? kfileparent(origfp) : NULL;
|
|
|
|
uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
|
|
|
|
|
|
|
|
// look in ./
|
|
|
|
// ex: ./grabbag.mid
|
|
|
|
Bstrcpy(testfn, fn);
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
|
|
|
if (fp.isOpen())
|
|
|
|
{
|
|
|
|
Bfree(testfn);
|
|
|
|
return fp;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
// look in ./music/<file's parent GRP name>/
|
|
|
|
// ex: ./music/duke3d/grabbag.mid
|
|
|
|
// ex: ./music/nwinter/grabbag.mid
|
|
|
|
if (origparent != NULL)
|
|
|
|
{
|
|
|
|
char const * const parentextension = Bstrrchr(origparent, '.');
|
|
|
|
uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength;
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn);
|
|
|
|
auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
|
|
|
if (fp.isOpen())
|
|
|
|
{
|
|
|
|
Bfree(testfn);
|
|
|
|
return fp;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
// look in ./music/
|
|
|
|
// ex: ./music/grabbag.mid
|
|
|
|
{
|
|
|
|
Bsprintf(testfn, "music/%s", fn);
|
|
|
|
auto fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
|
|
|
|
if (fp.isOpen())
|
|
|
|
{
|
|
|
|
Bfree(testfn);
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bfree(testfn);
|
|
|
|
return origfp;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
END_BLD_NS
|