From 5c2335bbeba532e2d5e4e6030c5e9aadb9578148 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 6 Apr 2021 16:22:24 +0200 Subject: [PATCH] - encapsulate setuptile(range) parsing in separate functions. --- source/build/src/defs.cpp | 36 ++++-------------------------------- source/core/parsefuncs.h | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index ab94457b0..55f382431 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -611,41 +611,13 @@ static int32_t defsparser(scriptfile *script) } break; case T_SETUPTILE: - { - int tile, tmp; - - if (scriptfile_getsymbol(script,&tile)) break; - if (check_tile("setuptile", tile, script, pos)) - break; - auto& tiled = TileFiles.tiledata[tile]; - if (scriptfile_getsymbol(script,&tiled.hiofs.xsize)) break; // XXX - if (scriptfile_getsymbol(script, &tiled.hiofs.ysize)) break; - if (scriptfile_getsymbol(script, &tiled.hiofs.xoffs)) break; - if (scriptfile_getsymbol(script, &tiled.hiofs.yoffs)) break; + parseSetupTile(*script, pos); break; - } + case T_SETUPTILERANGE: - { - int tile1,tile2; - TileOffs t; - - if (scriptfile_getsymbol(script,&tile1)) break; - if (scriptfile_getsymbol(script,&tile2)) break; - if (scriptfile_getnumber(script,&t.xsize)) break; - if (scriptfile_getnumber(script,&t.ysize)) break; - if (scriptfile_getsymbol(script,&t.xoffs)) break; - if (scriptfile_getsymbol(script,&t.yoffs)) break; - - if (check_tile_range("setuptilerange", &tile1, &tile2, script, pos)) - break; - - for (int i=tile1; i<=tile2; i++) - { - TileFiles.tiledata[i].hiofs = t; - } - + parseSetupTileRange(*script, pos); break; - } + case T_ANIMTILERANGE: parseAnimTileRange(*script, pos); break; diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h index 05b3aa87b..498f3cdb7 100644 --- a/source/core/parsefuncs.h +++ b/source/core/parsefuncs.h @@ -35,6 +35,33 @@ ** */ +void parseSetupTile(FScanner& sc, FScriptPosition& pos) +{ + int tile; + if (!sc.GetNumber(tile, true)) return; + if (!ValidateTilenum("setuptile", tile, pos)) return; + auto& tiled = TileFiles.tiledata[tile]; + if (!sc.GetNumber(tiled.hiofs.xsize, true)) return; + if (!sc.GetNumber(tiled.hiofs.ysize, true)) return; + if (!sc.GetNumber(tiled.hiofs.xoffs, true)) return; + if (!sc.GetNumber(tiled.hiofs.yoffs, true)) return; +} + +void parseSetupTileRange(FScanner& sc, FScriptPosition& pos) +{ + int tilestart, tileend; + if (!sc.GetNumber(tilestart, true)) return; + if (!sc.GetNumber(tileend, true)) return; + if (!ValidateTileRange("setuptilerange", tilestart, tileend, pos)) return; + + TileOffs hiofs; + if (!sc.GetNumber(hiofs.xsize, true)) return; + if (!sc.GetNumber(hiofs.ysize, true)) return; + if (!sc.GetNumber(hiofs.xoffs, true)) return; + if (!sc.GetNumber(hiofs.yoffs, true)) return; + + for (int i = tilestart; i <= tileend; i++) TileFiles.tiledata[i].hiofs = hiofs; +} void parseAnimTileRange(FScanner& sc, FScriptPosition& pos) {