- no need to have 2 CRC32 implementations.

Just let Bcrc32 point to zlib instead of having its own implementation.
This commit is contained in:
Christoph Oelckers 2019-11-02 22:10:53 +01:00
parent 4e3ad17e4a
commit 3530c52264
19 changed files with 15 additions and 156 deletions

View file

@ -725,7 +725,6 @@ set (PCH_SOURCES
thirdparty/src/base64.cpp thirdparty/src/base64.cpp
thirdparty/src/sjson.cpp thirdparty/src/sjson.cpp
thirdparty/src/crc32.cpp
thirdparty/src/fix16.cpp thirdparty/src/fix16.cpp
thirdparty/src/fix16_str.cpp thirdparty/src/fix16_str.cpp
thirdparty/src/md4.cpp thirdparty/src/md4.cpp

View file

@ -7,7 +7,7 @@ endif()
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" ) include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" )
if (WIN32) 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 () else ()
include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}") include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}")
endif() endif()

View file

@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "build.h" #include "build.h"
#include "compat.h" #include "compat.h"
#include "common_game.h" #include "common_game.h"
#include "crc32_.h" #include "m_crc32.h"
//#include "actor.h" //#include "actor.h"
#include "globals.h" #include "globals.h"

View file

@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "compat.h" #include "compat.h"
#include "common_game.h" #include "common_game.h"
#include "crc32_.h" #include "m_crc32.h"
#include "globals.h" #include "globals.h"
#include "tile.h" #include "tile.h"

View file

@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "crc32_.h"
#include "compat.h" #include "compat.h"
#include "cache1d.h" #include "cache1d.h"
#include "common_game.h" #include "common_game.h"

View file

@ -15,7 +15,6 @@
#include "colmatch.h" #include "colmatch.h"
#include "common.h" #include "common.h"
#include "compat.h" #include "compat.h"
#include "crc32_.h"
#include "engine_priv.h" #include "engine_priv.h"
#include "lz4.h" #include "lz4.h"
#include "osd.h" #include "osd.h"
@ -7600,21 +7599,6 @@ static int32_t engineLoadTables(void)
for (i=0; i<5120; i++) for (i=0; i<5120; i++)
qradarang[10239-i] = -qradarang[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: // TABLES.DAT format:
//fr.Read(sintable,2048*2); //fr.Read(sintable,2048*2);
//fr.Read(radarang,640*2); //fr.Read(radarang,640*2);
@ -8114,8 +8098,6 @@ int32_t enginePreInit(void)
#endif #endif
initcrc32table();
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE
engineInitClipMaps(); engineInitClipMaps();
#endif #endif

View file

@ -4,7 +4,6 @@
#include "build.h" #include "build.h"
#include "cache1d.h" #include "cache1d.h"
#include "crc32_.h"
#include "compat.h" #include "compat.h"
#include "baselayer.h" #include "baselayer.h"
#include "osd.h" #include "osd.h"
@ -15,6 +14,7 @@
#include "keyboard.h" #include "keyboard.h"
#include "control.h" #include "control.h"
#include "gamecontrol.h" #include "gamecontrol.h"
#include "m_crc32.h"
#define XXH_STATIC_LINKING_ONLY #define XXH_STATIC_LINKING_ONLY
#include "xxhash.h" #include "xxhash.h"

View file

@ -12,7 +12,6 @@
#include "engine_priv.h" #include "engine_priv.h"
#include "cache1d.h" #include "cache1d.h"
#include "lz4.h" #include "lz4.h"
#include "crc32_.h"
#include "vfs.h" #include "vfs.h"

View file

@ -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); 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);
}

View file

@ -7,7 +7,7 @@ endif()
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" ) include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" )
if (WIN32) 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 () else ()
include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}") include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}")
endif() endif()

View file

@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "compat.h" #include "compat.h"
#include "renderlayer.h" #include "renderlayer.h"
#include "osdcmds.h" #include "osdcmds.h"
#include "crc32_.h"
#include "network.h" #include "network.h"
#include "menus.h" #include "menus.h"
#include "savegame.h" #include "savegame.h"
@ -5909,8 +5908,6 @@ static void G_Startup(void)
timerInit(TICRATE); timerInit(TICRATE);
timerSetCallback(gameTimerHandler); timerSetCallback(gameTimerHandler);
initcrc32table();
G_CompileScripts(); G_CompileScripts();
if (engineInit()) if (engineInit())

View file

@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "cheats.h" #include "cheats.h"
#include "common.h" #include "common.h"
#include "common_game.h" #include "common_game.h"
#include "crc32_.h" #include "m_crc32.h"
#include "duke3d.h" #include "duke3d.h"
#include "gameexec.h" #include "gameexec.h"
#include "namesdyn.h" #include "namesdyn.h"

View file

@ -40,7 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "enet.h" #include "enet.h"
#include "lz4.h" #include "lz4.h"
#include "crc32_.h" #include "m_crc32.h"
#include "vfs.h" #include "vfs.h"

View file

@ -7,7 +7,7 @@ endif()
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" ) include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/../../build/include" )
if (WIN32) 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 () else ()
include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}") include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GDTOA_INCLUDE_DIR}")
endif() endif()

View file

@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "compat.h" #include "compat.h"
#include "renderlayer.h" #include "renderlayer.h"
#include "osdcmds.h" #include "osdcmds.h"
#include "crc32_.h"
#include "net.h" #include "net.h"
#include "menus.h" #include "menus.h"
#include "savegame.h" #include "savegame.h"
@ -7319,8 +7318,6 @@ static void G_Startup(void)
timerInit(TICRATE); timerInit(TICRATE);
initcrc32table();
G_CompileScripts(); G_CompileScripts();
enginecompatibility_mode = ENGINECOMPATIBILITY_19961112; enginecompatibility_mode = ENGINECOMPATIBILITY_19961112;

View file

@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "m_argv.h" #include "m_argv.h"
#include "osd.h" #include "osd.h"
#include "crc32_.h" #include "m_crc32.h"
#include "printf.h" #include "printf.h"
BEGIN_RR_NS BEGIN_RR_NS

View file

@ -28,10 +28,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "premap.h" #include "premap.h"
#include "savegame.h" #include "savegame.h"
#include "input.h" #include "input.h"
#include "m_crc32.h"
#include "enet.h" #include "enet.h"
#include "lz4.h" #include "lz4.h"
#include "crc32_.h"
BEGIN_RR_NS BEGIN_RR_NS

View file

@ -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

View file

@ -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
}
}