Added user setting compression factor
This commit is contained in:
parent
cef2967637
commit
a54cbba0fd
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/// Compresses a_Data into a_Compressed; returns Z_XXX error constants same as zlib's compress2()
|
/// Compresses a_Data into a_Compressed; returns Z_XXX error constants same as zlib's compress2()
|
||||||
int CompressString(const char * a_Data, int a_Length, AString & a_Compressed)
|
int CompressString(const char * a_Data, int a_Length, AString & a_Compressed, int a_Factor)
|
||||||
{
|
{
|
||||||
uLongf CompressedSize = compressBound(a_Length);
|
uLongf CompressedSize = compressBound(a_Length);
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ int CompressString(const char * a_Data, int a_Length, AString & a_Compressed)
|
|||||||
// It saves us one allocation and one memcpy of the entire compressed data
|
// It saves us one allocation and one memcpy of the entire compressed data
|
||||||
// It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010)
|
// It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010)
|
||||||
a_Compressed.resize(CompressedSize);
|
a_Compressed.resize(CompressedSize);
|
||||||
int errorcode = compress2( (Bytef*)a_Compressed.data(), &CompressedSize, (const Bytef*)a_Data, a_Length, Z_DEFAULT_COMPRESSION);
|
int errorcode = compress2( (Bytef*)a_Compressed.data(), &CompressedSize, (const Bytef*)a_Data, a_Length, a_Factor);
|
||||||
if (errorcode != Z_OK)
|
if (errorcode != Z_OK)
|
||||||
{
|
{
|
||||||
return errorcode;
|
return errorcode;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/// Compresses a_Data into a_Compressed using ZLIB; returns Z_XXX error constants same as zlib's compress2()
|
/// Compresses a_Data into a_Compressed using ZLIB; returns Z_XXX error constants same as zlib's compress2()
|
||||||
extern int CompressString(const char * a_Data, int a_Length, AString & a_Compressed);
|
extern int CompressString(const char * a_Data, int a_Length, AString & a_Compressed, int a_Factor);
|
||||||
|
|
||||||
/// Uncompresses a_Data into a_Uncompressed; returns Z_XXX error constants same as zlib's decompress()
|
/// Uncompresses a_Data into a_Uncompressed; returns Z_XXX error constants same as zlib's decompress()
|
||||||
extern int UncompressString(const char * a_Data, int a_Length, AString & a_Uncompressed, int a_UncompressedSize);
|
extern int UncompressString(const char * a_Data, int a_Length, AString & a_Uncompressed, int a_UncompressedSize);
|
||||||
|
@ -231,6 +231,7 @@ cWorld::cWorld(const AString & a_WorldName) :
|
|||||||
m_WorldName(a_WorldName),
|
m_WorldName(a_WorldName),
|
||||||
m_IniFileName(m_WorldName + "/world.ini"),
|
m_IniFileName(m_WorldName + "/world.ini"),
|
||||||
m_StorageSchema("Default"),
|
m_StorageSchema("Default"),
|
||||||
|
m_StorageCompressionFactor(6),
|
||||||
m_IsSpawnExplicitlySet(false),
|
m_IsSpawnExplicitlySet(false),
|
||||||
m_WorldAgeSecs(0),
|
m_WorldAgeSecs(0),
|
||||||
m_TimeOfDaySecs(0),
|
m_TimeOfDaySecs(0),
|
||||||
@ -512,6 +513,7 @@ void cWorld::Start(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema);
|
m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema);
|
||||||
|
m_StorageCompressionFactor = IniFile.GetValueSetI ("Storage", "CompressionFactor", m_StorageCompressionFactor);
|
||||||
m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3);
|
m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3);
|
||||||
m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3);
|
m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3);
|
||||||
m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false);
|
m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false);
|
||||||
@ -585,7 +587,7 @@ void cWorld::Start(void)
|
|||||||
m_SimulatorManager->RegisterSimulator(m_RedstoneSimulator, 1);
|
m_SimulatorManager->RegisterSimulator(m_RedstoneSimulator, 1);
|
||||||
|
|
||||||
m_Lighting.Start(this);
|
m_Lighting.Start(this);
|
||||||
m_Storage.Start(this, m_StorageSchema);
|
m_Storage.Start(this, m_StorageSchema, m_StorageCompressionFactor );
|
||||||
m_Generator.Start(m_GeneratorCallbacks, m_GeneratorCallbacks, IniFile);
|
m_Generator.Start(m_GeneratorCallbacks, m_GeneratorCallbacks, IniFile);
|
||||||
m_ChunkSender.Start(this);
|
m_ChunkSender.Start(this);
|
||||||
m_TickThread.Start();
|
m_TickThread.Start();
|
||||||
|
@ -681,6 +681,8 @@ private:
|
|||||||
/// Name of the storage schema used to load and save chunks
|
/// Name of the storage schema used to load and save chunks
|
||||||
AString m_StorageSchema;
|
AString m_StorageSchema;
|
||||||
|
|
||||||
|
int m_StorageCompressionFactor;
|
||||||
|
|
||||||
/// The dimension of the world, used by the client to provide correct lighting scheme
|
/// The dimension of the world, used by the client to provide correct lighting scheme
|
||||||
eDimension m_Dimension;
|
eDimension m_Dimension;
|
||||||
|
|
||||||
|
@ -58,8 +58,9 @@ Since only the header is actually in the memory, this number can be high, but st
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// cWSSAnvil:
|
// cWSSAnvil:
|
||||||
|
|
||||||
cWSSAnvil::cWSSAnvil(cWorld * a_World) :
|
cWSSAnvil::cWSSAnvil(cWorld * a_World, int a_CompressionFactor) :
|
||||||
super(a_World)
|
super(a_World),
|
||||||
|
m_CompressionFactor(a_CompressionFactor)
|
||||||
{
|
{
|
||||||
// Create a level.dat file for mapping tools, if it doesn't already exist:
|
// Create a level.dat file for mapping tools, if it doesn't already exist:
|
||||||
AString fnam;
|
AString fnam;
|
||||||
@ -272,7 +273,7 @@ bool cWSSAnvil::SaveChunkToData(const cChunkCoords & a_Chunk, AString & a_Data)
|
|||||||
}
|
}
|
||||||
Writer.Finish();
|
Writer.Finish();
|
||||||
|
|
||||||
CompressString(Writer.GetResult().data(), Writer.GetResult().size(), a_Data);
|
CompressString(Writer.GetResult().data(), Writer.GetResult().size(), a_Data, m_CompressionFactor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class cWSSAnvil :
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cWSSAnvil(cWorld * a_World);
|
cWSSAnvil(cWorld * a_World, int a_CompressionFactor);
|
||||||
virtual ~cWSSAnvil();
|
virtual ~cWSSAnvil();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -89,6 +89,8 @@ protected:
|
|||||||
|
|
||||||
cCriticalSection m_CS;
|
cCriticalSection m_CS;
|
||||||
cMCAFiles m_Files; // a MRU cache of MCA files
|
cMCAFiles m_Files; // a MRU cache of MCA files
|
||||||
|
|
||||||
|
int m_CompressionFactor;
|
||||||
|
|
||||||
/// Gets chunk data from the correct file; locks file CS as needed
|
/// Gets chunk data from the correct file; locks file CS as needed
|
||||||
bool GetChunkData(const cChunkCoords & a_Chunk, AString & a_Data);
|
bool GetChunkData(const cChunkCoords & a_Chunk, AString & a_Data);
|
||||||
|
@ -193,7 +193,7 @@ cWSSCompact::cPAKFile * cWSSCompact::LoadPAKFile(const cChunkCoords & a_Chunk)
|
|||||||
// Load it anew:
|
// Load it anew:
|
||||||
AString FileName;
|
AString FileName;
|
||||||
Printf(FileName, "%s/X%i_Z%i.pak", m_World->GetName().c_str(), LayerX, LayerZ );
|
Printf(FileName, "%s/X%i_Z%i.pak", m_World->GetName().c_str(), LayerX, LayerZ );
|
||||||
cPAKFile * f = new cPAKFile(FileName, LayerX, LayerZ);
|
cPAKFile * f = new cPAKFile(FileName, LayerX, LayerZ, m_CompressionFactor);
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -399,8 +399,9 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
|
|||||||
return; \
|
return; \
|
||||||
}
|
}
|
||||||
|
|
||||||
cWSSCompact::cPAKFile::cPAKFile(const AString & a_FileName, int a_LayerX, int a_LayerZ) :
|
cWSSCompact::cPAKFile::cPAKFile(const AString & a_FileName, int a_LayerX, int a_LayerZ, int a_CompressionFactor) :
|
||||||
m_FileName(a_FileName),
|
m_FileName(a_FileName),
|
||||||
|
m_CompressionFactor(a_CompressionFactor),
|
||||||
m_LayerX(a_LayerX),
|
m_LayerX(a_LayerX),
|
||||||
m_LayerZ(a_LayerZ),
|
m_LayerZ(a_LayerZ),
|
||||||
m_NumDirty(0),
|
m_NumDirty(0),
|
||||||
@ -648,7 +649,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2()
|
|||||||
// Re-compress data
|
// Re-compress data
|
||||||
AString CompressedData;
|
AString CompressedData;
|
||||||
{
|
{
|
||||||
int errorcode = CompressString(Converted.data(), Converted.size(), CompressedData);
|
int errorcode = CompressString(Converted.data(), Converted.size(), CompressedData,m_CompressionFactor);
|
||||||
if (errorcode != Z_OK)
|
if (errorcode != Z_OK)
|
||||||
{
|
{
|
||||||
LOGERROR("Error %d compressing data for chunk [%d, %d]",
|
LOGERROR("Error %d compressing data for chunk [%d, %d]",
|
||||||
@ -786,7 +787,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
|
|||||||
// Re-compress data
|
// Re-compress data
|
||||||
AString CompressedData;
|
AString CompressedData;
|
||||||
{
|
{
|
||||||
int errorcode = CompressString(Converted.data(), Converted.size(), CompressedData);
|
int errorcode = CompressString(Converted.data(), Converted.size(), CompressedData, m_CompressionFactor);
|
||||||
if (errorcode != Z_OK)
|
if (errorcode != Z_OK)
|
||||||
{
|
{
|
||||||
LOGERROR("Error %d compressing data for chunk [%d, %d]",
|
LOGERROR("Error %d compressing data for chunk [%d, %d]",
|
||||||
@ -939,7 +940,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
|
|||||||
|
|
||||||
// Compress the data:
|
// Compress the data:
|
||||||
AString CompressedData;
|
AString CompressedData;
|
||||||
int errorcode = CompressString(Data.data(), Data.size(), CompressedData);
|
int errorcode = CompressString(Data.data(), Data.size(), CompressedData, m_CompressionFactor);
|
||||||
if ( errorcode != Z_OK )
|
if ( errorcode != Z_OK )
|
||||||
{
|
{
|
||||||
LOGERROR("Error %i compressing data for chunk [%d, %d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
|
LOGERROR("Error %i compressing data for chunk [%d, %d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
|
||||||
|
@ -53,7 +53,7 @@ class cWSSCompact :
|
|||||||
public cWSSchema
|
public cWSSchema
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cWSSCompact(cWorld * a_World) : cWSSchema(a_World) {}
|
cWSSCompact(cWorld * a_World, int a_CompressionFactor) : cWSSchema(a_World), m_CompressionFactor(a_CompressionFactor) {}
|
||||||
virtual ~cWSSCompact();
|
virtual ~cWSSCompact();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -74,7 +74,7 @@ protected:
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cPAKFile(const AString & a_FileName, int a_LayerX, int a_LayerZ);
|
cPAKFile(const AString & a_FileName, int a_LayerX, int a_LayerZ, int a_CompressionFactor);
|
||||||
~cPAKFile();
|
~cPAKFile();
|
||||||
|
|
||||||
bool GetChunkData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, AString & a_Data);
|
bool GetChunkData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, AString & a_Data);
|
||||||
@ -95,6 +95,7 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
AString m_FileName;
|
AString m_FileName;
|
||||||
|
int m_CompressionFactor;
|
||||||
int m_LayerX;
|
int m_LayerX;
|
||||||
int m_LayerZ;
|
int m_LayerZ;
|
||||||
|
|
||||||
@ -119,6 +120,8 @@ protected:
|
|||||||
cCriticalSection m_CS;
|
cCriticalSection m_CS;
|
||||||
cPAKFiles m_PAKFiles; // A MRU cache of PAK files
|
cPAKFiles m_PAKFiles; // A MRU cache of PAK files
|
||||||
|
|
||||||
|
int m_CompressionFactor;
|
||||||
|
|
||||||
/// Loads the correct PAK file either from cache or from disk, manages the m_PAKFiles cache
|
/// Loads the correct PAK file either from cache or from disk, manages the m_PAKFiles cache
|
||||||
cPAKFile * LoadPAKFile(const cChunkCoords & a_Chunk);
|
cPAKFile * LoadPAKFile(const cChunkCoords & a_Chunk);
|
||||||
|
|
||||||
|
@ -68,11 +68,11 @@ cWorldStorage::~cWorldStorage()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cWorldStorage::Start(cWorld * a_World, const AString & a_StorageSchemaName)
|
bool cWorldStorage::Start(cWorld * a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor )
|
||||||
{
|
{
|
||||||
m_World = a_World;
|
m_World = a_World;
|
||||||
m_StorageSchemaName = a_StorageSchemaName;
|
m_StorageSchemaName = a_StorageSchemaName;
|
||||||
InitSchemas();
|
InitSchemas(a_StorageCompressionFactor);
|
||||||
|
|
||||||
return super::Start();
|
return super::Start();
|
||||||
}
|
}
|
||||||
@ -197,11 +197,11 @@ void cWorldStorage::UnqueueSave(const cChunkCoords & a_Chunk)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cWorldStorage::InitSchemas(void)
|
void cWorldStorage::InitSchemas(int a_StorageCompressionFactor)
|
||||||
{
|
{
|
||||||
// The first schema added is considered the default
|
// The first schema added is considered the default
|
||||||
m_Schemas.push_back(new cWSSAnvil (m_World));
|
m_Schemas.push_back(new cWSSAnvil (m_World,a_StorageCompressionFactor));
|
||||||
m_Schemas.push_back(new cWSSCompact (m_World));
|
m_Schemas.push_back(new cWSSCompact (m_World,a_StorageCompressionFactor));
|
||||||
m_Schemas.push_back(new cWSSForgetful(m_World));
|
m_Schemas.push_back(new cWSSForgetful(m_World));
|
||||||
// Add new schemas here
|
// Add new schemas here
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
void UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
|
void UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
|
||||||
void UnqueueSave(const cChunkCoords & a_Chunk);
|
void UnqueueSave(const cChunkCoords & a_Chunk);
|
||||||
|
|
||||||
bool Start(cWorld * a_World, const AString & a_StorageSchemaName); // Hide the cIsThread's Start() method, we need to provide args
|
bool Start(cWorld * a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor); // Hide the cIsThread's Start() method, we need to provide args
|
||||||
void Stop(void); // Hide the cIsThread's Stop() method, we need to signal the event
|
void Stop(void); // Hide the cIsThread's Stop() method, we need to signal the event
|
||||||
void WaitForFinish(void);
|
void WaitForFinish(void);
|
||||||
void WaitForLoadQueueEmpty(void);
|
void WaitForLoadQueueEmpty(void);
|
||||||
@ -126,7 +126,7 @@ protected:
|
|||||||
/// The one storage schema used for saving
|
/// The one storage schema used for saving
|
||||||
cWSSchema * m_SaveSchema;
|
cWSSchema * m_SaveSchema;
|
||||||
|
|
||||||
void InitSchemas(void);
|
void InitSchemas(int a_StorageCompressionFactor);
|
||||||
|
|
||||||
virtual void Execute(void) override;
|
virtual void Execute(void) override;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user