Make sure xchunk write size can specified to be smaller than xchunk size to respect zlib to add size instead of removing size due to not being able to compress

This commit is contained in:
Jan 2021-03-18 11:47:41 +01:00
parent 7c0504603e
commit 2add1ba22d
4 changed files with 12 additions and 8 deletions

View File

@ -25,6 +25,7 @@ namespace T6
static constexpr int ZONE_VERSION = 147;
static constexpr int STREAM_COUNT = 4;
static constexpr int XCHUNK_SIZE = 0x8000;
static constexpr int XCHUNK_MAX_WRITE_SIZE = XCHUNK_SIZE - 0x40;
static constexpr int VANILLA_BUFFER_SIZE = 0x80000;
static constexpr int OFFSET_BLOCK_BIT_COUNT = 3;
static constexpr block_t INSERT_BLOCK = XFILE_BLOCK_VIRTUAL;

View File

@ -74,7 +74,7 @@ public:
ICapturedDataProvider* AddXChunkProcessor(const bool isEncrypted)
{
ICapturedDataProvider* result = nullptr;
auto xChunkProcessor = std::make_unique<OutputProcessorXChunks>(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
auto xChunkProcessor = std::make_unique<OutputProcessorXChunks>(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::XCHUNK_MAX_WRITE_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
// Decompress the chunks using zlib
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorDeflate>());

View File

@ -55,9 +55,10 @@ void OutputProcessorXChunks::WriteChunk()
m_current_stream = (m_current_stream + 1) % m_stream_count;
}
OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize)
OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize, const size_t xChunkWriteSize)
: m_stream_count(numStreams),
m_chunk_size(xChunkSize),
m_chunk_write_size(xChunkWriteSize),
m_vanilla_buffer_size(0),
m_initialized(false),
m_current_stream(0),
@ -68,6 +69,7 @@ OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_
{
assert(numStreams > 0);
assert(xChunkSize > 0);
assert(m_chunk_size >= m_chunk_write_size);
for (auto i = 0u; i < 2u; i++)
m_buffers.emplace_back(std::make_unique<uint8_t[]>(xChunkSize));
@ -76,8 +78,8 @@ OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_
m_output_buffer = m_buffers[1].get();
}
OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize)
: OutputProcessorXChunks(numStreams, xChunkSize)
OutputProcessorXChunks::OutputProcessorXChunks(const int numStreams, const size_t xChunkSize, const size_t xChunkWriteSize, const size_t vanillaBufferSize)
: OutputProcessorXChunks(numStreams, xChunkSize, xChunkWriteSize)
{
m_vanilla_buffer_size = vanillaBufferSize;
}
@ -99,11 +101,11 @@ void OutputProcessorXChunks::Write(const void* buffer, const size_t length)
auto sizeRemaining = length;
while (sizeRemaining > 0)
{
const auto toWrite = std::min(m_chunk_size - m_input_size, sizeRemaining);
const auto toWrite = std::min(m_chunk_write_size - m_input_size, sizeRemaining);
memcpy(&m_input_buffer[m_input_size], &static_cast<const char*>(buffer)[length - sizeRemaining], toWrite);
m_input_size += toWrite;
if (m_input_size >= m_chunk_size)
if (m_input_size >= m_chunk_write_size)
WriteChunk();
sizeRemaining -= toWrite;

View File

@ -13,6 +13,7 @@ class OutputProcessorXChunks final : public OutputStreamProcessor
int m_stream_count;
size_t m_chunk_size;
size_t m_chunk_write_size;
size_t m_vanilla_buffer_size;
bool m_initialized;
@ -28,8 +29,8 @@ class OutputProcessorXChunks final : public OutputStreamProcessor
void WriteChunk();
public:
OutputProcessorXChunks(int numStreams, size_t xChunkSize);
OutputProcessorXChunks(int numStreams, size_t xChunkSize, size_t vanillaBufferSize);
OutputProcessorXChunks(int numStreams, size_t xChunkSize, size_t xChunkWriteSize);
OutputProcessorXChunks(int numStreams, size_t xChunkSize, size_t xChunkWriteSize, size_t vanillaBufferSize);
~OutputProcessorXChunks() override = default;
OutputProcessorXChunks(const OutputProcessorXChunks& other) = delete;