From f4ec9a19214b1e33ce615546f8c9105739f21730 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 13 Apr 2021 00:28:51 +0200 Subject: [PATCH] - 4 more .def commands ported --- source/build/include/build.h | 8 +- source/build/src/defs.cpp | 177 ++--------------------------------- source/build/src/engine.cpp | 2 - source/core/parsefuncs.h | 104 ++++++++++++++++++++ 4 files changed, 115 insertions(+), 176 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 1e7fbd436..f9ddbf45b 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -215,13 +215,13 @@ typedef struct { // The proportion at which looking up/down affects the apparent 'horiz' of // a parallaxed sky, scaled by 65536 (so, a value of 65536 makes it align // with the drawn surrounding scene): - int32_t horizfrac; + int horizfrac; // The texel index offset in the y direction of a parallaxed sky: // XXX: currently always 0. - int32_t yoffs; + int yoffs; - int8_t lognumtiles; // 1<(*script, pos); break; case T_SPRITECOL: @@ -1545,180 +1544,20 @@ static int32_t defsparser(scriptfile *script) case T_SOUND: case T_MUSIC: - { - FScanner::SavedPos p; - FString dummy, dummy2; - static const tokenlist sound_musictokens[] = - { - { "id", T_ID }, - { "file", T_FILE }, - }; - - if (scriptfile_getbraces(script,&p)) break; - while (!scriptfile_endofblock(script, p)) - { - switch (getatoken(script,sound_musictokens,countof(sound_musictokens))) - { - case T_ID: - scriptfile_getstring(script,&dummy2); - break; - case T_FILE: - scriptfile_getstring(script,&dummy); - break; - } - } - SetMusicForMap(dummy2, dummy, true); - } + parseMusic(*script, pos); break; case T_MAPINFO: - { - FString mapmd4string; - FScanner::SavedPos mapinfoend; - usermaphack_t mhk; - static const tokenlist mapinfotokens[] = - { - { "mapfile", T_MAPFILE }, - { "maptitle", T_MAPTITLE }, - { "mapmd4", T_MAPMD4 }, - { "mhkfile", T_MHKFILE }, - }; - - if (scriptfile_getbraces(script,&mapinfoend)) break; - while (!scriptfile_endofblock(script, mapinfoend)) - { - switch (getatoken(script,mapinfotokens,countof(mapinfotokens))) - { - case T_MAPFILE: - scriptfile_getstring(script,nullptr); - break; - case T_MAPTITLE: - scriptfile_getstring(script,&mhk.title); - break; - case T_MAPMD4: - { - scriptfile_getstring(script,&mapmd4string); - - for (int i = 0; i < 16; i++) - { - char smallbuf[3] = { mapmd4string[2 * i], mapmd4string[2 * i + 1], 0 }; - mhk.md4[i] = strtol(smallbuf, NULL, 16); - } - - break; - } - case T_MHKFILE: - scriptfile_getstring(script,&mhk.mhkfile); - break; - } - } - AddUserMapHack(mhk); - } - break; + parseMapinfo(*script, pos); + break; case T_ECHO: - { - FString string; - scriptfile_getstring(script,&string); - Printf("%s\n",string.GetChars()); - } - break; - - case T_GLOBALFLAGS: - { - if (scriptfile_getnumber(script,&globalflags)) break; - } - break; + parseEcho(*script, pos); + break; case T_MULTIPSKY: - { - FScanner::SavedPos blockend; - int32_t tile; - - static const tokenlist subtokens[] = - { - { "horizfrac", T_HORIZFRAC }, - { "yoffset", T_YOFFSET }, - { "lognumtiles", T_LOGNUMTILES }, - { "tile", T_TILE }, - { "panel", T_TILE }, - { "yscale", T_YSCALE }, - }; - - if (scriptfile_getsymbol(script,&tile)) - break; - if (scriptfile_getbraces(script,&blockend)) - break; - - if (tile != DEFAULTPSKY && (unsigned)tile >= MAXUSERTILES) - { - scriptfile_setposition(script, blockend); - break; - } - - psky_t * const newpsky = tileSetupSky(tile); - - while (!scriptfile_endofblock(script, blockend)) - { - int32_t token = getatoken(script,subtokens,countof(subtokens)); - switch (token) - { - case T_HORIZFRAC: - { - int32_t horizfrac; - scriptfile_getsymbol(script,&horizfrac); - - newpsky->horizfrac = horizfrac; - break; - } - case T_YOFFSET: - { - int32_t yoffset; - scriptfile_getsymbol(script,&yoffset); - - newpsky->yoffs = yoffset; - break; - } - case T_LOGNUMTILES: - { - int32_t lognumtiles; - scriptfile_getsymbol(script,&lognumtiles); - - if ((1< MAXPSKYTILES) - break; - - newpsky->lognumtiles = lognumtiles; - break; - } - case T_TILE: - { - int32_t panel, offset; - scriptfile_getsymbol(script,&panel); - scriptfile_getsymbol(script,&offset); - - if ((unsigned) panel >= MAXPSKYTILES) - break; - - if ((unsigned) offset > PSKYOFF_MAX) - break; - - newpsky->tileofs[panel] = offset; - break; - } - case T_YSCALE: - { - int32_t yscale; - scriptfile_getsymbol(script,&yscale); - - newpsky->yscale = yscale; - break; - } - default: - break; - } - } - } - break; + parseMultiPsky(*script, pos); + break; case T_BASEPALETTE: { FScanner::SavedPos blockend; diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index bbbfa8948..9ce27d667 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -56,8 +56,6 @@ int16_t pskybits_override = -1; static int32_t beforedrawrooms = 1; -int32_t globalflags; - static int8_t tempbuf[MAXWALLS]; static int32_t no_radarang2 = 0; diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h index 5d72b0cb8..ce2b1cccb 100644 --- a/source/core/parsefuncs.h +++ b/source/core/parsefuncs.h @@ -38,6 +38,7 @@ int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor); int tileSetSkybox(int picnum, int palnum, FString* facenames); void tileRemoveReplacement(int num); +void AddUserMapHack(usermaphack_t&); //=========================================================================== // @@ -539,3 +540,106 @@ void parseTint(FScanner& sc, FScriptPosition& pos) lookups.setPaletteTint(pal, clamp(red, 0, 255), clamp(green, 0, 255), clamp(blue, 0, 255), clamp(shadered, 0, 255), clamp(shadegreen, 0, 255), clamp(shadeblue, 0, 255), flags); } + + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseMusic(FScanner& sc, FScriptPosition& pos) +{ + FString id, file; + FScanner::SavedPos blockend; + + if (sc.StartBraces(&blockend)) return; + while (!sc.FoundEndBrace(blockend)) + { + sc.MustGetString(); + if (sc.Compare("id")) sc.GetString(id); + else if (sc.Compare("file")) sc.GetString(file); + } + SetMusicForMap(id, file, true); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseMapinfo(FScanner& sc, FScriptPosition& pos) +{ + usermaphack_t mhk; + FScanner::SavedPos blockend; + + if (sc.StartBraces(&blockend)) return; + while (!sc.FoundEndBrace(blockend)) + { + sc.MustGetString(); + if (sc.Compare("mapfile")) sc.GetString(); + else if (sc.Compare("maptitle")) sc.GetString(mhk.title); + else if (sc.Compare("mhkfile")) sc.GetString(mhk.mhkfile); + else if (sc.Compare("mapmd4")) + { + sc.GetString(); + for (int i = 0; i < 16; i++) + { + char smallbuf[3] = { sc.String[2 * i], sc.String[2 * i + 1], 0 }; + mhk.md4[i] = strtol(smallbuf, nullptr, 16); + } + } + } + AddUserMapHack(mhk); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseEcho(FScanner& sc, FScriptPosition& pos) +{ + sc.MustGetString(); + Printf("%s\n", sc.String); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseMultiPsky(FScanner& sc, FScriptPosition& pos) +{ + usermaphack_t mhk; + FScanner::SavedPos blockend; + psky_t sky{}; + + sky.yscale = 65536; + if (!sc.GetNumber(sky.tilenum, true)) return; + + if (sc.StartBraces(&blockend)) return; + while (!sc.FoundEndBrace(blockend)) + { + sc.MustGetString(); + if (sc.Compare("horizfrac")) sc.GetNumber(sky.horizfrac, true); + else if (sc.Compare("yoffset")) sc.GetNumber(sky.yoffs, true); + else if (sc.Compare("lognumtiles")) sc.GetNumber(sky.lognumtiles, true); + else if (sc.Compare("yscale")) sc.GetNumber(sky.yscale, true); + else if (sc.Compare({ "tile", "panel" })) + { + int panel, offset; + sc.GetNumber(panel, true); + sc.GetNumber(offset, true); + if ((unsigned)panel < MAXPSKYTILES && (unsigned)offset <= PSKYOFF_MAX) sky.tileofs[panel] = offset; + } + } + + if (sky.tilenum != DEFAULTPSKY && (unsigned)sky.tilenum >= MAXUSERTILES) return; + if ((1 << sky.lognumtiles) > MAXPSKYTILES) return; + auto psky = tileSetupSky(sky.tilenum); + *psky = sky; +}