From 6b684e74bae233dccd977362591a4466142597f0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Apr 2021 14:09:08 +0200 Subject: [PATCH] - migrated 'texture' .def command. --- source/build/src/defs.cpp | 185 +--------------------------------- source/common/engine/sc_man.h | 9 ++ source/core/parsefuncs.h | 156 ++++++++++++++++++++++++---- 3 files changed, 150 insertions(+), 200 deletions(-) diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 8cbb7844a..be38f8bdd 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -1638,189 +1638,8 @@ static int32_t defsparser(scriptfile *script) } break; case T_TEXTURE: - { - FScanner::SavedPos textureend; - int32_t tile=-1, token; - - static const tokenlist texturetokens[] = - { - { "pal", T_PAL }, - { "detail", T_DETAIL }, - { "glow", T_GLOW }, - { "specular",T_SPECULAR }, - { "normal", T_NORMAL }, - }; - - if (scriptfile_getsymbol(script,&tile)) break; - if (scriptfile_getbraces(script,&textureend)) break; - while (!scriptfile_endofblock(script, textureend)) - { - token = getatoken(script,texturetokens,countof(texturetokens)); - switch (token) - { - case T_PAL: - { - auto palpos = scriptfile_getposition(script); - FScanner::SavedPos palend; - int32_t pal=-1, xsiz = 0, ysiz = 0; - FString fn; - double alphacut = -1.0, xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; - - static const tokenlist texturetokens_pal[] = - { - { "file", T_FILE },{ "name", T_FILE }, - { "alphacut", T_ALPHACUT }, - { "detailscale", T_XSCALE }, { "scale", T_XSCALE }, { "xscale", T_XSCALE }, { "intensity", T_XSCALE }, - { "yscale", T_YSCALE }, - { "specpower", T_SPECPOWER }, { "specularpower", T_SPECPOWER }, { "parallaxscale", T_SPECPOWER }, - { "specfactor", T_SPECFACTOR }, { "specularfactor", T_SPECFACTOR }, { "parallaxbias", T_SPECFACTOR }, - { "nocompress", T_NOCOMPRESS }, - { "nodownsize", T_NODOWNSIZE }, - { "forcefilter", T_FORCEFILTER }, - { "artquality", T_ARTQUALITY }, - { "orig_sizex", T_ORIGSIZEX }, { "orig_sizey", T_ORIGSIZEY } - }; - - if (scriptfile_getsymbol(script,&pal)) break; - if (scriptfile_getbraces(script,&palend)) break; - while (!scriptfile_endofblock(script, palend)) - { - switch (getatoken(script,texturetokens_pal,countof(texturetokens_pal))) - { - case T_FILE: - scriptfile_getstring(script,&fn); break; - case T_ALPHACUT: - scriptfile_getdouble(script,&alphacut); break; - case T_XSCALE: - scriptfile_getdouble(script,&xscale); break; - case T_YSCALE: - scriptfile_getdouble(script,&yscale); break; - case T_SPECPOWER: - scriptfile_getdouble(script,&specpower); break; - case T_SPECFACTOR: - scriptfile_getdouble(script,&specfactor); break; - case T_ORIGSIZEX: - scriptfile_getnumber(script, &xsiz); - break; - case T_ORIGSIZEY: - scriptfile_getnumber(script, &ysiz); - break; - default: - break; - } - } - - if ((unsigned)tile >= MAXUSERTILES) break; // message is printed later - if ((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS) - { - palpos.Message(MSG_ERROR, "missing or invalid 'palette number' for texture definition"); - break; - } - if (fn.IsEmpty()) - { - palpos.Message(MSG_ERROR, "missing 'file name' for texture definition"); - break; - } - - if (!fileSystem.FileExists(fn)) - { - palpos.Message(MSG_ERROR, "%s not found in replacement for tile %d", fn.GetChars(), tile); - break; - } - - if (xsiz > 0 && ysiz > 0) - { - tileSetDummy(tile, xsiz, ysiz); - } - xscale = 1.0f / xscale; - yscale = 1.0f / yscale; - - tileSetHightileReplacement(tile,pal,fn,alphacut,xscale,yscale, specpower, specfactor); - } - break; - case T_DETAIL: case T_GLOW: case T_SPECULAR: case T_NORMAL: - { - auto detailpos = scriptfile_getposition(script); - FScanner::SavedPos detailend; - int32_t pal = 0; - FString fn; - double xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; - - static const tokenlist texturetokens_pal[] = - { - { "file", T_FILE },{ "name", T_FILE }, - { "alphacut", T_ALPHACUT }, - { "detailscale", T_XSCALE }, { "scale", T_XSCALE }, { "xscale", T_XSCALE }, { "intensity", T_XSCALE }, - { "yscale", T_YSCALE }, - { "specpower", T_SPECPOWER }, { "specularpower", T_SPECPOWER }, { "parallaxscale", T_SPECPOWER }, - { "specfactor", T_SPECFACTOR }, { "specularfactor", T_SPECFACTOR }, { "parallaxbias", T_SPECFACTOR }, - { "nocompress", T_NOCOMPRESS }, - { "nodownsize", T_NODOWNSIZE }, - { "forcefilter", T_FORCEFILTER }, - { "artquality", T_ARTQUALITY }, - }; - - if (scriptfile_getbraces(script,&detailend)) break; - while (!scriptfile_endofblock(script, detailend)) - { - switch (getatoken(script,texturetokens_pal,countof(texturetokens_pal))) - { - case T_FILE: - scriptfile_getstring(script,&fn); break; - case T_XSCALE: - scriptfile_getdouble(script,&xscale); break; - case T_YSCALE: - scriptfile_getdouble(script,&yscale); break; - case T_SPECPOWER: - scriptfile_getdouble(script,&specpower); break; - case T_SPECFACTOR: - scriptfile_getdouble(script,&specfactor); break; - default: - break; - } - } - - if ((unsigned)tile >= MAXUSERTILES) break; // message is printed later - if (fn.IsEmpty()) - { - detailpos.Message(MSG_ERROR, "missing 'file name' for texture definition"); - break; - } - - if (!fileSystem.FileExists(fn)) - break; - - switch (token) - { - case T_DETAIL: - pal = DETAILPAL; - xscale = 1.0f / xscale; - yscale = 1.0f / yscale; - break; - case T_GLOW: - pal = GLOWPAL; - break; - case T_SPECULAR: - pal = SPECULARPAL; - break; - case T_NORMAL: - pal = NORMALPAL; - break; - } - tileSetHightileReplacement(tile,pal,fn,-1.0f,xscale,yscale, specpower, specfactor); - } - break; - default: - break; - } - } - if ((unsigned)tile >= MAXUSERTILES) - { - pos.Message(MSG_ERROR, "missing or invalid 'tile number' for texture definition"); - break; - } - } - break; + parseTexture(*script, pos); + break; case T_UNDEFMODEL: case T_UNDEFMODELRANGE: diff --git a/source/common/engine/sc_man.h b/source/common/engine/sc_man.h index 6874eb186..64690d24b 100644 --- a/source/common/engine/sc_man.h +++ b/source/common/engine/sc_man.h @@ -130,6 +130,15 @@ public: } bool GetFloat(bool evaluate = false); + + bool GetFloat(double& var, bool evaluate = false) + { + if (!GetFloat(evaluate)) return false; + var = Float; + return true; + } + + void MustGetFloat(bool evaluate = false); bool CheckFloat(bool evaluate = false); diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h index 5f2d18026..f36893671 100644 --- a/source/core/parsefuncs.h +++ b/source/core/parsefuncs.h @@ -86,6 +86,128 @@ void parseDefineTexture(FScanner& sc, FScriptPosition& pos) // //=========================================================================== +static void parseTexturePaletteBlock(FScanner& sc, FScriptPosition& pos, int tile) +{ + FScanner::SavedPos blockend; + + int pal = -1, xsiz = 0, ysiz = 0; + FString fn; + double alphacut = -1.0, xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; + + if (!sc.GetNumber(pal, true)) return; + + if (sc.StartBraces(&blockend)) return; + while (!sc.FoundEndBrace(blockend)) + { + sc.GetString(); + if (sc.Compare("file")) sc.GetString(fn); + else if (sc.Compare("alphacut")) sc.GetFloat(alphacut, true); + else if (sc.Compare({ "xscale", "scale", "intensity", "detailscale" })) sc.GetFloat(xscale, true); // what's the point of all of these names? + else if (sc.Compare("yscale")) sc.GetFloat(yscale, true); + else if (sc.Compare({ "specpower", "specularpower", "parallaxscale" })) sc.GetFloat(specpower, true); + else if (sc.Compare({ "specfactor", "specularfactor", "parallaxbias" })) sc.GetFloat(specfactor, true); + else if (sc.Compare("orig_sizex")) sc.GetNumber(xsiz, true); + else if (sc.Compare("orig_sizey")) sc.GetNumber(ysiz, true); + }; + + if ((unsigned)tile < MAXUSERTILES) + { + if ((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS) + { + pos.Message(MSG_ERROR, "missing or invalid 'palette number' for texture definition"); + } + else if (fn.IsEmpty()) + { + pos.Message(MSG_ERROR, "missing 'file name' for texture definition"); + } + else if (!fileSystem.FileExists(fn)) + { + pos.Message(MSG_ERROR, "%s not found in replacement for tile %d", fn.GetChars(), tile); + } + else + { + if (xsiz > 0 && ysiz > 0) + { + tileSetDummy(tile, xsiz, ysiz); + } + xscale = 1.0f / xscale; + yscale = 1.0f / yscale; + + tileSetHightileReplacement(tile, pal, fn, alphacut, xscale, yscale, specpower, specfactor); + } + } +} + +static void parseTextureSpecialBlock(FScanner& sc, FScriptPosition& pos, int tile, int specialpal) +{ + FScanner::SavedPos blockend; + + int pal = -1; + FString fn; + double xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; + + if (!sc.GetNumber(pal, true)) return; + + if (sc.StartBraces(&blockend)) return; + while (!sc.FoundEndBrace(blockend)) + { + sc.GetString(); + if (sc.Compare("file")) sc.GetString(fn); + else if (sc.Compare({ "xscale", "scale", "intensity", "detailscale" })) sc.GetFloat(xscale, true); // what's the point of all of these names? + else if (sc.Compare("yscale")) sc.GetFloat(yscale, true); + else if (sc.Compare({ "specpower", "specularpower", "parallaxscale" })) sc.GetFloat(specpower, true); + else if (sc.Compare({ "specfactor", "specularfactor", "parallaxbias" })) sc.GetFloat(specfactor, true); + }; + + if ((unsigned)tile < MAXUSERTILES) + { + if (fn.IsEmpty()) + { + pos.Message(MSG_ERROR, "missing 'file name' for texture definition"); + } + else if (!fileSystem.FileExists(fn)) + { + pos.Message(MSG_ERROR, "%s not found in replacement for tile %d", fn.GetChars(), tile); + } + else + { + if (pal == DETAILPAL) + { + xscale = 1.0f / xscale; + yscale = 1.0f / yscale; + } + + tileSetHightileReplacement(tile, pal, fn, -1.f, xscale, yscale, specpower, specfactor); + } + } +} + +void parseTexture(FScanner& sc, FScriptPosition& pos) +{ + FScanner::SavedPos blockend; + int tile = -1; + + if (!sc.GetNumber(tile, true)) return; + ValidateTilenum("texture", tile, pos); // do not abort, we still need to parse over the data. + + if (sc.StartBraces(&blockend)) return; + while (!sc.FoundEndBrace(blockend)) + { + sc.MustGetString(); + if (sc.Compare("pal")) parseTexturePaletteBlock(sc, pos, tile); + else if (sc.Compare("detail")) parseTextureSpecialBlock(sc, pos, tile, DETAILPAL); + else if (sc.Compare("glow")) parseTextureSpecialBlock(sc, pos, tile, GLOWPAL); + else if (sc.Compare("specular")) parseTextureSpecialBlock(sc, pos, tile, SPECULARPAL); + else if (sc.Compare("normal")) parseTextureSpecialBlock(sc, pos, tile, NORMALPAL); + } +} + +//=========================================================================== +// +// +// +//=========================================================================== + void parseDefineSkybox(FScanner& sc, FScriptPosition& pos) { int tile, palette; @@ -110,30 +232,30 @@ void parseDefineSkybox(FScanner& sc, FScriptPosition& pos) void parseSkybox(FScanner& sc, FScriptPosition& pos) { - FString faces[6]; - FScanner::SavedPos blockend; - int32_t tile = -1, pal = 0; + FString faces[6]; + FScanner::SavedPos blockend; + int 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]); + if (sc.StartBraces(&blockend)) return; + while (!sc.FoundEndBrace(blockend)) + { + sc.MustGetString(); + 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); + tileSetSkybox(tile, pal, faces); } //===========================================================================