2012-03-26 22:03:20 +00:00
|
|
|
//
|
|
|
|
// 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!
|
|
|
|
|
2012-03-26 22:03:20 +00:00
|
|
|
#include "compat.h"
|
2012-06-03 16:09:33 +00:00
|
|
|
#include "build.h"
|
2014-08-31 11:15:23 +00:00
|
|
|
#include "baselayer.h"
|
2016-06-21 00:33:06 +00:00
|
|
|
#include "palette.h"
|
2019-10-22 15:47:24 +00:00
|
|
|
#include "gamecvars.h"
|
2019-10-26 11:41:42 +00:00
|
|
|
#include "cmdlib.h"
|
2014-07-28 06:42:28 +00:00
|
|
|
#include "grpscan.h"
|
2019-10-27 12:40:24 +00:00
|
|
|
#include "rts.h"
|
2012-03-26 22:03:20 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
#include "vfs.h"
|
|
|
|
|
2013-03-21 09:48:21 +00:00
|
|
|
#ifdef _WIN32
|
2017-02-25 08:15:01 +00:00
|
|
|
# include "windows_inc.h"
|
2019-09-25 20:38:47 +00:00
|
|
|
# include "win32/winbits.h"
|
2014-12-08 04:31:57 +00:00
|
|
|
#elif defined __APPLE__
|
|
|
|
# include "osxbits.h"
|
2013-03-21 09:48:21 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-26 22:03:20 +00:00
|
|
|
#include "common.h"
|
2012-06-03 16:09:33 +00:00
|
|
|
#include "common_game.h"
|
2012-03-26 22:03:20 +00:00
|
|
|
|
2019-09-21 20:53:00 +00:00
|
|
|
BEGIN_DUKE_NS
|
|
|
|
|
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
struct grpfile_t const *g_selectedGrp;
|
|
|
|
|
2012-06-27 17:45:52 +00:00
|
|
|
int32_t g_gameType = GAMEFLAG_DUKE;
|
2016-08-27 01:41:33 +00:00
|
|
|
int g_addonNum = 0;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
|
|
|
// g_gameNamePtr can point to one of: grpfiles[].name (string literal), string
|
|
|
|
// literal, malloc'd block (XXX: possible leak)
|
|
|
|
const char *g_gameNamePtr = NULL;
|
|
|
|
|
2014-07-28 06:43:46 +00:00
|
|
|
// grp/con handling
|
2012-06-03 16:09:33 +00:00
|
|
|
|
2017-01-18 22:21:08 +00:00
|
|
|
static const char *defaultconfilename = "GAME.CON";
|
|
|
|
#ifndef EDUKE32_STANDALONE
|
2016-08-27 01:41:33 +00:00
|
|
|
static const char *defaultgamegrp[GAMECOUNT] = { "DUKE3D.GRP", "NAM.GRP", "NAPALM.GRP", "WW2GI.GRP" };
|
|
|
|
static const char *defaultdeffilename[GAMECOUNT] = { "duke3d.def", "nam.def", "napalm.def", "ww2gi.def" };
|
2014-12-02 06:15:49 +00:00
|
|
|
static const char *defaultgameconfilename[GAMECOUNT] = { "EDUKE.CON", "NAM.CON", "NAPALM.CON", "WW2GI.CON" };
|
2017-01-18 22:21:08 +00:00
|
|
|
#endif
|
2012-06-03 16:09:33 +00:00
|
|
|
|
|
|
|
// g_grpNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
|
|
|
|
char *g_grpNamePtr = NULL;
|
|
|
|
// g_scriptNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
|
|
|
|
char *g_scriptNamePtr = NULL;
|
|
|
|
|
|
|
|
void clearGrpNamePtr(void)
|
|
|
|
{
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(g_grpNamePtr);
|
2012-06-03 16:09:33 +00:00
|
|
|
// g_grpNamePtr assumed to be assigned to right after
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearScriptNamePtr(void)
|
|
|
|
{
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(g_scriptNamePtr);
|
2012-06-03 16:09:33 +00:00
|
|
|
// g_scriptNamePtr assumed to be assigned to right after
|
|
|
|
}
|
|
|
|
|
2012-07-01 22:11:33 +00:00
|
|
|
const char *G_DefaultGrpFile(void)
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2017-01-18 22:21:08 +00:00
|
|
|
#ifndef EDUKE32_STANDALONE
|
2012-06-03 16:09:33 +00:00
|
|
|
if (DUKE)
|
|
|
|
return defaultgamegrp[GAME_DUKE];
|
|
|
|
else if (NAPALM)
|
|
|
|
return defaultgamegrp[GAME_NAPALM];
|
|
|
|
else if (WW2GI)
|
|
|
|
return defaultgamegrp[GAME_WW2GI];
|
|
|
|
else if (NAM)
|
|
|
|
return defaultgamegrp[GAME_NAM];
|
|
|
|
|
|
|
|
return defaultgamegrp[0];
|
2017-01-18 22:21:08 +00:00
|
|
|
#else
|
|
|
|
return "(none)";
|
|
|
|
#endif
|
2012-06-03 16:09:33 +00:00
|
|
|
}
|
2012-07-01 22:11:33 +00:00
|
|
|
const char *G_DefaultDefFile(void)
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2017-01-18 22:21:08 +00:00
|
|
|
#ifndef EDUKE32_STANDALONE
|
2012-06-03 16:09:33 +00:00
|
|
|
if (DUKE)
|
|
|
|
return defaultdeffilename[GAME_DUKE];
|
|
|
|
else if (WW2GI)
|
|
|
|
return defaultdeffilename[GAME_WW2GI];
|
|
|
|
else if (NAPALM)
|
|
|
|
{
|
2012-06-11 20:35:47 +00:00
|
|
|
if (!testkopen(defaultdeffilename[GAME_NAPALM],0) && testkopen(defaultdeffilename[GAME_NAM],0))
|
2013-03-28 09:05:18 +00:00
|
|
|
return defaultdeffilename[GAME_NAM]; // NAM/NAPALM Sharing
|
2012-06-03 16:09:33 +00:00
|
|
|
else
|
|
|
|
return defaultdeffilename[GAME_NAPALM];
|
|
|
|
}
|
|
|
|
else if (NAM)
|
|
|
|
{
|
2012-06-11 20:35:47 +00:00
|
|
|
if (!testkopen(defaultdeffilename[GAME_NAM],0) && testkopen(defaultdeffilename[GAME_NAPALM],0))
|
2013-03-28 09:05:18 +00:00
|
|
|
return defaultdeffilename[GAME_NAPALM]; // NAM/NAPALM Sharing
|
2012-06-03 16:09:33 +00:00
|
|
|
else
|
|
|
|
return defaultdeffilename[GAME_NAM];
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultdeffilename[0];
|
2017-01-18 22:21:08 +00:00
|
|
|
#else
|
|
|
|
return "(none)";
|
|
|
|
#endif
|
2012-06-03 16:09:33 +00:00
|
|
|
}
|
2012-07-01 22:11:33 +00:00
|
|
|
const char *G_DefaultConFile(void)
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2017-01-18 22:21:08 +00:00
|
|
|
#ifndef EDUKE32_STANDALONE
|
2012-06-11 20:35:47 +00:00
|
|
|
if (DUKE && testkopen(defaultgameconfilename[GAME_DUKE],0))
|
2012-06-03 16:09:33 +00:00
|
|
|
return defaultgameconfilename[GAME_DUKE];
|
2012-06-11 20:35:47 +00:00
|
|
|
else if (WW2GI && testkopen(defaultgameconfilename[GAME_WW2GI],0))
|
2012-06-03 16:09:33 +00:00
|
|
|
return defaultgameconfilename[GAME_WW2GI];
|
|
|
|
else if (NAPALM)
|
|
|
|
{
|
2012-06-11 20:35:47 +00:00
|
|
|
if (!testkopen(defaultgameconfilename[GAME_NAPALM],0))
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2012-06-11 20:35:47 +00:00
|
|
|
if (testkopen(defaultgameconfilename[GAME_NAM],0))
|
2013-03-28 09:05:18 +00:00
|
|
|
return defaultgameconfilename[GAME_NAM]; // NAM/NAPALM Sharing
|
2012-06-03 16:09:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return defaultgameconfilename[GAME_NAPALM];
|
|
|
|
}
|
|
|
|
else if (NAM)
|
|
|
|
{
|
2012-06-11 20:35:47 +00:00
|
|
|
if (!testkopen(defaultgameconfilename[GAME_NAM],0))
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2012-06-11 20:35:47 +00:00
|
|
|
if (testkopen(defaultgameconfilename[GAME_NAPALM],0))
|
2013-03-28 09:05:18 +00:00
|
|
|
return defaultgameconfilename[GAME_NAPALM]; // NAM/NAPALM Sharing
|
2012-06-03 16:09:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return defaultgameconfilename[GAME_NAM];
|
|
|
|
}
|
2017-01-18 22:21:08 +00:00
|
|
|
#endif
|
2012-06-03 16:09:33 +00:00
|
|
|
return defaultconfilename;
|
|
|
|
}
|
|
|
|
|
2012-07-01 22:11:33 +00:00
|
|
|
const char *G_GrpFile(void)
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2016-08-27 01:41:33 +00:00
|
|
|
return (g_grpNamePtr == NULL) ? G_DefaultGrpFile() : g_grpNamePtr;
|
2012-06-03 16:09:33 +00:00
|
|
|
}
|
2013-04-08 18:30:39 +00:00
|
|
|
|
2012-07-01 22:11:33 +00:00
|
|
|
const char *G_DefFile(void)
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2016-08-27 01:41:33 +00:00
|
|
|
return (g_defNamePtr == NULL) ? G_DefaultDefFile() : g_defNamePtr;
|
2012-06-03 16:09:33 +00:00
|
|
|
}
|
2013-04-08 18:30:39 +00:00
|
|
|
|
2012-07-01 22:11:33 +00:00
|
|
|
const char *G_ConFile(void)
|
2012-06-03 16:09:33 +00:00
|
|
|
{
|
2016-08-27 01:41:33 +00:00
|
|
|
return (g_scriptNamePtr == NULL) ? G_DefaultConFile() : g_scriptNamePtr;
|
2012-06-03 16:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////
|
2012-03-26 22:03:20 +00:00
|
|
|
|
2013-08-04 20:37:45 +00:00
|
|
|
// Set up new-style multi-psky handling.
|
2016-08-27 01:41:33 +00:00
|
|
|
void G_InitMultiPsky(int CLOUDYOCEAN__DYN, int MOONSKY1__DYN, int BIGORBIT1__DYN, int LA__DYN)
|
2012-11-25 04:25:31 +00:00
|
|
|
{
|
2013-08-04 20:37:45 +00:00
|
|
|
// When adding other multi-skies, take care that the tileofs[] values are
|
|
|
|
// <= PSKYOFF_MAX. (It can be increased up to MAXPSKYTILES, but should be
|
|
|
|
// set as tight as possible.)
|
2012-11-25 04:25:31 +00:00
|
|
|
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
// The default sky properties (all others are implicitly zero):
|
2018-04-12 21:03:47 +00:00
|
|
|
psky_t *sky = tileSetupSky(DEFAULTPSKY);
|
2016-08-27 01:41:33 +00:00
|
|
|
sky->lognumtiles = 3;
|
|
|
|
sky->horizfrac = 32768;
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
|
|
|
|
// CLOUDYOCEAN
|
|
|
|
// Aligns with the drawn scene horizon because it has one itself.
|
2018-04-12 21:03:47 +00:00
|
|
|
sky = tileSetupSky(CLOUDYOCEAN__DYN);
|
2016-08-27 01:41:33 +00:00
|
|
|
sky->lognumtiles = 3;
|
|
|
|
sky->horizfrac = 65536;
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
|
2012-11-25 04:25:31 +00:00
|
|
|
// MOONSKY1
|
|
|
|
// earth mountain mountain sun
|
2018-04-12 21:03:47 +00:00
|
|
|
sky = tileSetupSky(MOONSKY1__DYN);
|
2016-08-27 01:41:33 +00:00
|
|
|
sky->lognumtiles = 3;
|
|
|
|
sky->horizfrac = 32768;
|
|
|
|
sky->tileofs[6] = 1;
|
|
|
|
sky->tileofs[1] = 2;
|
|
|
|
sky->tileofs[4] = 2;
|
|
|
|
sky->tileofs[2] = 3;
|
2012-11-25 04:25:31 +00:00
|
|
|
|
|
|
|
// BIGORBIT1 // orbit
|
|
|
|
// earth1 2 3 moon/sun
|
2018-04-12 21:03:47 +00:00
|
|
|
sky = tileSetupSky(BIGORBIT1__DYN);
|
2016-08-27 01:41:33 +00:00
|
|
|
sky->lognumtiles = 3;
|
|
|
|
sky->horizfrac = 32768;
|
|
|
|
sky->tileofs[5] = 1;
|
|
|
|
sky->tileofs[6] = 2;
|
|
|
|
sky->tileofs[7] = 3;
|
|
|
|
sky->tileofs[2] = 4;
|
2012-11-25 04:25:31 +00:00
|
|
|
|
|
|
|
// LA // la city
|
|
|
|
// earth1 2 3 moon/sun
|
2018-04-12 21:03:47 +00:00
|
|
|
sky = tileSetupSky(LA__DYN);
|
2016-08-27 01:41:33 +00:00
|
|
|
sky->lognumtiles = 3;
|
|
|
|
sky->horizfrac = 16384 + 1024;
|
|
|
|
sky->tileofs[0] = 1;
|
|
|
|
sky->tileofs[1] = 2;
|
|
|
|
sky->tileofs[2] = 1;
|
|
|
|
sky->tileofs[3] = 3;
|
|
|
|
sky->tileofs[4] = 4;
|
|
|
|
sky->tileofs[5] = 0;
|
|
|
|
sky->tileofs[6] = 2;
|
|
|
|
sky->tileofs[7] = 3;
|
2013-08-04 20:37:45 +00:00
|
|
|
|
2015-05-27 08:47:34 +00:00
|
|
|
#if 0
|
|
|
|
// This assertion should hold. See note above.
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=0; i<pskynummultis; ++i)
|
|
|
|
for (bssize_t j=0; j<(1<<multipsky[i].lognumtiles); ++j)
|
2013-08-04 20:37:45 +00:00
|
|
|
Bassert(multipsky[i].tileofs[j] <= PSKYOFF_MAX);
|
2015-05-27 08:47:34 +00:00
|
|
|
#endif
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void G_SetupGlobalPsky(void)
|
|
|
|
{
|
2016-08-27 01:41:33 +00:00
|
|
|
int skyIdx = 0;
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
|
|
|
|
// NOTE: Loop must be running backwards for the same behavior as the game
|
|
|
|
// (greatest sector index with matching parallaxed sky takes precedence).
|
2018-11-18 18:08:14 +00:00
|
|
|
for (int i = numsectors - 1; i >= 0; i--)
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
{
|
|
|
|
if (sector[i].ceilingstat & 1)
|
|
|
|
{
|
2016-08-27 01:41:33 +00:00
|
|
|
skyIdx = getpskyidx(sector[i].ceilingpicnum);
|
|
|
|
if (skyIdx > 0)
|
Clean up parallaxed sky functionality, part 2.
- Rename sky_t members: yscale -> horizfrac, bits -> lognumtiles.
- Add default sky (8 tiles, horizfrac=32768 (i.e. 1/2 the scene horiz), offsets
all zero) and CLOUDYOCEAN sky (8 tiles, horizfrac=65536, offsets all zero)
to multipsky[].
- Get rid of "psky_t g_psky", merely maintaining a g_pskyidx instead. Set it up
at map load time so as to keep the behavior of the legacy per-map psky:
the last sector index with a matching psky ceiling wins.
- In mapstate_t, save g_pskyidx too, not (former) pskybits and pskyoffs[].
- Make on-map-load global psky setup consistent for the game and editor by
factoring it out into common.c: G_SetupGlobalPsky().
- Remove a couple of useless initializations, add some static assertions.
This commit is more likely to introduce subtle differences in behavior.
Specifically, getpsky() now always returns the default sky properties instead of
the global sky ones (but with all-zero offsets) when no match for a suiting
multi-psky is found. This is only likely to affect the yscale/horizfrac of
non-multi-pskies when a global non-default multi-psky has been set up.
Bump BYTEVERSION again.
git-svn-id: https://svn.eduke32.com/eduke32@3976 1a8010ca-5511-0410-912e-c29ae57300e0
2013-08-04 20:37:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 04:25:31 +00:00
|
|
|
|
2016-08-27 01:41:33 +00:00
|
|
|
g_pskyidx = skyIdx;
|
2012-11-25 04:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////
|
|
|
|
|
2019-09-19 21:02:57 +00:00
|
|
|
//char g_modDir[BMAX_PATH] = "/";
|
2014-07-28 06:42:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void G_LoadAddon(void);
|
|
|
|
int32_t g_groupFileHandle;
|
2019-09-21 20:53:00 +00:00
|
|
|
struct strllist* CommandPaths, * CommandGrps;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
|
|
|
void G_ExtInit(void)
|
|
|
|
{
|
2015-02-14 07:26:10 +00:00
|
|
|
#ifdef EDUKE32_OSX
|
2014-12-08 04:31:57 +00:00
|
|
|
char *appdir = Bgetappdir();
|
|
|
|
addsearchpath(appdir);
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(appdir);
|
2014-07-28 06:42:28 +00:00
|
|
|
#endif
|
2014-12-08 04:31:57 +00:00
|
|
|
|
2019-10-30 05:51:44 +00:00
|
|
|
char cwd[BMAX_PATH];
|
2019-03-01 08:51:50 +00:00
|
|
|
#ifdef USE_PHYSFS
|
|
|
|
strncpy(cwd, PHYSFS_getBaseDir(), ARRAY_SIZE(cwd));
|
|
|
|
cwd[ARRAY_SIZE(cwd)-1] = '\0';
|
|
|
|
#else
|
|
|
|
if (buildvfs_getcwd(cwd, ARRAY_SIZE(cwd)) && Bstrcmp(cwd, "/") != 0)
|
|
|
|
#endif
|
2014-07-28 06:42:28 +00:00
|
|
|
addsearchpath(cwd);
|
|
|
|
|
|
|
|
if (CommandPaths)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
struct strllist *s;
|
|
|
|
while (CommandPaths)
|
|
|
|
{
|
|
|
|
s = CommandPaths->next;
|
|
|
|
i = addsearchpath(CommandPaths->str);
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
initprintf("Failed adding %s for game data: %s\n", CommandPaths->str,
|
|
|
|
i==-1 ? "not a directory" : "no such directory");
|
|
|
|
}
|
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(CommandPaths->str);
|
|
|
|
Xfree(CommandPaths);
|
2014-07-28 06:42:28 +00:00
|
|
|
CommandPaths = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 05:22:19 +00:00
|
|
|
void G_ScanGroups(void)
|
2014-07-28 06:42:28 +00:00
|
|
|
{
|
|
|
|
ScanGroups();
|
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
g_selectedGrp = NULL;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
char const * const currentGrp = G_GrpFile();
|
2015-02-11 05:22:19 +00:00
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
for (grpfile_t const *fg = foundgrps; fg; fg=fg->next)
|
2015-02-11 05:22:19 +00:00
|
|
|
{
|
2015-03-27 12:30:35 +00:00
|
|
|
if (!Bstrcasecmp(fg->filename, currentGrp))
|
2014-07-28 06:42:28 +00:00
|
|
|
{
|
2015-03-27 12:30:35 +00:00
|
|
|
g_selectedGrp = fg;
|
|
|
|
break;
|
2014-07-28 06:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-18 22:21:31 +00:00
|
|
|
|
|
|
|
if (g_selectedGrp == NULL)
|
|
|
|
g_selectedGrp = foundgrps;
|
2015-03-27 12:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t G_TryLoadingGrp(char const * const grpfile)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
if ((i = initgroupfile(grpfile)) == -1)
|
|
|
|
initprintf("Warning: could not find main data file \"%s\"!\n", grpfile);
|
|
|
|
else
|
|
|
|
initprintf("Using \"%s\" as main game data file.\n", grpfile);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t G_LoadGrpDependencyChain(grpfile_t const * const grp)
|
|
|
|
{
|
|
|
|
if (!grp)
|
|
|
|
return -1;
|
|
|
|
|
2015-07-08 03:34:13 +00:00
|
|
|
if (grp->type->dependency && grp->type->dependency != grp->type->crcval)
|
2015-03-27 12:30:35 +00:00
|
|
|
G_LoadGrpDependencyChain(FindGroup(grp->type->dependency));
|
|
|
|
|
|
|
|
int32_t const i = G_TryLoadingGrp(grp->filename);
|
|
|
|
|
|
|
|
if (grp->type->postprocessing)
|
2017-10-30 03:48:28 +00:00
|
|
|
grp->type->postprocessing(i);
|
2015-03-27 12:30:35 +00:00
|
|
|
|
|
|
|
return i;
|
2014-07-28 06:42:28 +00:00
|
|
|
}
|
2013-03-21 09:49:12 +00:00
|
|
|
|
2019-10-27 08:38:55 +00:00
|
|
|
void G_LoadGroups()
|
2013-03-21 09:49:12 +00:00
|
|
|
{
|
2014-07-28 06:42:28 +00:00
|
|
|
if (g_modDir[0] != '/')
|
|
|
|
{
|
|
|
|
char cwd[BMAX_PATH];
|
|
|
|
|
2019-10-26 11:41:42 +00:00
|
|
|
FString g_rootDir = progdir + g_modDir;
|
|
|
|
addsearchpath(g_rootDir);
|
2015-02-11 05:22:19 +00:00
|
|
|
// addsearchpath(mod_dir);
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2018-09-06 19:06:55 +00:00
|
|
|
char path[BMAX_PATH];
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
if (buildvfs_getcwd(cwd, BMAX_PATH))
|
2014-07-28 06:42:28 +00:00
|
|
|
{
|
2018-09-06 19:06:55 +00:00
|
|
|
Bsnprintf(path, sizeof(path), "%s/%s", cwd, g_modDir);
|
|
|
|
if (!Bstrcmp(g_rootDir, path))
|
2014-07-28 06:42:28 +00:00
|
|
|
{
|
2019-10-30 20:51:04 +00:00
|
|
|
addsearchpath(path);
|
2014-07-28 06:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-27 01:41:33 +00:00
|
|
|
if (g_addonNum)
|
2014-07-28 06:42:28 +00:00
|
|
|
G_LoadAddon();
|
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
const char *grpfile;
|
2015-02-11 05:22:19 +00:00
|
|
|
int32_t i;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
if ((i = G_LoadGrpDependencyChain(g_selectedGrp)) != -1)
|
2015-02-11 05:22:19 +00:00
|
|
|
{
|
2015-03-27 12:30:35 +00:00
|
|
|
grpfile = g_selectedGrp->filename;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
clearGrpNamePtr();
|
|
|
|
g_grpNamePtr = dup_filename(grpfile);
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
grpinfo_t const * const type = g_selectedGrp->type;
|
|
|
|
|
|
|
|
g_gameType = type->game;
|
|
|
|
g_gameNamePtr = type->name;
|
|
|
|
|
|
|
|
if (type->scriptname && g_scriptNamePtr == NULL)
|
|
|
|
g_scriptNamePtr = dup_filename(type->scriptname);
|
|
|
|
|
|
|
|
if (type->defname && g_defNamePtr == NULL)
|
|
|
|
g_defNamePtr = dup_filename(type->defname);
|
2018-02-11 05:03:55 +00:00
|
|
|
|
2019-10-27 12:40:24 +00:00
|
|
|
if (type->rtsname)
|
|
|
|
RTS_Init(type->rtsname);
|
2015-03-27 12:30:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
grpfile = G_GrpFile();
|
|
|
|
i = G_TryLoadingGrp(grpfile);
|
|
|
|
}
|
2015-03-23 06:28:27 +00:00
|
|
|
|
2019-10-27 08:38:55 +00:00
|
|
|
if (G_AllowAutoload())
|
2015-02-11 05:22:19 +00:00
|
|
|
{
|
|
|
|
G_LoadGroupsInDir("autoload");
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-02-11 05:22:19 +00:00
|
|
|
if (i != -1)
|
|
|
|
G_DoAutoload(grpfile);
|
2014-07-28 06:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_modDir[0] != '/')
|
|
|
|
G_LoadGroupsInDir(g_modDir);
|
|
|
|
|
2017-01-18 22:21:08 +00:00
|
|
|
#ifndef EDUKE32_STANDALONE
|
2014-07-28 06:42:28 +00:00
|
|
|
if (g_defNamePtr == NULL)
|
|
|
|
{
|
|
|
|
const char *tmpptr = getenv("DUKE3DDEF");
|
|
|
|
if (tmpptr)
|
|
|
|
{
|
|
|
|
clearDefNamePtr();
|
|
|
|
g_defNamePtr = dup_filename(tmpptr);
|
|
|
|
initprintf("Using \"%s\" as definitions file\n", g_defNamePtr);
|
|
|
|
}
|
|
|
|
}
|
2017-01-18 22:21:08 +00:00
|
|
|
#endif
|
2014-07-28 06:42:28 +00:00
|
|
|
|
|
|
|
loaddefinitions_game(G_DefFile(), TRUE);
|
|
|
|
|
2015-02-11 05:22:19 +00:00
|
|
|
struct strllist *s;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-07-08 03:34:16 +00:00
|
|
|
int const bakpathsearchmode = pathsearchmode;
|
2015-02-11 05:22:19 +00:00
|
|
|
pathsearchmode = 1;
|
2015-07-08 03:34:16 +00:00
|
|
|
|
2015-02-11 05:22:19 +00:00
|
|
|
while (CommandGrps)
|
|
|
|
{
|
|
|
|
int32_t j;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-02-11 05:22:19 +00:00
|
|
|
s = CommandGrps->next;
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-02-11 05:22:19 +00:00
|
|
|
if ((j = initgroupfile(CommandGrps->str)) == -1)
|
|
|
|
initprintf("Could not find file \"%s\".\n", CommandGrps->str);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_groupFileHandle = j;
|
|
|
|
initprintf("Using file \"%s\" as game data.\n", CommandGrps->str);
|
2019-10-27 08:38:55 +00:00
|
|
|
if (G_AllowAutoload())
|
2015-02-11 05:22:19 +00:00
|
|
|
G_DoAutoload(CommandGrps->str);
|
2014-07-28 06:42:28 +00:00
|
|
|
}
|
2015-02-11 05:22:19 +00:00
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(CommandGrps->str);
|
|
|
|
Xfree(CommandGrps);
|
2015-02-11 05:22:19 +00:00
|
|
|
CommandGrps = s;
|
2014-07-28 06:42:28 +00:00
|
|
|
}
|
2015-07-08 03:34:16 +00:00
|
|
|
pathsearchmode = bakpathsearchmode;
|
2013-03-21 09:49:12 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 23:35:52 +00:00
|
|
|
|
|
|
|
|
2014-07-28 06:42:28 +00:00
|
|
|
static void G_LoadAddon(void)
|
|
|
|
{
|
2017-01-18 22:21:08 +00:00
|
|
|
#ifndef EDUKE32_STANDALONE
|
2014-07-28 06:42:28 +00:00
|
|
|
int32_t crc = 0; // compiler-happy
|
|
|
|
|
2016-08-27 01:41:33 +00:00
|
|
|
switch (g_addonNum)
|
2014-07-28 06:42:28 +00:00
|
|
|
{
|
|
|
|
case ADDON_DUKEDC:
|
|
|
|
crc = DUKEDC_CRC;
|
|
|
|
break;
|
|
|
|
case ADDON_NWINTER:
|
|
|
|
crc = DUKENW_CRC;
|
|
|
|
break;
|
|
|
|
case ADDON_CARIBBEAN:
|
|
|
|
crc = DUKECB_CRC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!crc) return;
|
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
grpfile_t const * const grp = FindGroup(crc);
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2015-03-27 12:30:35 +00:00
|
|
|
if (grp)
|
|
|
|
g_selectedGrp = grp;
|
2017-01-18 22:21:08 +00:00
|
|
|
#endif
|
2014-07-28 06:42:28 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 09:48:21 +00:00
|
|
|
|
2013-04-08 18:30:39 +00:00
|
|
|
void G_CleanupSearchPaths(void)
|
|
|
|
{
|
2015-01-08 15:14:47 +00:00
|
|
|
removesearchpaths_withuser(SEARCHPATH_REMOVE);
|
2014-09-30 03:53:14 +00:00
|
|
|
|
2015-11-25 12:08:24 +00:00
|
|
|
if (!NAM)
|
2015-01-08 15:14:47 +00:00
|
|
|
removesearchpaths_withuser(SEARCHPATH_NAM);
|
2015-11-25 12:08:37 +00:00
|
|
|
|
|
|
|
if (!WW2GI)
|
|
|
|
removesearchpaths_withuser(SEARCHPATH_WW2GI);
|
2013-04-08 18:30:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 09:48:21 +00:00
|
|
|
//////////
|
|
|
|
|
2012-03-26 22:03:20 +00:00
|
|
|
|
2018-02-17 22:30:39 +00:00
|
|
|
GrowArray<char *> g_scriptModules;
|
2013-11-03 04:02:23 +00:00
|
|
|
|
2012-03-26 22:03:20 +00:00
|
|
|
void G_AddGroup(const char *buffer)
|
|
|
|
{
|
|
|
|
char buf[BMAX_PATH];
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
struct strllist *s = (struct strllist *)Xcalloc(1,sizeof(struct strllist));
|
2012-03-26 22:03:20 +00:00
|
|
|
|
|
|
|
Bstrcpy(buf, buffer);
|
|
|
|
|
|
|
|
if (Bstrchr(buf,'.') == 0)
|
|
|
|
Bstrcat(buf,".grp");
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
s->str = Xstrdup(buf);
|
2012-03-26 22:03:20 +00:00
|
|
|
|
|
|
|
if (CommandGrps)
|
|
|
|
{
|
|
|
|
struct strllist *t;
|
|
|
|
for (t = CommandGrps; t->next; t=t->next) ;
|
|
|
|
t->next = s;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CommandGrps = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void G_AddPath(const char *buffer)
|
|
|
|
{
|
2014-05-30 00:02:19 +00:00
|
|
|
struct strllist *s = (struct strllist *)Xcalloc(1,sizeof(struct strllist));
|
|
|
|
s->str = Xstrdup(buffer);
|
2012-03-26 22:03:20 +00:00
|
|
|
|
|
|
|
if (CommandPaths)
|
|
|
|
{
|
|
|
|
struct strllist *t;
|
|
|
|
for (t = CommandPaths; t->next; t=t->next) ;
|
|
|
|
t->next = s;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CommandPaths = s;
|
|
|
|
}
|
2012-03-26 22:05:23 +00:00
|
|
|
|
2013-11-03 04:02:23 +00:00
|
|
|
void G_AddCon(const char *buffer)
|
|
|
|
{
|
|
|
|
clearScriptNamePtr();
|
|
|
|
g_scriptNamePtr = dup_filename(buffer);
|
|
|
|
initprintf("Using CON file \"%s\".\n",g_scriptNamePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void G_AddConModule(const char *buffer)
|
|
|
|
{
|
2018-02-17 22:30:39 +00:00
|
|
|
g_scriptModules.append(Xstrdup(buffer));
|
2013-11-03 04:02:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 22:05:23 +00:00
|
|
|
//////////
|
|
|
|
|
2012-12-12 02:53:10 +00:00
|
|
|
// loads all group (grp, zip, pk3/4) files in the given directory
|
2012-03-28 19:41:57 +00:00
|
|
|
void G_LoadGroupsInDir(const char *dirname)
|
|
|
|
{
|
2016-03-14 00:07:55 +00:00
|
|
|
static const char *extensions[] = { "*.grp", "*.zip", "*.ssi", "*.pk3", "*.pk4" };
|
2012-03-28 19:41:57 +00:00
|
|
|
char buf[BMAX_PATH];
|
|
|
|
fnlist_t fnlist = FNLIST_INITIALIZER;
|
|
|
|
|
2018-10-25 23:33:40 +00:00
|
|
|
for (auto & extension : extensions)
|
2012-03-28 19:41:57 +00:00
|
|
|
{
|
|
|
|
CACHE1D_FIND_REC *rec;
|
|
|
|
|
2018-10-25 23:33:40 +00:00
|
|
|
fnlist_getnames(&fnlist, dirname, extension, -1, 0);
|
2012-03-28 19:41:57 +00:00
|
|
|
|
|
|
|
for (rec=fnlist.findfiles; rec; rec=rec->next)
|
|
|
|
{
|
|
|
|
Bsnprintf(buf, sizeof(buf), "%s/%s", dirname, rec->name);
|
|
|
|
initprintf("Using group file \"%s\".\n", buf);
|
|
|
|
initgroupfile(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
fnlist_clearnames(&fnlist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void G_DoAutoload(const char *dirname)
|
|
|
|
{
|
|
|
|
char buf[BMAX_PATH];
|
|
|
|
|
|
|
|
Bsnprintf(buf, sizeof(buf), "autoload/%s", dirname);
|
|
|
|
G_LoadGroupsInDir(buf);
|
|
|
|
}
|
2014-07-28 06:45:53 +00:00
|
|
|
|
|
|
|
//////////
|
|
|
|
|
2015-09-23 17:54:55 +00:00
|
|
|
void G_LoadLookups(void)
|
2014-07-28 06:45:53 +00:00
|
|
|
{
|
2019-03-01 08:51:50 +00:00
|
|
|
int32_t j;
|
2014-07-28 06:45:53 +00:00
|
|
|
|
2019-10-20 20:26:53 +00:00
|
|
|
auto fr = kopenFileReader("lookup.dat", 0);
|
|
|
|
if (!fr.isOpen())
|
|
|
|
return;
|
2014-07-28 06:45:53 +00:00
|
|
|
|
2019-10-20 20:26:53 +00:00
|
|
|
j = paletteLoadLookupTable(fr);
|
2014-07-28 06:45:53 +00:00
|
|
|
|
|
|
|
if (j < 0)
|
|
|
|
{
|
|
|
|
if (j == -1)
|
|
|
|
initprintf("ERROR loading \"lookup.dat\": failed reading enough data.\n");
|
2015-09-23 17:54:55 +00:00
|
|
|
|
2019-10-20 20:26:53 +00:00
|
|
|
return;
|
2014-07-28 06:45:53 +00:00
|
|
|
}
|
|
|
|
|
2015-09-23 17:55:02 +00:00
|
|
|
uint8_t paldata[768];
|
|
|
|
|
2014-07-28 06:45:53 +00:00
|
|
|
for (j=1; j<=5; j++)
|
|
|
|
{
|
|
|
|
// Account for TITLE and REALMS swap between basepal number and on-disk order.
|
|
|
|
int32_t basepalnum = (j == 3 || j == 4) ? 4+3-j : j;
|
|
|
|
|
2019-10-20 20:26:53 +00:00
|
|
|
if (fr.Read(paldata, 768) != 768)
|
|
|
|
return;
|
2015-09-23 17:55:02 +00:00
|
|
|
|
2018-10-25 23:33:40 +00:00
|
|
|
for (unsigned char & k : paldata)
|
|
|
|
k <<= 2;
|
2015-09-23 17:55:11 +00:00
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
paletteSetColorTable(basepalnum, paldata);
|
2014-07-28 06:45:53 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-25 12:17:59 +00:00
|
|
|
|
2015-11-25 12:08:07 +00:00
|
|
|
//////////
|
|
|
|
|
2016-01-12 10:31:05 +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)
|
2015-01-25 12:17:59 +00:00
|
|
|
{
|
2019-10-19 23:47:12 +00:00
|
|
|
#ifdef HAVE_FLAC
|
2019-10-20 21:37:07 +00:00
|
|
|
{
|
2015-11-25 12:08:07 +00:00
|
|
|
Bstrcpy(fn_suffix, ".flac");
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = kopenFileReader(testfn, searchfirst);
|
|
|
|
if (fp.isOpen())
|
|
|
|
return fp;
|
|
|
|
}
|
2015-11-25 12:08:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_VORBIS
|
2019-10-20 21:37:07 +00:00
|
|
|
{
|
2015-11-25 12:08:07 +00:00
|
|
|
Bstrcpy(fn_suffix, ".ogg");
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = kopenFileReader(testfn, searchfirst);
|
|
|
|
if (fp.isOpen())
|
|
|
|
return fp;
|
|
|
|
}
|
2015-11-25 12:08:07 +00:00
|
|
|
#endif
|
2015-01-25 12:17:59 +00:00
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
return FileReader();
|
2015-11-25 12:08:07 +00:00
|
|
|
}
|
2015-01-25 12:17:59 +00:00
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
static FileReader S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic)
|
2015-11-25 12:08:07 +00:00
|
|
|
{
|
|
|
|
char * extension = Bstrrchr(testfn, '.');
|
|
|
|
char * const fn_end = Bstrchr(testfn, '\0');
|
|
|
|
|
|
|
|
// ex: grabbag.voc --> grabbag_voc.*
|
2015-05-27 08:46:12 +00:00
|
|
|
if (extension != NULL)
|
2015-01-25 12:17:59 +00:00
|
|
|
{
|
2015-05-27 08:46:12 +00:00
|
|
|
*extension = '_';
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = S_TryFormats(testfn, fn_end, searchfirst);
|
|
|
|
if (fp.isOpen())
|
2015-05-27 08:46:12 +00:00
|
|
|
return fp;
|
2015-11-25 12:08:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
extension = fn_end;
|
|
|
|
}
|
2015-05-27 08:46:12 +00:00
|
|
|
|
2015-11-25 12:08:07 +00:00
|
|
|
// ex: grabbag.mid --> grabbag.*
|
2017-02-25 08:16:04 +00:00
|
|
|
if (ismusic)
|
2015-11-25 12:08:07 +00:00
|
|
|
{
|
2019-10-20 21:37:07 +00:00
|
|
|
auto fp = S_TryFormats(testfn, extension, searchfirst);
|
|
|
|
if (fp.isOpen())
|
|
|
|
return fp;
|
2015-11-25 12:08:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
return FileReader();
|
2015-11-25 12:08:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
FileReader S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
|
2015-11-25 12:08:07 +00:00
|
|
|
{
|
2019-10-20 21:37:07 +00:00
|
|
|
auto origfp = kopenFileReader(fn, searchfirst);
|
2019-10-22 00:01:05 +00:00
|
|
|
if (!snd_tryformats) return origfp;
|
|
|
|
|
2019-10-20 21:37:07 +00:00
|
|
|
char const* const origparent = origfp.isOpen() ? kfileparent(origfp) : NULL;
|
|
|
|
uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0;
|
2015-11-25 12:08:07 +00:00
|
|
|
|
2018-11-18 18:12:11 +00:00
|
|
|
auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
|
2015-11-25 12:08:07 +00:00
|
|
|
|
|
|
|
// look in ./
|
|
|
|
// ex: ./grabbag.mid
|
2018-11-18 18:12:11 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-05-27 08:46:12 +00:00
|
|
|
|
2015-11-25 12:08:07 +00:00
|
|
|
// look in ./music/<file's parent GRP name>/
|
|
|
|
// ex: ./music/duke3d/grabbag.mid
|
|
|
|
// ex: ./music/nwinter/grabbag.mid
|
|
|
|
if (origparent != NULL)
|
|
|
|
{
|
2018-11-18 18:12:11 +00:00
|
|
|
char const * const parentextension = Bstrrchr(origparent, '.');
|
|
|
|
uint32_t const namelength = parentextension != NULL ? (unsigned)(parentextension - origparent) : parentlength;
|
2015-11-25 12:08:07 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2015-11-25 12:08:07 +00:00
|
|
|
}
|
2015-01-25 12:17:59 +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;
|
2015-01-25 12:17:59 +00:00
|
|
|
}
|
2016-01-12 10:31:05 +00:00
|
|
|
|
2018-02-11 05:03:55 +00:00
|
|
|
void Duke_CommonCleanup(void)
|
|
|
|
{
|
|
|
|
DO_FREE_AND_NULL(g_grpNamePtr);
|
|
|
|
DO_FREE_AND_NULL(g_scriptNamePtr);
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:31:05 +00:00
|
|
|
#endif
|
2019-09-21 20:53:00 +00:00
|
|
|
|
|
|
|
END_DUKE_NS
|