- started some reorganization of low level utility code by moving all third party dependencies to a separate place.

This commit is contained in:
Christoph Oelckers 2020-04-11 12:52:48 +02:00
parent 820fe8b3f9
commit 669e8fbe48
70 changed files with 104 additions and 99 deletions

View file

@ -610,9 +610,10 @@ file( GLOB HEADER_FILES
win32/*.h win32/*.h
r_data/*.h r_data/*.h
r_data/models/*.h r_data/models/*.h
utility/rapidjson/*.h common/thirdparty/*.h
common/thirdparty/rapidjson/*.h
common/thirdparty/math./*h
utility/sfmt/*.h utility/sfmt/*.h
utility/math./*h
utility/*.h utility/*.h
scripting/*.h scripting/*.h
scripting/backend/*.h scripting/backend/*.h
@ -1127,8 +1128,6 @@ set (PCH_SOURCES
utility/m_png.cpp utility/m_png.cpp
utility/m_random.cpp utility/m_random.cpp
utility/memarena.cpp utility/memarena.cpp
utility/md5.cpp
utility/superfasthash.cpp
utility/nodebuilder/nodebuild.cpp utility/nodebuilder/nodebuild.cpp
utility/nodebuilder/nodebuild_classify_nosse2.cpp utility/nodebuilder/nodebuild_classify_nosse2.cpp
utility/nodebuilder/nodebuild_events.cpp utility/nodebuilder/nodebuild_events.cpp
@ -1148,6 +1147,8 @@ set (PCH_SOURCES
utility/v_collection.cpp utility/v_collection.cpp
utility/utf8.cpp utility/utf8.cpp
utility/zstrformat.cpp utility/zstrformat.cpp
common/thirdparty/md5.cpp
common/thirdparty/superfasthash.cpp
) )
if( ${HAVE_VM_JIT} ) if( ${HAVE_VM_JIT} )
@ -1171,26 +1172,26 @@ add_executable( zdoom WIN32 MACOSX_BUNDLE
${FASTMATH_SOURCES} ${FASTMATH_SOURCES}
${PCH_SOURCES} ${PCH_SOURCES}
utility/x86.cpp utility/x86.cpp
utility/strnatcmp.c common/thirdparty/strnatcmp.c
utility/zstring.cpp utility/zstring.cpp
utility/math/asin.c common/thirdparty/math/asin.c
utility/math/atan.c common/thirdparty/math/atan.c
utility/math/const.c common/thirdparty/math/const.c
utility/math/cosh.c common/thirdparty/math/cosh.c
utility/math/exp.c common/thirdparty/math/exp.c
utility/math/isnan.c common/thirdparty/math/isnan.c
utility/math/log.c common/thirdparty/math/log.c
utility/math/log10.c common/thirdparty/math/log10.c
utility/math/mtherr.c common/thirdparty/math/mtherr.c
utility/math/polevl.c common/thirdparty/math/polevl.c
utility/math/pow.c common/thirdparty/math/pow.c
utility/math/powi.c common/thirdparty/math/powi.c
utility/math/sin.c common/thirdparty/math/sin.c
utility/math/sinh.c common/thirdparty/math/sinh.c
utility/math/sqrt.c common/thirdparty/math/sqrt.c
utility/math/tan.c common/thirdparty/math/tan.c
utility/math/tanh.c common/thirdparty/math/tanh.c
utility/math/fastsin.cpp common/thirdparty/math/fastsin.cpp
zzautozend.cpp zzautozend.cpp
) )
@ -1215,6 +1216,7 @@ endif()
target_link_libraries( zdoom ${ZDOOM_LIBS} gdtoa lzma ${ZMUSIC_LIBRARIES} ) target_link_libraries( zdoom ${ZDOOM_LIBS} gdtoa lzma ${ZMUSIC_LIBRARIES} )
include_directories( . include_directories( .
common/thirdparty
g_statusbar g_statusbar
console console
playsim playsim
@ -1353,6 +1355,7 @@ source_group("Game Data\\Textures\\Formats" REGULAR_EXPRESSION "^${CMAKE_CURRENT
source_group("Intermission" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/intermission/.+") source_group("Intermission" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/intermission/.+")
source_group("Map Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/maploader/.+") source_group("Map Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/maploader/.+")
source_group("Menu" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/menu/.+") source_group("Menu" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/menu/.+")
source_group("Console" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/console/.+")
source_group("Playsim" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/.+") source_group("Playsim" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/.+")
source_group("Playsim\\Bots" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/bots/.+") source_group("Playsim\\Bots" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/bots/.+")
source_group("Playsim\\FraggleScript" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/fragglescript/.+") source_group("Playsim\\FraggleScript" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/playsim/fragglescript/.+")
@ -1413,10 +1416,12 @@ source_group("Scripting\\ZScript frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_
source_group("Scripting\\Compiler backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/backend/.+") source_group("Scripting\\Compiler backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/backend/.+")
source_group("Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/vm/.+") source_group("Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/vm/.+")
source_group("Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/.+") source_group("Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/.+")
source_group("Common" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/.+")
source_group("Common\\Third Party" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/.+")
source_group("Common\\Third Party\\Math" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/math/.+")
source_group("Common\\Third Party\\RapidJSON" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/thirdparty/rapidjson/.+")
source_group("Utility" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/.+") source_group("Utility" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/.+")
source_group("Utility\\Node Builder" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/nodebuilder/.+") source_group("Utility\\Node Builder" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/nodebuilder/.+")
source_group("Utility\\Math" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/math/.+")
source_group("Utility\\RapidJSON" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/rapidjson/.+")
source_group("Utility\\SFMT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/sfmt/.+") source_group("Utility\\SFMT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/utility/sfmt/.+")
source_group("Statusbar" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/g_statusbar/.+") source_group("Statusbar" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/g_statusbar/.+")
source_group("Versioning" FILES version.h win32/zdoom.rc) source_group("Versioning" FILES version.h win32/zdoom.rc)

View file

@ -16,11 +16,9 @@
*/ */
#include <string.h> /* for memcpy() */ #include <string.h> /* for memcpy() */
#include <algorithm>
#include "doomtype.h"
#include "md5.h" #include "md5.h"
#include "templates.h"
#include "files.h"
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
void byteSwap(uint32_t *buf, unsigned words) void byteSwap(uint32_t *buf, unsigned words)
@ -95,20 +93,6 @@ void MD5Context::Update(const uint8_t *buf, unsigned len)
memcpy(in, buf, len); memcpy(in, buf, len);
} }
void MD5Context::Update(FileReader &file, unsigned len)
{
uint8_t readbuf[8192];
long t;
while (len > 0)
{
t = MIN<long>(len, sizeof(readbuf));
len -= t;
t = (long)file.Read(readbuf, t);
Update(readbuf, t);
}
}
/* /*
* Final wrapup - pad to 64-byte boundary with the bit pattern * Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first) * 1 0* (64-bit count of bits processed, MSB-first)
@ -250,46 +234,3 @@ MD5Transform(uint32_t buf[4], const uint32_t in[16])
#endif #endif
//==========================================================================
//
// CCMD md5sum
//
// Like the command-line tool, because I wanted to make sure I had it right.
//
//==========================================================================
#include "c_dispatch.h"
#include <errno.h>
CCMD (md5sum)
{
if (argv.argc() < 2)
{
Printf("Usage: md5sum <file> ...\n");
}
for (int i = 1; i < argv.argc(); ++i)
{
FileReader fr;
if (!fr.OpenFile(argv[i]))
{
Printf("%s: %s\n", argv[i], strerror(errno));
}
else
{
MD5Context md5;
uint8_t readbuf[8192];
size_t len;
while ((len = fr.Read(readbuf, sizeof(readbuf))) > 0)
{
md5.Update(readbuf, (unsigned int)len);
}
md5.Final(readbuf);
for(int j = 0; j < 16; ++j)
{
Printf("%02x", readbuf[j]);
}
Printf(" *%s\n", argv[i]);
}
}
}

View file

@ -18,15 +18,12 @@
#ifndef MD5_H #ifndef MD5_H
#define MD5_H #define MD5_H
class FileReader;
struct MD5Context struct MD5Context
{ {
MD5Context() { Init(); } MD5Context() { Init(); }
void Init(); void Init();
void Update(const uint8_t *buf, unsigned len); void Update(const uint8_t *buf, unsigned len);
void Update(FileReader &file, unsigned len);
void Final(uint8_t digest[16]); void Final(uint8_t digest[16]);
private: private:

View file

@ -35,6 +35,7 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#ifdef _WIN32 #ifdef _WIN32
#include <direct.h> #include <direct.h>
@ -68,6 +69,7 @@
#include "c_functions.h" #include "c_functions.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "v_video.h" #include "v_video.h"
#include "md5.h"
extern FILE *Logfile; extern FILE *Logfile;
extern bool insave; extern bool insave;
@ -1303,3 +1305,45 @@ CCMD(r_showcaps)
PRINT_CAP("Truecolor Enabled", RFF_TRUECOLOR) PRINT_CAP("Truecolor Enabled", RFF_TRUECOLOR)
PRINT_CAP("Voxels", RFF_VOXELS) PRINT_CAP("Voxels", RFF_VOXELS)
} }
//==========================================================================
//
// CCMD md5sum
//
// Like the command-line tool, because I wanted to make sure I had it right.
//
//==========================================================================
CCMD (md5sum)
{
if (argv.argc() < 2)
{
Printf("Usage: md5sum <file> ...\n");
}
for (int i = 1; i < argv.argc(); ++i)
{
FileReader fr;
if (!fr.OpenFile(argv[i]))
{
Printf("%s: %s\n", argv[i], strerror(errno));
}
else
{
MD5Context md5;
uint8_t readbuf[8192];
size_t len;
while ((len = fr.Read(readbuf, sizeof(readbuf))) > 0)
{
md5.Update(readbuf, (unsigned int)len);
}
md5.Final(readbuf);
for(int j = 0; j < 16; ++j)
{
Printf("%02x", readbuf[j]);
}
Printf(" *%s\n", argv[i]);
}
}
}

View file

@ -2662,6 +2662,7 @@ static int D_DoomMain_Internal (void)
C_InitConback(); C_InitConback();
StartScreen->Progress(); StartScreen->Progress();
palMgr.Init(NUM_TRANSLATION_TABLES);
V_InitFonts(); V_InitFonts();
// [CW] Parse any TEAMINFO lumps. // [CW] Parse any TEAMINFO lumps.

View file

@ -83,6 +83,21 @@ FWadCollection Wads;
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
void md5Update(FileReader& file, MD5Context &md5, unsigned len)
{
uint8_t readbuf[8192];
unsigned t;
while (len > 0)
{
t = std::min<unsigned>(len, sizeof(readbuf));
len -= t;
t = (long)file.Read(readbuf, t);
md5.Update(readbuf, t);
}
}
//========================================================================== //==========================================================================
// //
// uppercoppy // uppercoppy
@ -282,7 +297,7 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadr)
{ {
MD5Context md5; MD5Context md5;
wadreader.Seek(0, FileReader::SeekSet); wadreader.Seek(0, FileReader::SeekSet);
md5.Update(wadreader, (unsigned)wadreader.GetLength()); md5Update(wadreader, md5, (unsigned)wadreader.GetLength());
md5.Final(cksum); md5.Final(cksum);
for (size_t j = 0; j < sizeof(cksum); ++j) for (size_t j = 0; j < sizeof(cksum); ++j)
@ -304,7 +319,7 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadr)
{ {
MD5Context md5; MD5Context md5;
auto reader = lump->NewReader(); auto reader = lump->NewReader();
md5.Update(reader, lump->LumpSize); md5Update(reader, md5, lump->LumpSize);
md5.Final(cksum); md5.Final(cksum);
for (size_t j = 0; j < sizeof(cksum); ++j) for (size_t j = 0; j < sizeof(cksum); ++j)
@ -966,7 +981,7 @@ void FWadCollection::RenameNerve ()
} }
fr->Seek(0, FileReader::SeekSet); fr->Seek(0, FileReader::SeekSet);
MD5Context md5; MD5Context md5;
md5.Update(*fr, (unsigned)fr->GetLength()); md5Update(*fr, md5, (unsigned)fr->GetLength());
md5.Final(cksum); md5.Final(cksum);
if (memcmp(nerve[isizecheck], cksum, 16) == 0) if (memcmp(nerve[isizecheck], cksum, 16) == 0)
{ {
@ -1033,7 +1048,7 @@ void FWadCollection::FixMacHexen()
uint8_t checksum[16]; uint8_t checksum[16];
MD5Context md5; MD5Context md5;
md5.Update(*reader, (unsigned)iwadSize); md5Update(*reader, md5, (unsigned)iwadSize);
md5.Final(checksum); md5.Final(checksum);
static const uint8_t HEXEN_DEMO_MD5[16] = static const uint8_t HEXEN_DEMO_MD5[16] =

View file

@ -41,6 +41,8 @@
#include "md5.h" #include "md5.h"
#include "g_levellocals.h" #include "g_levellocals.h"
void md5Update(FileReader& file, MD5Context& md5, unsigned len);
inline bool P_IsBuildMap(MapData *map) inline bool P_IsBuildMap(MapData *map)
{ {
return false; return false;
@ -395,19 +397,19 @@ void MapData::GetChecksum(uint8_t cksum[16])
if (isText) if (isText)
{ {
md5.Update(Reader(ML_TEXTMAP), Size(ML_TEXTMAP)); md5Update(Reader(ML_TEXTMAP), md5, Size(ML_TEXTMAP));
} }
else else
{ {
md5.Update(Reader(ML_LABEL), Size(ML_LABEL)); md5Update(Reader(ML_LABEL), md5, Size(ML_LABEL));
md5.Update(Reader(ML_THINGS), Size(ML_THINGS)); md5Update(Reader(ML_THINGS), md5, Size(ML_THINGS));
md5.Update(Reader(ML_LINEDEFS), Size(ML_LINEDEFS)); md5Update(Reader(ML_LINEDEFS), md5, Size(ML_LINEDEFS));
md5.Update(Reader(ML_SIDEDEFS), Size(ML_SIDEDEFS)); md5Update(Reader(ML_SIDEDEFS), md5, Size(ML_SIDEDEFS));
md5.Update(Reader(ML_SECTORS), Size(ML_SECTORS)); md5Update(Reader(ML_SECTORS), md5, Size(ML_SECTORS));
} }
if (HasBehavior) if (HasBehavior)
{ {
md5.Update(Reader(ML_BEHAVIOR), Size(ML_BEHAVIOR)); md5Update(Reader(ML_BEHAVIOR), md5, Size(ML_BEHAVIOR));
} }
md5.Final(cksum); md5.Final(cksum);
} }