1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 09:32:29 +01:00

Move SawyerEncoding into OpenRCT2::SawyerCoding namespace, rename to ChunkEncoding

This commit is contained in:
Gymnasiast
2025-07-02 20:26:20 +02:00
parent f2a483e0df
commit 9f2db42a19
7 changed files with 42 additions and 38 deletions

View File

@@ -45,14 +45,14 @@ namespace OpenRCT2::SawyerCoding
{
switch (chunkHeader.encoding)
{
case SawyerEncoding::none:
case ChunkEncoding::none:
std::memcpy(dst_file, &chunkHeader, sizeof(ChunkHeader));
dst_file += sizeof(ChunkHeader);
std::memcpy(dst_file, buffer, chunkHeader.length);
// fwrite(&chunkHeader, sizeof(ChunkHeader), 1, file);
// fwrite(buffer, 1, chunkHeader.length, file);
break;
case SawyerEncoding::rle:
case ChunkEncoding::rle:
{
auto encode_buffer = std::make_unique<uint8_t[]>(0x600000);
chunkHeader.length = static_cast<uint32_t>(EncodeChunkRLE(buffer, encode_buffer.get(), chunkHeader.length));
@@ -61,7 +61,7 @@ namespace OpenRCT2::SawyerCoding
std::memcpy(dst_file, encode_buffer.get(), chunkHeader.length);
}
break;
case SawyerEncoding::rleCompressed:
case ChunkEncoding::rleCompressed:
{
auto encode_buffer = std::make_unique<uint8_t[]>(chunkHeader.length * 2);
auto encode_buffer2 = std::make_unique<uint8_t[]>(0x600000);
@@ -73,7 +73,7 @@ namespace OpenRCT2::SawyerCoding
std::memcpy(dst_file, encode_buffer2.get(), chunkHeader.length);
}
break;
case SawyerEncoding::rotate:
case ChunkEncoding::rotate:
{
auto encode_buffer = std::make_unique<uint8_t[]>(chunkHeader.length);
std::memcpy(encode_buffer.get(), buffer, chunkHeader.length);

View File

@@ -47,6 +47,7 @@
#undef CP_UTF8
using namespace OpenRCT2;
using namespace OpenRCT2::SawyerCoding;
struct ObjectEntryHash
{
@@ -475,10 +476,10 @@ private:
}
// 0x0098DA2C
static constexpr std::array<SawyerEncoding, 11> kLegacyObjectEntryGroupEncoding = {
SawyerEncoding::rle, SawyerEncoding::rle, SawyerEncoding::rle, SawyerEncoding::rle,
SawyerEncoding::rle, SawyerEncoding::rle, SawyerEncoding::rle, SawyerEncoding::rle,
SawyerEncoding::rle, SawyerEncoding::rle, SawyerEncoding::rotate,
static constexpr std::array<ChunkEncoding, 11> kLegacyObjectEntryGroupEncoding = {
ChunkEncoding::rle, ChunkEncoding::rle, ChunkEncoding::rle, ChunkEncoding::rle,
ChunkEncoding::rle, ChunkEncoding::rle, ChunkEncoding::rle, ChunkEncoding::rle,
ChunkEncoding::rle, ChunkEncoding::rle, ChunkEncoding::rotate,
};
static void SaveObject(

View File

@@ -13,7 +13,7 @@
namespace OpenRCT2
{
SawyerChunk::SawyerChunk(SawyerEncoding encoding, MemoryStream&& data)
SawyerChunk::SawyerChunk(SawyerCoding::ChunkEncoding encoding, MemoryStream&& data)
: _data(std::move(data))
, _encoding(encoding)
{

View File

@@ -15,23 +15,22 @@
namespace OpenRCT2
{
/**
* The type of encoding / compression for a sawyer encoded chunk.
*/
enum class SawyerEncoding : uint8_t
{
none,
rle,
rleCompressed,
rotate,
};
namespace SawyerCoding
{
/**
* The type of encoding / compression for a sawyer encoded chunk.
*/
enum class ChunkEncoding : uint8_t
{
none,
rle,
rleCompressed,
rotate,
};
#pragma pack(push, 1)
struct ChunkHeader
{
SawyerEncoding encoding;
ChunkEncoding encoding;
uint32_t length;
};
static_assert(sizeof(ChunkHeader) == 5);
@@ -45,7 +44,7 @@ namespace OpenRCT2
{
private:
OpenRCT2::MemoryStream _data;
SawyerEncoding _encoding = SawyerEncoding::none;
SawyerCoding::ChunkEncoding _encoding = SawyerCoding::ChunkEncoding::none;
public:
const void* GetData() const
@@ -56,11 +55,11 @@ namespace OpenRCT2
{
return _data.GetLength();
}
SawyerEncoding GetEncoding() const
SawyerCoding::ChunkEncoding GetEncoding() const
{
return _encoding;
}
SawyerChunk(SawyerEncoding encoding, OpenRCT2::MemoryStream&& data);
SawyerChunk(SawyerCoding::ChunkEncoding encoding, OpenRCT2::MemoryStream&& data);
};
} // namespace OpenRCT2

View File

@@ -13,6 +13,8 @@
#include "../core/MemoryStream.h"
#include "../core/Numerics.hpp"
using namespace OpenRCT2::SawyerCoding;
namespace OpenRCT2
{
// Allow chunks to be uncompressed to a maximum of 16 MiB
@@ -58,10 +60,10 @@ namespace OpenRCT2
switch (header.encoding)
{
case SawyerEncoding::none:
case SawyerEncoding::rle:
case SawyerEncoding::rleCompressed:
case SawyerEncoding::rotate:
case ChunkEncoding::none:
case ChunkEncoding::rle:
case ChunkEncoding::rleCompressed:
case ChunkEncoding::rotate:
{
auto compressedData = std::make_unique<uint8_t[]>(header.length);
if (_stream->TryRead(compressedData.get(), header.length) != header.length)
@@ -75,7 +77,7 @@ namespace OpenRCT2
throw SawyerChunkException(kExceptionMessageZeroSizedChunk);
}
return std::make_shared<SawyerChunk>(static_cast<SawyerEncoding>(header.encoding), std::move(buffer));
return std::make_shared<SawyerChunk>(static_cast<ChunkEncoding>(header.encoding), std::move(buffer));
}
default:
throw SawyerChunkException(kExceptionMessageInvalidChunkEncoding);
@@ -108,13 +110,13 @@ namespace OpenRCT2
throw SawyerChunkException(kExceptionMessageCorruptChunkSize);
}
SawyerCoding::ChunkHeader header{ SawyerEncoding::rle, compressedDataLength };
SawyerCoding::ChunkHeader header{ ChunkEncoding::rle, compressedDataLength };
auto buffer = DecodeChunk(compressedData.get(), header);
if (buffer.GetLength() == 0)
{
throw SawyerChunkException(kExceptionMessageZeroSizedChunk);
}
return std::make_shared<SawyerChunk>(SawyerEncoding::rle, std::move(buffer));
return std::make_shared<SawyerChunk>(ChunkEncoding::rle, std::move(buffer));
}
catch (const std::exception&)
{
@@ -266,16 +268,16 @@ namespace OpenRCT2
switch (header.encoding)
{
case SawyerEncoding::none:
case ChunkEncoding::none:
buf.Write(src, header.length);
break;
case SawyerEncoding::rle:
case ChunkEncoding::rle:
buf = DecodeChunkRLE(src, header.length);
break;
case SawyerEncoding::rleCompressed:
case ChunkEncoding::rleCompressed:
buf = DecodeChunkRLERepeat(src, header.length);
break;
case SawyerEncoding::rotate:
case ChunkEncoding::rotate:
buf = DecodeChunkRotate(src, header.length);
break;
default:

View File

@@ -13,6 +13,8 @@
#include "../core/Numerics.hpp"
#include "../core/SawyerCoding.h"
using namespace OpenRCT2::SawyerCoding;
namespace OpenRCT2
{
// Maximum buffer size to store compressed data, maximum of 16 MiB
@@ -28,7 +30,7 @@ namespace OpenRCT2
WriteChunk(chunk->GetData(), chunk->GetLength(), chunk->GetEncoding());
}
void SawyerChunkWriter::WriteChunk(const void* src, size_t length, SawyerEncoding encoding)
void SawyerChunkWriter::WriteChunk(const void* src, size_t length, ChunkEncoding encoding)
{
SawyerCoding::ChunkHeader header;
header.encoding = encoding;

View File

@@ -39,7 +39,7 @@ namespace OpenRCT2
* @param src The source buffer.
* @param length The size of the source buffer.
*/
void WriteChunk(const void* src, size_t length, SawyerEncoding encoding);
void WriteChunk(const void* src, size_t length, SawyerCoding::ChunkEncoding encoding);
/**
* Writes a track chunk to the stream containing the given buffer.
@@ -52,7 +52,7 @@ namespace OpenRCT2
* Writes a chunk to the stream containing the given type.
*/
template<typename T>
void WriteChunk(const T* src, SawyerEncoding encoding)
void WriteChunk(const T* src, SawyerCoding::ChunkEncoding encoding)
{
WriteChunk(src, sizeof(T), encoding);
}