From cecd34efc7c7cc62c99dee8a470e67e0d655344f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 7 Apr 2021 21:59:47 +0200 Subject: [PATCH] - moved a bit more script parsing functionality into the backend and tried it out on the 'skybox' command. --- source/build/src/defs.cpp | 63 ++------------------------------ source/common/engine/sc_man.cpp | 36 +++++++++++++++++++ source/common/engine/sc_man.h | 9 +++++ source/core/parsefuncs.h | 64 +++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 61 deletions(-) diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index bf9d48197..7726d9bf2 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -1566,67 +1566,8 @@ 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); - } - break; + parseSkybox(*script, pos); + break; case T_HIGHPALOOKUP: { int32_t basepal=-1, pal=-1; diff --git a/source/common/engine/sc_man.cpp b/source/common/engine/sc_man.cpp index fa9a2f6c4..f24f25d92 100644 --- a/source/common/engine/sc_man.cpp +++ b/source/common/engine/sc_man.cpp @@ -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 diff --git a/source/common/engine/sc_man.h b/source/common/engine/sc_man.h index 3a894fcb3..6874eb186 100644 --- a/source/common/engine/sc_man.h +++ b/source/common/engine/sc_man.h @@ -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); diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h index 6096bdd2d..c26746dff 100644 --- a/source/core/parsefuncs.h +++ b/source/core/parsefuncs.h @@ -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;