- consolidated the DEF parser parts in the backend.

Only Blood had some special handling - better implement callbacks here instead of requiring a second parsing pass.
This commit is contained in:
Christoph Oelckers 2020-08-19 20:29:37 +02:00
parent dd20d74c51
commit d645674c1c
8 changed files with 50 additions and 439 deletions

View file

@ -736,7 +736,6 @@ static void app_init()
levelLoadDefaults();
loaddefinitionsfile(BLOODWIDESCREENDEF);
loaddefinitions_game(BLOODWIDESCREENDEF, FALSE);
const char* defsfile = G_DefFile();
uint32_t stime = timerGetTicks();
@ -745,7 +744,6 @@ static void app_init()
uint32_t etime = timerGetTicks();
Printf("Definitions file \"%s\" loaded in %d ms.\n", defsfile, etime - stime);
}
loaddefinitions_game(defsfile, FALSE);
powerupInit();
Printf("Loading cosine table\n");
trigInit();
@ -980,302 +978,6 @@ int GameInterface::app_main()
return 0;
}
static int parsedefinitions_game(scriptfile *, int);
static void parsedefinitions_game_include(const char *fileName, scriptfile *pScript, const char *cmdtokptr, int const firstPass)
{
scriptfile *included = scriptfile_fromfile(fileName);
if (!included)
{
if (!Bstrcasecmp(cmdtokptr,"null") || pScript == NULL) // this is a bit overboard to prevent unused parameter warnings
{
// Printf("Warning: Failed including %s as module\n", fn);
}
/*
else
{
Printf("Warning: Failed including %s on line %s:%d\n",
fn, script->filename,scriptfile_getlinum(script,cmdtokptr));
}
*/
}
else
{
parsedefinitions_game(included, firstPass);
scriptfile_close(included);
}
}
static int parsedefinitions_game(scriptfile *pScript, int firstPass)
{
int token;
char *pToken;
static const tokenlist tokens[] =
{
{ "include", T_INCLUDE },
{ "#include", T_INCLUDE },
{ "includedefault", T_INCLUDEDEFAULT },
{ "#includedefault", T_INCLUDEDEFAULT },
{ "loadgrp", T_LOADGRP },
{ "cachesize", T_CACHESIZE },
{ "noautoload", T_NOAUTOLOAD },
{ "sound", T_SOUND },
//{ "cutscene", T_CUTSCENE },
//{ "animsounds", T_ANIMSOUNDS },
{ "renamefile", T_RENAMEFILE },
{ "globalgameflags", T_GLOBALGAMEFLAGS },
{ "rffdefineid", T_RFFDEFINEID },
{ "tilefromtexture", T_TILEFROMTEXTURE },
};
static const tokenlist soundTokens[] =
{
{ "id", T_ID },
{ "file", T_FILE },
{ "minpitch", T_MINPITCH },
{ "maxpitch", T_MAXPITCH },
{ "priority", T_PRIORITY },
{ "type", T_TYPE },
{ "distance", T_DISTANCE },
{ "volume", T_VOLUME },
};
#if 0
static const tokenlist animTokens [] =
{
{ "delay", T_DELAY },
{ "aspect", T_ASPECT },
{ "sounds", T_SOUND },
{ "forcefilter", T_FORCEFILTER },
{ "forcenofilter", T_FORCENOFILTER },
{ "texturefilter", T_TEXTUREFILTER },
};
#endif
do
{
token = getatoken(pScript, tokens, ARRAY_SIZE(tokens));
pToken = pScript->ltextptr;
switch (token)
{
case T_LOADGRP:
{
char *fileName;
if (!scriptfile_getstring(pScript,&fileName) && firstPass)
{
fileSystem.AddAdditionalFile(fileName);
}
}
break;
case T_CACHESIZE:
{
int32_t cacheSize;
if (scriptfile_getnumber(pScript, &cacheSize) || !firstPass)
break;
}
break;
case T_INCLUDE:
{
char *fileName;
if (!scriptfile_getstring(pScript, &fileName))
parsedefinitions_game_include(fileName, pScript, pToken, firstPass);
break;
}
case T_INCLUDEDEFAULT:
{
parsedefinitions_game_include(G_DefaultDefFile(), pScript, pToken, firstPass);
break;
}
case T_NOAUTOLOAD:
if (firstPass)
gNoAutoLoad = true;
break;
case T_RFFDEFINEID:
{
char *resName = NULL;
char *resType = NULL;
char *rffName = NULL;
int resID;
if (scriptfile_getstring(pScript, &resName))
break;
if (scriptfile_getstring(pScript, &resType))
break;
if (scriptfile_getnumber(pScript, &resID))
break;
if (scriptfile_getstring(pScript, &rffName))
break;
if (!firstPass)
{
FStringf name("%s.%s", resName, resType);
fileSystem.CreatePathlessCopy(resName, resID, 0);
}
}
break;
case T_TILEFROMTEXTURE:
{
char *texturetokptr = pScript->ltextptr, *textureend;
int32_t tile = -1;
int32_t havesurface = 0, havevox = 0, haveview = 0, haveshade = 0;
int32_t surface = 0, vox = 0, view = 0, shade = 0;
int32_t tile_crc32 = 0;
vec2_t tile_size{};
uint8_t have_crc32 = 0;
uint8_t have_size = 0;
static const tokenlist tilefromtexturetokens[] =
{
{ "surface", T_SURFACE },
{ "voxel", T_VOXEL },
{ "ifcrc", T_IFCRC },
{ "view", T_VIEW },
{ "shade", T_SHADE },
};
if (scriptfile_getsymbol(pScript,&tile)) break;
if (scriptfile_getbraces(pScript,&textureend)) break;
while (pScript->textptr < textureend)
{
int32_t token = getatoken(pScript,tilefromtexturetokens,ARRAY_SIZE(tilefromtexturetokens));
switch (token)
{
case T_IFCRC:
scriptfile_getsymbol(pScript, &tile_crc32);
have_crc32 = 1;
break;
case T_IFMATCH:
{
char *ifmatchend;
static const tokenlist ifmatchtokens[] =
{
{ "crc32", T_CRC32 },
{ "size", T_SIZE },
};
if (scriptfile_getbraces(pScript,&ifmatchend)) break;
while (pScript->textptr < ifmatchend)
{
int32_t token = getatoken(pScript,ifmatchtokens,ARRAY_SIZE(ifmatchtokens));
switch (token)
{
case T_CRC32:
scriptfile_getsymbol(pScript, &tile_crc32);
have_crc32 = 1;
break;
case T_SIZE:
scriptfile_getsymbol(pScript, &tile_size.x);
scriptfile_getsymbol(pScript, &tile_size.y);
have_size = 1;
break;
default:
break;
}
}
break;
}
case T_SURFACE:
havesurface = 1;
scriptfile_getsymbol(pScript, &surface);
break;
case T_VOXEL:
havevox = 1;
scriptfile_getsymbol(pScript, &vox);
break;
case T_VIEW:
haveview = 1;
scriptfile_getsymbol(pScript, &view);
break;
case T_SHADE:
haveshade = 1;
scriptfile_getsymbol(pScript, &shade);
break;
}
}
if (!firstPass)
{
if (EDUKE32_PREDICT_FALSE((unsigned)tile >= MAXUSERTILES))
{
Printf("Error: missing or invalid 'tile number' for texture definition near line %s:%d\n",
pScript->filename, scriptfile_getlinum(pScript,texturetokptr));
break;
}
if (have_crc32)
{
int32_t const orig_crc32 = tileGetCRC32(tile);
if (orig_crc32 != tile_crc32)
{
// Printf("CRC32 of tile %d doesn't match! CRC32: %d, Expected: %d\n", tile, orig_crc32, tile_crc32);
break;
}
}
if (have_size)
{
vec2_16_t const orig_size = tilesiz[tile];
if (orig_size.x != tile_size.x && orig_size.y != tile_size.y)
{
// Printf("Size of tile %d doesn't match! Size: (%d, %d), Expected: (%d, %d)\n", tile, orig_size.x, orig_size.y, tile_size.x, tile_size.y);
break;
}
}
if (havesurface)
surfType[tile] = surface;
if (havevox)
voxelIndex[tile] = vox;
if (haveshade)
tileShade[tile] = shade;
if (haveview)
picanm[tile].extra = view&7;
}
}
break;
case T_GLOBALGAMEFLAGS: scriptfile_getnumber(pScript, &blood_globalflags); break;
case T_EOF: return 0;
default: break;
}
}
while (1);
return 0;
}
int loaddefinitions_game(const char *fileName, int32_t firstPass)
{
scriptfile *pScript = scriptfile_fromfile(fileName);
if (pScript)
parsedefinitions_game(pScript, firstPass);
if (userConfig.AddDefs) for (auto & m : *userConfig.AddDefs)
parsedefinitions_game_include(m, NULL, "null", firstPass);
if (pScript)
scriptfile_close(pScript);
scriptfile_clearsymbols();
return 0;
}
bool DemoRecordStatus(void) {
return false;
}

View file

@ -478,8 +478,6 @@ enum searchpathtypes_t {
SEARCHPATH_REMOVE = 1<<0,
};
extern int loaddefinitions_game(const char *fn, int32_t preload);
extern void G_ExtInit(void);
extern void G_SetupGlobalPsky(void);

View file

@ -60,7 +60,7 @@ static void drawTextScreenBackground(void)
{
if (bLoadScreenCrcMatch == -1) bLoadScreenCrcMatch = tileGetCRC32(kLoadScreen) == kLoadScreenCRC;
if ((blood_globalflags & BLOOD_FORCE_WIDELOADSCREEN) || (bLoadScreenCrcMatch))
if (bLoadScreenCrcMatch)
{
if (yxaspect >= 65536)
{

View file

@ -188,6 +188,7 @@ enum scripttoken_t
T_RFFDEFINEID,
T_EXTRA,
T_ROTATE,
T_SURFACE, T_VIEW,
};
static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0;
@ -657,6 +658,7 @@ static int32_t defsparser(scriptfile *script)
uint8_t have_crc32 = 0;
uint8_t have_size = 0;
int32_t extra = 0;
int havesurface = 0, surface = 0, havevox = 0, vox = 0, haveview = 0, view = 0, haveshade = 0, shade = 0;
static const tokenlist tilefromtexturetokens[] =
{
@ -673,6 +675,12 @@ static int32_t defsparser(scriptfile *script)
{ "ifcrc", T_IFCRC },
{ "ifmatch", T_IFMATCH },
{ "extra", T_EXTRA },
// Blood also defines these.
{ "surface", T_SURFACE },
{ "voxel", T_VOXEL },
{ "view", T_VIEW },
{ "shade", T_SHADE },
};
if (scriptfile_getsymbol(script,&tile)) break;
@ -747,6 +755,23 @@ static int32_t defsparser(scriptfile *script)
haveextra = 1;
scriptfile_getsymbol(script, &extra);
break;
case T_SURFACE:
havesurface = 1;
scriptfile_getsymbol(script, &surface);
break;
case T_VOXEL:
havevox = 1;
scriptfile_getsymbol(script, &vox);
break;
case T_VIEW:
haveview = 1;
scriptfile_getsymbol(script, &view);
break;
case T_SHADE:
haveshade = 1;
scriptfile_getsymbol(script, &shade);
break;
default:
break;
}
@ -778,6 +803,15 @@ static int32_t defsparser(scriptfile *script)
break;
}
}
// fixme - forward to the game code. These are Blood specific.
if (havesurface)
;// gi->SetSurfType(tile, surface);
if (havevox)
;// gi->SetVoxel(tile, vox);
if (haveshade)
;// gi->SetShade(tile, shade);
if (haveview)
picanm[tile].extra = view & 7;
if (!fn)
{
@ -3373,20 +3407,29 @@ static int32_t defsparser(scriptfile *script)
case T_RFFDEFINEID:
{
char *dummy;
int dummy2;
char* resName = NULL;
char* resType = NULL;
char* rffName = NULL;
int resID;
if (scriptfile_getstring(script, &dummy))
if (scriptfile_getstring(script, &resName))
break;
if (scriptfile_getstring(script, &dummy))
if (scriptfile_getstring(script, &resType))
break;
if (scriptfile_getnumber(script, &dummy2))
if (scriptfile_getnumber(script, &resID))
break;
if (scriptfile_getstring(script, &dummy))
if (scriptfile_getstring(script, &rffName))
break;
FStringf name("%s.%s", resName, resType);
fileSystem.CreatePathlessCopy(resName, resID, 0);
}
break;
default:
Printf("Unknown token.\n"); break;
}

View file

@ -448,123 +448,8 @@ enum gametokens
T_USERCONTENT,
};
int exhumed_globalflags;
PlayerInput localInput;
static int parsedefinitions_game(scriptfile *, int);
static void parsedefinitions_game_include(const char *fileName, scriptfile *pScript, const char *cmdtokptr, int const firstPass)
{
scriptfile *included = scriptfile_fromfile(fileName);
if (!included)
{
if (!Bstrcasecmp(cmdtokptr,"null") || pScript == NULL) // this is a bit overboard to prevent unused parameter warnings
{
// Printf("Warning: Failed including %s as module\n", fn);
}
/*
else
{
Printf("Warning: Failed including %s on line %s:%d\n",
fn, script->filename,scriptfile_getlinum(script,cmdtokptr));
}
*/
}
else
{
parsedefinitions_game(included, firstPass);
scriptfile_close(included);
}
}
static int parsedefinitions_game(scriptfile *pScript, int firstPass)
{
int token;
char *pToken;
static const tokenlist tokens[] =
{
{ "include", T_INCLUDE },
{ "#include", T_INCLUDE },
{ "includedefault", T_INCLUDEDEFAULT },
{ "#includedefault", T_INCLUDEDEFAULT },
{ "loadgrp", T_LOADGRP },
{ "cachesize", T_CACHESIZE },
{ "noautoload", T_NOAUTOLOAD },
{ "renamefile", T_RENAMEFILE },
{ "globalgameflags", T_GLOBALGAMEFLAGS },
};
do
{
token = getatoken(pScript, tokens, ARRAY_SIZE(tokens));
pToken = pScript->ltextptr;
switch (token)
{
case T_LOADGRP:
{
char *fileName;
if (!scriptfile_getstring(pScript,&fileName) && firstPass)
{
fileSystem.AddAdditionalFile(fileName);
}
}
break;
case T_CACHESIZE:
{
int32_t cacheSize;
if (scriptfile_getnumber(pScript, &cacheSize) || !firstPass)
break;
}
break;
case T_INCLUDE:
{
char *fileName;
if (!scriptfile_getstring(pScript, &fileName))
parsedefinitions_game_include(fileName, pScript, pToken, firstPass);
break;
}
case T_INCLUDEDEFAULT:
{
parsedefinitions_game_include(G_DefaultDefFile(), pScript, pToken, firstPass);
break;
}
case T_NOAUTOLOAD:
break;
case T_GLOBALGAMEFLAGS: scriptfile_getnumber(pScript, &exhumed_globalflags); break;
case T_EOF: return 0;
default: break;
}
}
while (1);
return 0;
}
int loaddefinitions_game(const char *fileName, int32_t firstPass)
{
scriptfile *pScript = scriptfile_fromfile(fileName);
if (pScript)
parsedefinitions_game(pScript, firstPass);
for (auto &m : *userConfig.AddDefs)
parsedefinitions_game_include(m, NULL, "null", firstPass);
if (pScript)
scriptfile_close(pScript);
scriptfile_clearsymbols();
return 0;
}
////////
void ResetEngine()
@ -1812,10 +1697,6 @@ int GameInterface::app_main()
forcelevel = 1;
}
#if defined(RENDERTYPEWIN) && defined(USE_OPENGL)
if (forcegl) Printf("GL driver blacklist disabled.\n");
#endif
PatchDemoStrings();
// loc_115F5:
@ -1867,7 +1748,6 @@ int GameInterface::app_main()
uint32_t etime = timerGetTicks();
Printf("Definitions file \"%s\" loaded in %d ms.\n", defsfile, etime-stime);
}
loaddefinitions_game(defsfile, FALSE);
enginePostInit();

View file

@ -325,7 +325,6 @@ enum {
extern char g_modDir[BMAX_PATH];
extern int loaddefinitions_game(const char* fn, int32_t preload);
void G_LoadGroupsInDir(const char* dirname);
void G_DoAutoload(const char* dirname);

View file

@ -1214,14 +1214,6 @@ void GoToTheCinema(int nVal)
}
currentCinemaPalette = nVal;
#if 0
if (ISDEMOVER) {
//???
if (tilesiz[cinematile].x * tilesiz[cinematile].y == 0)
TileFiles.tileCreate(cinematile, 320, 200);
}
#endif
FadeOut(false);
StopAllSounds();
NoClip();

View file

@ -51,7 +51,6 @@ int showmap(short nLevel, short nLevelNew, short nLevelBest);
void ClearCinemaSeen();
void menu_DoPlasma();
int menu_Menu(int val);
void menu_AdjustVolume();
short menu_GameLoad(int nSlot);
void menu_GameLoad2(FILE *fp, bool bIsDemo = false);
void menu_GameSave2(FILE *fp);
@ -61,8 +60,6 @@ int menu_DrawTheMap(int nLevel, int param_B, int param_C);
void DoEnergyTile();
int LoadCinemaPalette(int nPal);
void CinemaFadeIn();
void ReadyCinemaText(uint16_t nVal);