From 616838dd0acaa3ca106dc9cce76f2645f5572a3a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 16 Sep 2020 00:10:12 +0200 Subject: [PATCH] - little bit of cleanup on tileImport. --- source/build/src/defs.cpp | 2 +- source/core/textures/buildtiles.cpp | 60 +++++++++++++++++++++-------- source/core/textures/buildtiles.h | 2 +- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 6f31bb031..7f3387c9f 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -760,7 +760,7 @@ static int32_t defsparser(scriptfile *script) break; } } - tileImport(pos, imp); + processTileImport("tileimporttexture", pos, imp); } break; case T_COPYTILE: diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index 8d256bbc2..a34b718ea 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -1069,37 +1069,63 @@ bool PickTexture(int picnum, FGameTexture* tex, int paletteid, TexturePick& pick return true; } +//=========================================================================== +// +// Parsing stuff for tile data comes below. +// +//=========================================================================== + +//=========================================================================== +// +// Helpers for tile parsing +// +//=========================================================================== + +bool ValidateTileRange(const char* cmd, int &begin, int& end, FScriptPosition pos) +{ + if (end < begin) + { + pos.Message(MSG_WARNING, "%s: tile range [%d..%d] is backwards. Indices were swapped.", cmd, begin, end); + std::swap(begin, end); + } + + if ((unsigned)begin >= MAXUSERTILES || (unsigned)end >= MAXUSERTILES) + { + pos.Message(MSG_ERROR, "%s: Invalid tile range [%d..%d]", cmd, begin, end); + return false; + } + + return true; +} + +bool ValidateTilenum(const char* cmd, int tile, FScriptPosition pos) +{ + if ((unsigned)tile >= MAXUSERTILES) + { + pos.Message(MSG_ERROR, "%s: Invalid tile number %d", cmd, tile); + return false; + } + + return true; +} + //=========================================================================== // // Internal worker for tileImportTexture // //=========================================================================== -void tileImport(FScriptPosition& pos, TileImport& imp) +void processTileImport(const char *cmd, FScriptPosition& pos, TileImport& imp) { - if (imp.tile == -1) - { - pos.Message(MSG_ERROR, "missing tile number in import declaration"); + if (!ValidateTilenum(cmd, imp.tile, pos)) return; - } - if ((unsigned)imp.tile >= MAXUSERTILES) - { - pos.Message(MSG_ERROR, "Invalid tile number %d in import declaration", imp.tile); - return; - } if (imp.crc32 != INT64_MAX && int(imp.crc32) != tileGetCRC32(imp.tile)) - { - // Only print as developer diagnostic if that mode is enabled. - pos.Message(MSG_DEBUGMSG, "CRC32 mismatch for tile %d.", imp.tile); return; - } if (imp.sizex != INT_MAX && tileWidth(imp.tile) != imp.sizex && tileHeight(imp.tile) != imp.sizey) - { - pos.Message(MSG_DEBUGMSG, "Size mismatch for tile %d", imp.tile); return; - } + gi->SetTileProps(imp.tile, imp.surface, imp.vox, imp.shade); if (imp.fn.IsNotEmpty() && tileImportFromTexture(imp.fn, imp.tile, imp.alphacut, imp.istexture) < 0) return; diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index a89fe0df6..8215c1226 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -518,4 +518,4 @@ struct TileImport }; -void tileImport(FScriptPosition& pos, TileImport& imp); +void processTileImport(const char* cmd, FScriptPosition& pos, TileImport& imp);