From 3530c522644a0555c84e169e3767e535191c2323 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 2 Nov 2019 22:10:53 +0100 Subject: [PATCH] - no need to have 2 CRC32 implementations. Just let Bcrc32 point to zlib instead of having its own implementation. --- source/CMakeLists.txt | 1 - source/blood/CMakeLists.txt | 2 +- source/blood/src/db.cpp | 2 +- source/blood/src/replace.cpp | 2 +- source/blood/src/resource.cpp | 1 - source/build/src/engine.cpp | 18 ----- source/build/src/osd.cpp | 2 +- source/build/src/tiles.cpp | 1 - source/common/utility/m_crc32.h | 5 ++ source/duke3d/CMakeLists.txt | 2 +- source/duke3d/src/game.cpp | 3 - source/duke3d/src/gamedef.cpp | 2 +- source/duke3d/src/network.cpp | 2 +- source/rr/CMakeLists.txt | 2 +- source/rr/src/game.cpp | 3 - source/rr/src/gamedef.cpp | 2 +- source/rr/src/net.cpp | 2 +- source/thirdparty/include/crc32_.h | 17 ----- source/thirdparty/src/crc32.cpp | 102 ----------------------------- 19 files changed, 15 insertions(+), 156 deletions(-) delete mode 100644 source/thirdparty/include/crc32_.h delete mode 100644 source/thirdparty/src/crc32.cpp diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 55a380f82..48f324769 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -725,7 +725,6 @@ set (PCH_SOURCES thirdparty/src/base64.cpp thirdparty/src/sjson.cpp - thirdparty/src/crc32.cpp thirdparty/src/fix16.cpp thirdparty/src/fix16_str.cpp thirdparty/src/md4.cpp diff --git a/source/blood/CMakeLists.txt b/source/blood/CMakeLists.txt index 2df18ed54..7203e11b4 100644 --- a/source/blood/CMakeLists.txt +++ b/source/blood/CMakeLists.txt @@ -7,7 +7,7 @@ endif() include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" ) if (WIN32) - include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/vpx" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/sdl2") + include_directories( "${ZLIB_INCLUDE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/vpx" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/sdl2") else () include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}") endif() diff --git a/source/blood/src/db.cpp b/source/blood/src/db.cpp index 6b35d8f6f..fd8c08622 100644 --- a/source/blood/src/db.cpp +++ b/source/blood/src/db.cpp @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "build.h" #include "compat.h" #include "common_game.h" -#include "crc32_.h" +#include "m_crc32.h" //#include "actor.h" #include "globals.h" diff --git a/source/blood/src/replace.cpp b/source/blood/src/replace.cpp index e9cad9ecf..2a48ed420 100644 --- a/source/blood/src/replace.cpp +++ b/source/blood/src/replace.cpp @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "compat.h" #include "common_game.h" -#include "crc32_.h" +#include "m_crc32.h" #include "globals.h" #include "tile.h" diff --git a/source/blood/src/resource.cpp b/source/blood/src/resource.cpp index 5086641e4..7139f2598 100644 --- a/source/blood/src/resource.cpp +++ b/source/blood/src/resource.cpp @@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include -#include "crc32_.h" #include "compat.h" #include "cache1d.h" #include "common_game.h" diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index cc95040c5..33bfa955c 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -15,7 +15,6 @@ #include "colmatch.h" #include "common.h" #include "compat.h" -#include "crc32_.h" #include "engine_priv.h" #include "lz4.h" #include "osd.h" @@ -7600,21 +7599,6 @@ static int32_t engineLoadTables(void) for (i=0; i<5120; i++) qradarang[10239-i] = -qradarang[i]; -#ifdef B_LITTLE_ENDIAN - i = 0; - if (Bcrc32((uint8_t *)sintable, sizeof(sintable), 0) != 0xee1e7aba) - i |= 1; - if (Bcrc32((uint8_t *)radarang, 640*sizeof(radarang[0]), 0) != 0xee893d92) - i |= 2; - - if (i != 0) - { - static const char *str[3] = { "sine table", "arctangent table", - "sine and arctangent tables" }; - initprintf("WARNING: Calculated %s differ%s from original!\n", - str[i-1], i==3 ? "" : "s"); - } -#endif // TABLES.DAT format: //fr.Read(sintable,2048*2); //fr.Read(radarang,640*2); @@ -8114,8 +8098,6 @@ int32_t enginePreInit(void) #endif - initcrc32table(); - #ifdef HAVE_CLIPSHAPE_FEATURE engineInitClipMaps(); #endif diff --git a/source/build/src/osd.cpp b/source/build/src/osd.cpp index 4342df827..1be60b600 100644 --- a/source/build/src/osd.cpp +++ b/source/build/src/osd.cpp @@ -4,7 +4,6 @@ #include "build.h" #include "cache1d.h" -#include "crc32_.h" #include "compat.h" #include "baselayer.h" #include "osd.h" @@ -15,6 +14,7 @@ #include "keyboard.h" #include "control.h" #include "gamecontrol.h" +#include "m_crc32.h" #define XXH_STATIC_LINKING_ONLY #include "xxhash.h" diff --git a/source/build/src/tiles.cpp b/source/build/src/tiles.cpp index 563808399..2271a0510 100644 --- a/source/build/src/tiles.cpp +++ b/source/build/src/tiles.cpp @@ -12,7 +12,6 @@ #include "engine_priv.h" #include "cache1d.h" #include "lz4.h" -#include "crc32_.h" #include "vfs.h" diff --git a/source/common/utility/m_crc32.h b/source/common/utility/m_crc32.h index b727d7a6b..079bffec4 100644 --- a/source/common/utility/m_crc32.h +++ b/source/common/utility/m_crc32.h @@ -50,3 +50,8 @@ inline uint32_t CRC1 (uint32_t crc, const uint8_t c, const uint32_t *crcTable) { return crcTable[(crc & 0xff) ^ c] ^ (crc >> 8); } + +inline uint32_t Bcrc32(const void* data, int length, uint32_t crc) +{ + return crc32(crc, (const Bytef*)data, length); +} diff --git a/source/duke3d/CMakeLists.txt b/source/duke3d/CMakeLists.txt index 077c06b2c..9d93f0abd 100644 --- a/source/duke3d/CMakeLists.txt +++ b/source/duke3d/CMakeLists.txt @@ -7,7 +7,7 @@ endif() include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" ) if (WIN32) - include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/vpx" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/sdl2" ) + include_directories( "${ZLIB_INCLUDE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/vpx" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/sdl2" ) else () include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}") endif() diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index b4ef16ba7..8651d4f3b 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "compat.h" #include "renderlayer.h" #include "osdcmds.h" -#include "crc32_.h" #include "network.h" #include "menus.h" #include "savegame.h" @@ -5909,8 +5908,6 @@ static void G_Startup(void) timerInit(TICRATE); timerSetCallback(gameTimerHandler); - initcrc32table(); - G_CompileScripts(); if (engineInit()) diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 84a43db1a..9bf56cdf0 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "cheats.h" #include "common.h" #include "common_game.h" -#include "crc32_.h" +#include "m_crc32.h" #include "duke3d.h" #include "gameexec.h" #include "namesdyn.h" diff --git a/source/duke3d/src/network.cpp b/source/duke3d/src/network.cpp index aadfaeba4..157bebc45 100644 --- a/source/duke3d/src/network.cpp +++ b/source/duke3d/src/network.cpp @@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "enet.h" #include "lz4.h" -#include "crc32_.h" +#include "m_crc32.h" #include "vfs.h" diff --git a/source/rr/CMakeLists.txt b/source/rr/CMakeLists.txt index a68b19e69..e503f5b0c 100644 --- a/source/rr/CMakeLists.txt +++ b/source/rr/CMakeLists.txt @@ -7,7 +7,7 @@ endif() include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" ) if (WIN32) - include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/vpx" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/sdl2") + include_directories( "${ZLIB_INCLUDE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/vpx" "${CMAKE_CURRENT_SOURCE_DIR}/../../platform/windows/include/sdl2") else () include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}") endif() diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 3751ec4e4..38e36b291 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "compat.h" #include "renderlayer.h" #include "osdcmds.h" -#include "crc32_.h" #include "net.h" #include "menus.h" #include "savegame.h" @@ -7319,8 +7318,6 @@ static void G_Startup(void) timerInit(TICRATE); - initcrc32table(); - G_CompileScripts(); enginecompatibility_mode = ENGINECOMPATIBILITY_19961112; diff --git a/source/rr/src/gamedef.cpp b/source/rr/src/gamedef.cpp index 4c642a979..9fe518009 100644 --- a/source/rr/src/gamedef.cpp +++ b/source/rr/src/gamedef.cpp @@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "m_argv.h" #include "osd.h" -#include "crc32_.h" +#include "m_crc32.h" #include "printf.h" BEGIN_RR_NS diff --git a/source/rr/src/net.cpp b/source/rr/src/net.cpp index 3ccfafad2..38948868e 100644 --- a/source/rr/src/net.cpp +++ b/source/rr/src/net.cpp @@ -28,10 +28,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "premap.h" #include "savegame.h" #include "input.h" +#include "m_crc32.h" #include "enet.h" #include "lz4.h" -#include "crc32_.h" BEGIN_RR_NS diff --git a/source/thirdparty/include/crc32_.h b/source/thirdparty/include/crc32_.h deleted file mode 100644 index 0fef21f05..000000000 --- a/source/thirdparty/include/crc32_.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef crc32_h_ -#define crc32_h_ - -#include "compat.h" - -#define POLY 0xEDB88320 - -#ifdef BITNESS64 -extern uint32_t crc32table[8][256]; -#else -extern uint32_t crc32table[4][256]; -#endif - -extern uint32_t Bcrc32(const void* data, int length, uint32_t crc); -extern void initcrc32table(void); - -#endif diff --git a/source/thirdparty/src/crc32.cpp b/source/thirdparty/src/crc32.cpp deleted file mode 100644 index 1b008d0df..000000000 --- a/source/thirdparty/src/crc32.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// based on http://create.stephan-brumme.com/crc32/Crc32.cpp, zlib license - -#include "compat.h" -#include "crc32_.h" - -uint32_t Bcrc32(const void* data, int length, uint32_t crc) -{ - const uint32_t* current = (const uint32_t*) data; - uint8_t const * currentChar; - crc = ~crc; - -#ifdef BITNESS64 - // process eight bytes at once (Slicing-by-8) - while (length >= 8) - { -#if B_BIG_ENDIAN != 0 - uint32_t one = *current ^ B_SWAP32(crc); - uint32_t two = *(current+1); - crc = crc32table[0][two & 0xFF] ^ - crc32table[1][(two>> 8) & 0xFF] ^ - crc32table[2][(two>>16) & 0xFF] ^ - crc32table[3][(two>>24) & 0xFF] ^ - crc32table[4][one & 0xFF] ^ - crc32table[5][(one>> 8) & 0xFF] ^ - crc32table[6][(one>>16) & 0xFF] ^ - crc32table[7][(one>>24) & 0xFF]; -#else - uint32_t one = *current ^ crc; - uint32_t two = *(current+1); - crc = crc32table[0][(two>>24) & 0xFF] ^ - crc32table[1][(two>>16) & 0xFF] ^ - crc32table[2][(two>> 8) & 0xFF] ^ - crc32table[3][two & 0xFF] ^ - crc32table[4][(one>>24) & 0xFF] ^ - crc32table[5][(one>>16) & 0xFF] ^ - crc32table[6][(one>> 8) & 0xFF] ^ - crc32table[7][one & 0xFF]; -#endif - current += 2; - length -= 8; - } -#else - // process four bytes at once (Slicing-by-4) - while (length >= 4) - { -#if B_BIG_ENDIAN != 0 - uint32_t one = *current++ ^ B_SWAP32(crc); - crc = crc32table[0][one & 0xFF] ^ - crc32table[1][(one>> 8) & 0xFF] ^ - crc32table[2][(one>>16) & 0xFF] ^ - crc32table[3][(one>>24) & 0xFF]; -#else - uint32_t one = *current++ ^ crc; - crc = crc32table[0][(one>>24) & 0xFF] ^ - crc32table[1][(one>>16) & 0xFF] ^ - crc32table[2][(one>> 8) & 0xFF] ^ - crc32table[3][one & 0xFF]; -#endif - - length -= 4; - } -#endif - - currentChar = (uint8_t const *) current; - // remaining 1 to 7 bytes (standard algorithm) - while (length-- > 0) - crc = (crc >> 8) ^ crc32table[0][(crc & 0xFF) ^ *currentChar++]; - - return ~crc; -} - -#ifdef BITNESS64 -uint32_t crc32table[8][256]; -#else -uint32_t crc32table[4][256]; -#endif - -void initcrc32table(void) -{ - int i; - for (i = 0; i <= 0xFF; i++) - { - uint32_t j, crc = i; - for (j = 0; j < 8; j++) - crc = (crc >> 1) ^ ((crc & 1) * POLY); - crc32table[0][i] = crc; - } - - for (i = 0; i <= 0xFF; i++) - { - crc32table[1][i] = (crc32table[0][i] >> 8) ^ crc32table[0][crc32table[0][i] & 0xFF]; - crc32table[2][i] = (crc32table[1][i] >> 8) ^ crc32table[0][crc32table[1][i] & 0xFF]; - crc32table[3][i] = (crc32table[2][i] >> 8) ^ crc32table[0][crc32table[2][i] & 0xFF]; - -#ifdef BITNESS64 - crc32table[4][i] = (crc32table[3][i] >> 8) ^ crc32table[0][crc32table[3][i] & 0xFF]; - crc32table[5][i] = (crc32table[4][i] >> 8) ^ crc32table[0][crc32table[4][i] & 0xFF]; - crc32table[6][i] = (crc32table[5][i] >> 8) ^ crc32table[0][crc32table[5][i] & 0xFF]; - crc32table[7][i] = (crc32table[6][i] >> 8) ^ crc32table[0][crc32table[6][i] & 0xFF]; -#endif - } -}