- better .def loading logic.

To allow cumulative loading without interfering with other ports, Raze will now look for files called xxxx-raze.def, where xxxx is the default .def name (e.g. duke3d-raze.def for Duke3D.) and if that is found, cumulatively load all same-named files - it will fall back on the default name if no such thing is found.
-def still overrides both and will not cumulatively load.
This commit is contained in:
Christoph Oelckers 2021-04-07 21:46:44 +02:00
parent 03c19a0cad
commit fb02b38279
4 changed files with 67 additions and 38 deletions

View file

@ -759,7 +759,7 @@ int32_t md_definehud (int32_t modelid, int32_t tilex, vec3f_t add,
int32_t md_undefinetile(int32_t tile);
int32_t md_undefinemodel(int32_t modelid);
int32_t loaddefinitionsfile(const char *fn, bool loadadds = false);
int32_t loaddefinitionsfile(const char *fn, bool loadadds = false, bool cumulative = false);
// if loadboard() fails with -2 return, try loadoldboard(). if it fails with
// -2, board is dodgy

View file

@ -211,8 +211,6 @@ enum scripttoken_t
};
static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0;
static char *faketilebuffer = NULL;
static int32_t faketilebuffersiz = 0;
static const char *skyfaces[6] =
{
@ -3169,37 +3167,44 @@ static int32_t defsparser(scriptfile *script)
return 0;
}
int32_t loaddefinitionsfile(const char *fn, bool loadadds)
int32_t loaddefinitionsfile(const char *fn, bool loadadds, bool cumulative)
{
scriptfile *script;
script = scriptfile_fromfile(fn);
if (script)
bool done = false;
auto parseit = [&](int lump)
{
Printf(PRINT_NONOTIFY, "Loading \"%s\"\n",fn);
FScanner sc;
sc.OpenLumpNum(lump);
sc.SetNoOctals(true);
sc.SetNoFatalErrors(true);
defsparser(&sc);
done = true;
Printf(PRINT_NONOTIFY, "\n");
};
defsparser(script);
if (!cumulative)
{
int lump = fileSystem.FindFile(fn);
if (lump >= 0)
{
Printf(PRINT_NONOTIFY, "Loading \"%s\"\n", fn);
parseit(lump);
}
}
else
{
int lump, lastlump = 0;
while ((lump = fileSystem.FindLumpFullName(fn, &lastlump)) >= 0)
{
Printf(PRINT_NONOTIFY, "Loading \"%s\"\n", fileSystem.GetFileFullPath(lump));
parseit(lump);
}
}
if (userConfig.AddDefs && loadadds) for (auto& m : *userConfig.AddDefs)
{
Printf("Loading module \"%s\"\n",m.GetChars());
defsparser_include(m, NULL, NULL); // Q: should we let the external script see our symbol table?
}
if (script)
scriptfile_close(script);
DO_FREE_AND_NULL(faketilebuffer);
faketilebuffersiz = 0;
if (!script) return -1;
Printf(PRINT_NONOTIFY, "\n");
return 0;
defsparser_include(m, nullptr, nullptr); // Q: should we let the external script see our symbol table?
Printf(PRINT_NONOTIFY, "\n");
}
return done ? 0 : -1;
}
// vim:ts=4:

View file

@ -350,7 +350,7 @@ void UserConfig::ProcessOptions()
static const char* defs[] = { "-def", "-h", nullptr };
Args->CollectFiles("-def", defs, ".def");
DefaultDef = Args->CheckValue("-def");
UserDef = Args->CheckValue("-def");
if (DefaultCon.IsEmpty())
{
@ -1309,27 +1309,50 @@ void DrawCrosshair(int deftile, int health, double xdelta, double ydelta, double
void LoadDefinitions()
{
loaddefinitionsfile("engine/engine.def"); // Internal stuff that is required.
const char* defsfile = G_DefFile();
cycle_t deftimer;
deftimer.Reset();
deftimer.Clock();
if (!loaddefinitionsfile(defsfile, true))
const char* loaded = nullptr;
const char* defsfile = G_DefFile();
FString razedefsfile = defsfile;
razedefsfile.Substitute(".def", "-raze.def");
loaddefinitionsfile("engine/engine.def", false); // Internal stuff that is required.
// check what we have.
// user .defs override the default ones and are not cumulative.
// if we fine even one Raze-specific file, all of those will be loaded cumulatively.
// otherwise the default rules inherited from older ports apply.
if (userConfig.UserDef.IsNotEmpty())
{
if (!loaddefinitionsfile(userConfig.UserDef, true, false)) loaded = userConfig.UserDef;
}
else
{
if (fileSystem.FileExists(razedefsfile))
{
if (!loaddefinitionsfile(razedefsfile, true, true)) loaded = razedefsfile;
}
else
{
if (!loaddefinitionsfile(defsfile, true, false)) loaded = defsfile;
}
}
if (loaded)
{
deftimer.Unclock();
Printf(PRINT_NONOTIFY, "Definitions file \"%s\" loaded in %.3f ms.\n", defsfile, deftimer.TimeMS());
DPrintf(DMSG_SPAMMY, "Definitions file \"%s\" loaded, %f ms.\n", loaded, deftimer.TimeMS());
}
userConfig.AddDefs.reset();
// load the widescreen replacements last so that they do not clobber the CRC for the original items so that mod-side replacement are picked up.
// load the widescreen replacements last. This ensures that mods still get the correct CRCs for their own tile replacements.
if (fileSystem.FindFile("engine/widescreen.def") >= 0 && !Args->CheckParm("-nowidescreen"))
{
loaddefinitionsfile("engine/widescreen.def");
}
fileSystem.InitHashChains();
fileSystem.InitHashChains(); // make sure that any resources that got added can be found again.
}
bool M_Active()

View file

@ -65,6 +65,7 @@ struct UserConfig
{
FString gamegrp;
FString CommandMap;
FString UserDef;
FString DefaultDef;
FString DefaultCon;
FString CommandDemo;