From e84d62416dfae494aab9791e7d857f2bc1091bdc Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 2 Mar 2019 23:21:37 +0000 Subject: [PATCH] Patch from Striker to allow selective tile redefinition in .def files based on the crc of the original tile This only works for "tilefromtexture" for now. git-svn-id: https://svn.eduke32.com/eduke32@7370 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/build.h | 1 + source/build/src/defs.cpp | 16 ++++++++++++++++ source/build/src/tiles.cpp | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/source/build/include/build.h b/source/build/include/build.h index 83e2aec3a..806736035 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1068,6 +1068,7 @@ void artClearMapArt(void); void artSetupMapArt(const char *filename); bool tileLoad(int16_t tilenume); void tileLoadData(int16_t tilenume, int32_t dasiz, char *buffer); +int32_t tileCRC(int16_t tileNum); void artConvertRGB(palette_t *pic, uint8_t const *buf, int32_t bufsizx, int32_t sizx, int32_t sizy); int32_t qloadkvx(int32_t voxindex, const char *filename); diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 8567764c6..643779774 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -121,6 +121,7 @@ enum scripttoken_t T_DST_COLOR, T_ONE_MINUS_DST_COLOR, T_SHADERED, T_SHADEGREEN, T_SHADEBLUE, T_SHADEFACTOR, + T_IFCRC, }; static int32_t lastmodelid = -1, lastvoxid = -1, modelskin = -1, lastmodelskin = -1, seenframe = 0; @@ -792,6 +793,7 @@ static int32_t defsparser(scriptfile *script) int32_t havexoffset = 0, haveyoffset = 0; int32_t xoffset = 0, yoffset = 0; int32_t istexture = 0; + int32_t tilecrc = 0, origcrc = 0; static const tokenlist tilefromtexturetokens[] = { @@ -805,6 +807,7 @@ static int32_t defsparser(scriptfile *script) { "texhitscan", T_TEXHITSCAN }, { "nofullbright", T_NOFULLBRIGHT }, { "texture", T_TEXTURE }, + { "ifcrc", T_IFCRC }, }; if (scriptfile_getsymbol(script,&tile)) break; @@ -831,6 +834,9 @@ static int32_t defsparser(scriptfile *script) scriptfile_getsymbol(script,&yoffset); yoffset = clamp(yoffset, -128, 127); break; + case T_IFCRC: + scriptfile_getsymbol(script, &tilecrc); + break; case T_TEXHITSCAN: flags |= PICANM_TEXHITSCAN_BIT; break; @@ -852,6 +858,16 @@ static int32_t defsparser(scriptfile *script) break; } + if (tilecrc) + { + origcrc = tileCRC(tile); + if (origcrc != tilecrc) + { + //initprintf("CRC of tile %d doesn't match! CRC: %d, Expected: %d\n", tile, origcrc, tilecrc); + break; + } + } + if (!fn) { // tilefromtexture { texhitscan } sets the bit but doesn't change tile data diff --git a/source/build/src/tiles.cpp b/source/build/src/tiles.cpp index 1d1982ce7..035a04c68 100644 --- a/source/build/src/tiles.cpp +++ b/source/build/src/tiles.cpp @@ -12,6 +12,7 @@ #include "engine_priv.h" #include "cache1d.h" #include "lz4.h" +#include "crc32.h" #include "vfs.h" @@ -740,6 +741,26 @@ static void tilePostLoad(int16_t tilenume) #endif } +int32_t tileCRC(int16_t tileNum) +{ + char *data; + + if ((unsigned)tileNum >= (unsigned)MAXTILES) + return 0; + int const dasiz = tilesiz[tileNum].x * tilesiz[tileNum].y; + if (dasiz <= 0) + return 0; + + data = (char *)Bmalloc(dasiz); + tileLoadData(tileNum, dasiz, data); + + int32_t crc = Bcrc32((unsigned char *)data, (unsigned int)dasiz, 0); + + Bfree(data); + + return crc; +} + // Assumes pic has been initialized to zero. void artConvertRGB(palette_t * const pic, uint8_t const * const buf, int32_t const bufsizx, int32_t const sizx, int32_t const sizy) {