- moved a bit more script parsing functionality into the backend and tried it out on the 'skybox' command.

This commit is contained in:
Christoph Oelckers 2021-04-07 21:59:47 +02:00
parent 4d29cd2df2
commit cecd34efc7
4 changed files with 111 additions and 61 deletions

View file

@ -1566,66 +1566,7 @@ static int32_t defsparser(scriptfile *script)
}
break;
case T_SKYBOX:
{
auto skyboxpos = scriptfile_getposition(script);
FString fn[6];
FScanner::SavedPos modelend;
int32_t i, tile = -1, pal = 0, happy = 1;
static const tokenlist skyboxtokens[] =
{
{ "tile" ,T_TILE },
{ "pal" ,T_PAL },
{ "ft" ,T_FRONT },{ "front" ,T_FRONT },{ "forward",T_FRONT },
{ "rt" ,T_RIGHT },{ "right" ,T_RIGHT },
{ "bk" ,T_BACK },{ "back" ,T_BACK },
{ "lf" ,T_LEFT },{ "left" ,T_LEFT },{ "lt" ,T_LEFT },
{ "up" ,T_TOP },{ "top" ,T_TOP },{ "ceiling",T_TOP },{ "ceil" ,T_TOP },
{ "dn" ,T_BOTTOM },{ "bottom" ,T_BOTTOM },{ "floor" ,T_BOTTOM },{ "down" ,T_BOTTOM },
{ "nocompress", T_NOCOMPRESS },
{ "nodownsize", T_NODOWNSIZE },
{ "forcefilter", T_FORCEFILTER },
{ "artquality", T_ARTQUALITY },
};
if (scriptfile_getbraces(script,&modelend)) break;
while (!scriptfile_endofblock(script, modelend))
{
switch (getatoken(script,skyboxtokens,countof(skyboxtokens)))
{
//case T_ERROR: Printf("Error on line %s:%d in skybox tokens\n",script->filename,linenum); break;
case T_TILE:
scriptfile_getsymbol(script,&tile); break;
case T_PAL:
scriptfile_getsymbol(script,&pal); break;
case T_FRONT:
scriptfile_getstring(script,&fn[0]); break;
case T_RIGHT:
scriptfile_getstring(script,&fn[1]); break;
case T_BACK:
scriptfile_getstring(script,&fn[2]); break;
case T_LEFT:
scriptfile_getstring(script,&fn[3]); break;
case T_TOP:
scriptfile_getstring(script,&fn[4]); break;
case T_BOTTOM:
scriptfile_getstring(script,&fn[5]); break;
}
}
if (tile < 0) skyboxpos.Message(MSG_ERROR, "skybox: missing 'tile number'"), happy=0;
for (i=0; i<6; i++)
{
if (fn[i].IsEmpty()) skyboxpos.Message(MSG_ERROR, "skybox: missing '%s filename'", skyfaces[i]), happy = 0;
// FIXME?
if (!fileSystem.FileExists(fn[i]))
happy = 0;
}
if (!happy) break;
tileSetSkybox(tile, pal, fn);
}
parseSkybox(*script, pos);
break;
case T_HIGHPALOOKUP:
{

View file

@ -1287,6 +1287,42 @@ void FScanner::AddSymbol(const char* name, double value)
symbols.Insert(name, sym);
}
//==========================================================================
//
//
//
//==========================================================================
int FScanner::StartBraces(FScanner::SavedPos* braceend)
{
if (CheckString("{"))
{
auto here = SavePos();
SkipToEndOfBlock();
*braceend = SavePos();
RestorePos(here);
return 0;
}
else
{
ScriptError("'{' expected");
return -1;
}
}
//==========================================================================
//
//
//
//==========================================================================
bool FScanner::FoundEndBrace(FScanner::SavedPos& braceend)
{
auto here = SavePos();
return here.SavedScriptPtr >= braceend.SavedScriptPtr;
}
//==========================================================================
//
// a class that remembers a parser position

View file

@ -94,6 +94,8 @@ public:
inline void AddSymbol(const char* name, uint32_t value) { return AddSymbol(name, uint64_t(value)); }
void AddSymbol(const char* name, double value);
void SkipToEndOfBlock();
int StartBraces(FScanner::SavedPos* braceend);
bool FoundEndBrace(FScanner::SavedPos& braceend);
static FString TokenName(int token, const char *string=NULL);
@ -120,6 +122,13 @@ public:
return true;
}
bool GetString(FString& var)
{
if (!GetString()) return false;
var = String;
return true;
}
bool GetFloat(bool evaluate = false);
void MustGetFloat(bool evaluate = false);
bool CheckFloat(bool evaluate = false);

View file

@ -39,6 +39,12 @@ int tileSetHightileReplacement(int picnum, int palnum, const char* filename, flo
int tileSetSkybox(int picnum, int palnum, FString* facenames);
void tileRemoveReplacement(int num);
//===========================================================================
//
//
//
//===========================================================================
void parseDefineTexture(FScanner& sc, FScriptPosition& pos)
{
int tile, palette;
@ -54,6 +60,12 @@ void parseDefineTexture(FScanner& sc, FScriptPosition& pos)
tileSetHightileReplacement(tile, palette, sc.String, -1.0, 1.0, 1.0, 1.0, 1.0);
}
//===========================================================================
//
//
//
//===========================================================================
void parseDefineSkybox(FScanner& sc, FScriptPosition& pos)
{
int tile, palette;
@ -70,6 +82,46 @@ void parseDefineSkybox(FScanner& sc, FScriptPosition& pos)
tileSetSkybox(tile, palette, fn);
}
//===========================================================================
//
//
//
//===========================================================================
void parseSkybox(FScanner& sc, FScriptPosition& pos)
{
FString faces[6];
FScanner::SavedPos blockend;
int32_t tile = -1, pal = 0;
if (sc.StartBraces(&blockend)) return;
while (!sc.FoundEndBrace(blockend))
{
sc.GetString();
if (sc.Compare("tile")) sc.GetNumber(tile, true);
else if (sc.Compare("pal")) sc.GetNumber(pal, true);
else if (sc.Compare({ "ft", "front", "forward" })) sc.GetString(faces[0]);
else if (sc.Compare({ "rt", "right" })) sc.GetString(faces[1]);
else if (sc.Compare({ "bk", "back" })) sc.GetString(faces[2]);
else if (sc.Compare({ "lt", "lf", "left" })) sc.GetString(faces[3]);
else if (sc.Compare({ "up", "ceiling", "top", "ceil" })) sc.GetString(faces[4]);
else if (sc.Compare({ "dn", "floor", "bottom", "down" })) sc.GetString(faces[5]);
// skip over everything else.
}
if (tile < 0)
{
pos.Message(MSG_ERROR, "skybox: missing tile number");
return;
}
tileSetSkybox(tile, pal, faces);
}
//===========================================================================
//
//
//
//===========================================================================
void parseSetupTile(FScanner& sc, FScriptPosition& pos)
{
int tile;
@ -82,6 +134,12 @@ void parseSetupTile(FScanner& sc, FScriptPosition& pos)
if (!sc.GetNumber(tiled.hiofs.yoffs, true)) return;
}
//===========================================================================
//
//
//
//===========================================================================
void parseSetupTileRange(FScanner& sc, FScriptPosition& pos)
{
int tilestart, tileend;
@ -98,6 +156,12 @@ void parseSetupTileRange(FScanner& sc, FScriptPosition& pos)
for (int i = tilestart; i <= tileend; i++) TileFiles.tiledata[i].hiofs = hiofs;
}
//===========================================================================
//
//
//
//===========================================================================
void parseAnimTileRange(FScanner& sc, FScriptPosition& pos)
{
SetAnim set;