From 542e1b2ba7aba319b2daac352ac8b68f51c6ad91 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 20 Apr 2021 23:13:42 +0200 Subject: [PATCH] - ported all simple model commands. 'model' is the last remaining one. --- source/build/src/defs.cpp | 197 ++++---------------------------------- source/core/parsefuncs.h | 165 +++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 181 deletions(-) diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 15041c67a..3dd43706e 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -410,150 +410,20 @@ static int32_t defsparser(scriptfile *script) break; case T_DEFINEMODEL: - { - FString modelfn; - double scale; - int32_t shadeoffs; - - if (scriptfile_getstring(script,&modelfn)) break; - if (scriptfile_getdouble(script,&scale)) break; - if (scriptfile_getnumber(script,&shadeoffs)) break; - - lastmodelid = md_loadmodel(modelfn); - if (lastmodelid < 0) - { - Printf("Warning: Failed loading MD2/MD3 model \"%s\"\n", modelfn.GetChars()); - break; - } - md_setmisc(lastmodelid,(float)scale, shadeoffs,0.0,0.0,0); - - modelskin = lastmodelskin = 0; - seenframe = 0; - } - break; + parseDefineModel(*script, pos); + break; case T_DEFINEMODELFRAME: - { - FString framename; - char happy=1; - int32_t tilex; - int32_t ftilenume, ltilenume; - - if (scriptfile_getstring(script,&framename)) break; - if (scriptfile_getsymbol(script,&ftilenume)) break; //first tile number - if (scriptfile_getsymbol(script,<ilenume)) break; //last tile number (inclusive) - - if (check_tile_range("definemodelframe", &ftilenume, <ilenume, script, pos)) - break; - - if (lastmodelid < 0) - { - pos.Message(MSG_WARNING, "Ignoring frame definition.\n"); - break; - } - for (tilex = ftilenume; tilex <= ltilenume && happy; tilex++) - { - switch (md_defineframe(lastmodelid, framename, tilex, max(0,modelskin), 0.0f,0)) - { - case -1: - happy = 0; break; // invalid model id!? - case -2: - Printf("Invalid tile number"); - happy = 0; - break; - case -3: - Printf("Invalid frame name"); - happy = 0; - break; - default: - break; - } - } - seenframe = 1; - } - break; + parseDefineModelFrame(*script, pos); + break; case T_DEFINEMODELANIM: - { - FString startframe, endframe; - int32_t flags; - double dfps; - - if (scriptfile_getstring(script,&startframe)) break; - if (scriptfile_getstring(script,&endframe)) break; - if (scriptfile_getdouble(script,&dfps)) break; //animation frame rate - if (scriptfile_getnumber(script,&flags)) break; - - if (lastmodelid < 0) - { - Printf("Warning: Ignoring animation definition.\n"); - break; - } - switch (md_defineanimation(lastmodelid, startframe, endframe, (int32_t)(dfps*(65536.0*.001)), flags)) - { - case 0: - break; - case -1: - break; // invalid model id!? - case -2: - Printf("Invalid starting frame name"); - break; - case -3: - Printf("Invalid ending frame name"); - break; - case -4: - Printf("Out of memory"); - break; - } - } - break; + parseDefineModelAnim(*script, pos); + break; case T_DEFINEMODELSKIN: - { - int32_t palnum; - FString skinfn; - - if (scriptfile_getsymbol(script,&palnum)) break; - if (scriptfile_getstring(script,&skinfn)) break; //skin filename - - // if we see a sequence of definemodelskin, then a sequence of definemodelframe, - // and then a definemodelskin, we need to increment the skin counter. - // - // definemodel "mymodel.md2" 1 1 - // definemodelskin 0 "normal.png" // skin 0 - // definemodelskin 21 "normal21.png" - // definemodelframe "foo" 1000 1002 // these use skin 0 - // definemodelskin 0 "wounded.png" // skin 1 - // definemodelskin 21 "wounded21.png" - // definemodelframe "foo2" 1003 1004 // these use skin 1 - // selectmodelskin 0 // resets to skin 0 - // definemodelframe "foo3" 1005 1006 // these use skin 0 - if (seenframe) { modelskin = ++lastmodelskin; } - seenframe = 0; - - if (!fileSystem.FileExists(skinfn)) - break; - - switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), 0, 0.0f, 1.0f, 1.0f, 0)) - { - case 0: - break; - case -1: - break; // invalid model id!? - case -2: - Printf("Invalid skin filename"); - break; - case -3: - Printf("Invalid palette number"); - break; - case -4: - Printf("Out of memory"); - break; - } - } - break; + parseDefineModelSkin(*script, pos); + break; case T_SELECTMODELSKIN: - { - if (scriptfile_getsymbol(script,&modelskin)) break; - } - break; + parseSelectModelSkin(*script, pos); + break; case T_DEFINEVOXEL: parseDefineVoxel(*script, pos); break; @@ -994,50 +864,15 @@ static int32_t defsparser(scriptfile *script) break; case T_UNDEFMODEL: + parseUndefModel(*script, pos); + break; case T_UNDEFMODELRANGE: - { - int32_t r0,r1; - - if (scriptfile_getsymbol(script,&r0)) break; - if (tokn == T_UNDEFMODELRANGE) - { - if (scriptfile_getsymbol(script,&r1)) break; - - if (check_tile_range("undefmodelrange", &r0, &r1, script, pos)) - break; - } - else - { - r1 = r0; - - if (check_tile("undefmodel", r0, script, pos)) - break; - } - for (; r0 <= r1; r0++) - md_undefinetile(r0); - } - break; - - case T_UNDEFMODELOF: - { - int32_t r0; - if (scriptfile_getsymbol(script,&r0)) break; - - if (check_tile("undefmodelof", r0, script, pos)) - break; - - // XXX: See comment of md_undefinemodel() - pos.Message(MSG_WARNING, "undefmodelof: currently non-functional."); + parseUndefModelRange(*script, pos); break; -#if defined USE_OPENGL && 0 - mid = md_tilehasmodel(r0,0); - if (mid < 0) break; - - md_undefinemodel(mid); -#endif - } - break; + case T_UNDEFMODELOF: + parseUndefModelOf(*script, pos); + break; case T_UNDEFTEXTURE: parseUndefTexture(*script, pos); diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h index 230baa371..7da21adc3 100644 --- a/source/core/parsefuncs.h +++ b/source/core/parsefuncs.h @@ -1580,3 +1580,168 @@ void parseHighpalookup(FScanner& sc, FScriptPosition& pos) } // todo } + + +struct ModelStatics +{ + int lastmodelid; + int modelskin, lastmodelskin; + int seenframe; +} mdglobal; + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseDefineModel(FScanner& sc, FScriptPosition& pos) +{ + FString modelfn; + double scale; + int shadeoffs; + + if (!sc.GetString(modelfn)) return; + if (!sc.GetFloat(scale, true)) return; + if (!sc.GetNumber(shadeoffs, true)) return; + + mdglobal.lastmodelid = md_loadmodel(modelfn); + if (mdglobal.lastmodelid < 0) + { + pos.Message(MSG_WARNING, "definemodel: Failed loading model file '%s'\n", modelfn.GetChars()); + } + else + { + md_setmisc(mdglobal.lastmodelid, (float)scale, shadeoffs, 0.0, 0.0, 0); + mdglobal.modelskin = mdglobal.lastmodelskin = 0; + mdglobal.seenframe = 0; + } +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseDefineModelFrame(FScanner& sc, FScriptPosition& pos) +{ + FString framename; + bool ok = true; + int firsttile, lasttile; + + if (!sc.GetString(framename)) return; + if (!sc.GetNumber(firsttile, true)) return; + if (!sc.GetNumber(lasttile, true)) return; + + if (!ValidateTileRange("definemodelframe", firsttile, lasttile, pos)) return; + + if (mdglobal.lastmodelid < 0) + { + pos.Message(MSG_WARNING, "definemodelframe: Ignoring frame definition outside model."); + return; + } + for (int i = firsttile; i <= lasttile && ok; i++) + { + int err = (md_defineframe(mdglobal.lastmodelid, framename, i, max(0, mdglobal.modelskin), 0.0f, 0)); + if (err < 0) ok = false; + if (err == -2) pos.Message(MSG_ERROR, "Invalid tile number %d", i); + else if (err == -3) pos.Message(MSG_ERROR, "Invalid frame name", framename.GetChars()); + } + mdglobal.seenframe = 1; +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseDefineModelAnim(FScanner& sc, FScriptPosition& pos) +{ + FString startframe, endframe; + int32_t flags; + double dfps; + + if (!sc.GetString(startframe)) return; + if (!sc.GetString(endframe)) return; + if (!sc.GetFloat(dfps, true)) return; + if (!sc.GetNumber(flags, true)) return; + + if (mdglobal.lastmodelid < 0) + { + pos.Message(MSG_WARNING, "definemodelframe: Ignoring animation definition outside model."); + return; + } + int err = (md_defineanimation(mdglobal.lastmodelid, startframe, endframe, (int32_t)(dfps * (65536.0 * .001)), flags)); + if (err == -2) pos.Message(MSG_ERROR, "Invalid starting frame name %s", startframe.GetChars()); + else if (err == -3) pos.Message(MSG_ERROR, "Invalid ending frame name %s", endframe.GetChars()); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseDefineModelSkin(FScanner& sc, FScriptPosition& pos) +{ + int palnum; + FString skinfn; + + if (!sc.GetNumber(palnum, true)) return; + if (!sc.GetString(skinfn)) return; + + if (mdglobal.seenframe) { mdglobal.modelskin = ++mdglobal.lastmodelskin; } + mdglobal.seenframe = 0; + + if (!fileSystem.FileExists(skinfn)) return; + + int err = (md_defineskin(mdglobal.lastmodelid, skinfn, palnum, max(0, mdglobal.modelskin), 0, 0.0f, 1.0f, 1.0f, 0)); + if (err == -2) pos.Message(MSG_ERROR, "Invalid skin file name %s", skinfn.GetChars()); + else if (err == -3) pos.Message(MSG_ERROR, "Invalid palette %d", palnum); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseSelectModelSkin(FScanner& sc, FScriptPosition& pos) +{ + sc.GetNumber(mdglobal.modelskin, true); +} + + +//=========================================================================== +// +// +// +//=========================================================================== + +void parseUndefModel(FScanner& sc, FScriptPosition& pos) +{ + int tile; + if (!sc.GetNumber(tile, true)) return; + if (!ValidateTilenum("undefmodel", tile, pos)) return; + md_undefinetile(tile); +} + +void parseUndefModelRange(FScanner& sc, FScriptPosition& pos) +{ + int start, end; + + if (!sc.GetNumber(start, true)) return; + if (!sc.GetNumber(end, true)) return; + if (!ValidateTileRange("undefmodel", start, end, pos)) return; + for (int i = start; i <= end; i++) md_undefinetile(i); +} + +void parseUndefModelOf(FScanner& sc, FScriptPosition& pos) +{ + int tile; + if (!sc.GetNumber(tile, true)) return; + if (!ValidateTilenum("undefmodelof", tile, pos)) return; + pos.Message(MSG_WARNING, "undefmodelof: currently non-functional."); +}