mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #7782 from Robyt3/Datafile-Zlib-Include-Cleanup
Avoid including `zlib.h` in header file
This commit is contained in:
commit
8c5210a156
|
@ -14,6 +14,8 @@
|
|||
#include <cstdlib>
|
||||
#include <limits>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
static const int DEBUG = 0;
|
||||
|
||||
enum
|
||||
|
@ -732,7 +734,7 @@ int CDataFileWriter::AddItem(int Type, int ID, size_t Size, const void *pData, c
|
|||
return NumItems;
|
||||
}
|
||||
|
||||
int CDataFileWriter::AddData(size_t Size, const void *pData, int CompressionLevel)
|
||||
int CDataFileWriter::AddData(size_t Size, const void *pData, ECompressionLevel CompressionLevel)
|
||||
{
|
||||
dbg_assert(Size > 0 && pData != nullptr, "Data missing");
|
||||
dbg_assert(Size <= (size_t)std::numeric_limits<int>::max(), "Data too large");
|
||||
|
@ -776,6 +778,20 @@ int CDataFileWriter::AddDataString(const char *pStr)
|
|||
return AddData(str_length(pStr) + 1, pStr);
|
||||
}
|
||||
|
||||
static int CompressionLevelToZlib(CDataFileWriter::ECompressionLevel CompressionLevel)
|
||||
{
|
||||
switch(CompressionLevel)
|
||||
{
|
||||
case CDataFileWriter::COMPRESSION_DEFAULT:
|
||||
return Z_DEFAULT_COMPRESSION;
|
||||
case CDataFileWriter::COMPRESSION_BEST:
|
||||
return Z_BEST_COMPRESSION;
|
||||
default:
|
||||
dbg_assert(false, "CompressionLevel invalid");
|
||||
dbg_break();
|
||||
}
|
||||
}
|
||||
|
||||
void CDataFileWriter::Finish()
|
||||
{
|
||||
dbg_assert((bool)m_File, "File not open");
|
||||
|
@ -786,7 +802,7 @@ void CDataFileWriter::Finish()
|
|||
{
|
||||
unsigned long CompressedSize = compressBound(DataInfo.m_UncompressedSize);
|
||||
DataInfo.m_pCompressedData = malloc(CompressedSize);
|
||||
const int Result = compress2((Bytef *)DataInfo.m_pCompressedData, &CompressedSize, (Bytef *)DataInfo.m_pUncompressedData, DataInfo.m_UncompressedSize, DataInfo.m_CompressionLevel);
|
||||
const int Result = compress2((Bytef *)DataInfo.m_pCompressedData, &CompressedSize, (Bytef *)DataInfo.m_pUncompressedData, DataInfo.m_UncompressedSize, CompressionLevelToZlib(DataInfo.m_CompressionLevel));
|
||||
DataInfo.m_CompressedSize = CompressedSize;
|
||||
free(DataInfo.m_pUncompressedData);
|
||||
DataInfo.m_pUncompressedData = nullptr;
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
enum
|
||||
{
|
||||
ITEMTYPE_EX = 0xffff,
|
||||
|
@ -70,13 +68,21 @@ public:
|
|||
// write access
|
||||
class CDataFileWriter
|
||||
{
|
||||
public:
|
||||
enum ECompressionLevel
|
||||
{
|
||||
COMPRESSION_DEFAULT,
|
||||
COMPRESSION_BEST,
|
||||
};
|
||||
|
||||
private:
|
||||
struct CDataInfo
|
||||
{
|
||||
void *m_pUncompressedData;
|
||||
int m_UncompressedSize;
|
||||
void *m_pCompressedData;
|
||||
int m_CompressedSize;
|
||||
int m_CompressionLevel;
|
||||
ECompressionLevel m_CompressionLevel;
|
||||
};
|
||||
|
||||
struct CItemInfo
|
||||
|
@ -131,7 +137,7 @@ public:
|
|||
|
||||
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType = IStorage::TYPE_SAVE);
|
||||
int AddItem(int Type, int ID, size_t Size, const void *pData, const CUuid *pUuid = nullptr);
|
||||
int AddData(size_t Size, const void *pData, int CompressionLevel = Z_DEFAULT_COMPRESSION);
|
||||
int AddData(size_t Size, const void *pData, ECompressionLevel CompressionLevel = COMPRESSION_DEFAULT);
|
||||
int AddDataSwapped(size_t Size, const void *pData);
|
||||
int AddDataString(const char *pStr);
|
||||
void Finish();
|
||||
|
|
|
@ -3741,7 +3741,7 @@ bool CGameClient::InitMultiView(int Team)
|
|||
CurPosition.y = CurCharacter.m_Y;
|
||||
}
|
||||
|
||||
int ClosestDistance = INT_MAX;
|
||||
int ClosestDistance = std::numeric_limits<int>::max();
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(!m_Snap.m_apPlayerInfos[i] || m_Snap.m_apPlayerInfos[i]->m_Team == TEAM_SPECTATORS || m_Teams.Team(i) != m_MultiViewTeam)
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include <game/mapitems.h>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
void CreateEmptyMap(IStorage *pStorage)
|
||||
{
|
||||
const char *pMapName = "maps/dummy3.map";
|
||||
|
|
|
@ -308,7 +308,7 @@ int main(int argc, const char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
Writer.AddData(Size, pPtr, Z_BEST_COMPRESSION);
|
||||
Writer.AddData(Size, pPtr, CDataFileWriter::COMPRESSION_BEST);
|
||||
|
||||
if(DeletePtr)
|
||||
free(pPtr);
|
||||
|
|
Loading…
Reference in a new issue