From 9f2db42a198396fa1dedcecfb3f1fae2832539f4 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 2 Jul 2025 20:26:20 +0200 Subject: [PATCH] Move SawyerEncoding into OpenRCT2::SawyerCoding namespace, rename to ChunkEncoding --- src/openrct2/core/SawyerCoding.cpp | 8 +++---- src/openrct2/object/ObjectRepository.cpp | 9 ++++---- src/openrct2/rct12/SawyerChunk.cpp | 2 +- src/openrct2/rct12/SawyerChunk.h | 29 ++++++++++++------------ src/openrct2/rct12/SawyerChunkReader.cpp | 24 +++++++++++--------- src/openrct2/rct12/SawyerChunkWriter.cpp | 4 +++- src/openrct2/rct12/SawyerChunkWriter.h | 4 ++-- 7 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/openrct2/core/SawyerCoding.cpp b/src/openrct2/core/SawyerCoding.cpp index 464b739f70..5c00249e57 100644 --- a/src/openrct2/core/SawyerCoding.cpp +++ b/src/openrct2/core/SawyerCoding.cpp @@ -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(0x600000); chunkHeader.length = static_cast(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(chunkHeader.length * 2); auto encode_buffer2 = std::make_unique(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(chunkHeader.length); std::memcpy(encode_buffer.get(), buffer, chunkHeader.length); diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index c0fe0545d2..3b130e65fc 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -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 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 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( diff --git a/src/openrct2/rct12/SawyerChunk.cpp b/src/openrct2/rct12/SawyerChunk.cpp index bb5ec1dfcc..cb3a047ab1 100644 --- a/src/openrct2/rct12/SawyerChunk.cpp +++ b/src/openrct2/rct12/SawyerChunk.cpp @@ -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) { diff --git a/src/openrct2/rct12/SawyerChunk.h b/src/openrct2/rct12/SawyerChunk.h index 1bc947c31a..dfd5be8dc8 100644 --- a/src/openrct2/rct12/SawyerChunk.h +++ b/src/openrct2/rct12/SawyerChunk.h @@ -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 diff --git a/src/openrct2/rct12/SawyerChunkReader.cpp b/src/openrct2/rct12/SawyerChunkReader.cpp index 2d0c5bbdcb..78ac13296c 100644 --- a/src/openrct2/rct12/SawyerChunkReader.cpp +++ b/src/openrct2/rct12/SawyerChunkReader.cpp @@ -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(header.length); if (_stream->TryRead(compressedData.get(), header.length) != header.length) @@ -75,7 +77,7 @@ namespace OpenRCT2 throw SawyerChunkException(kExceptionMessageZeroSizedChunk); } - return std::make_shared(static_cast(header.encoding), std::move(buffer)); + return std::make_shared(static_cast(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(SawyerEncoding::rle, std::move(buffer)); + return std::make_shared(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: diff --git a/src/openrct2/rct12/SawyerChunkWriter.cpp b/src/openrct2/rct12/SawyerChunkWriter.cpp index f4a682d455..035954bd5e 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.cpp +++ b/src/openrct2/rct12/SawyerChunkWriter.cpp @@ -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; diff --git a/src/openrct2/rct12/SawyerChunkWriter.h b/src/openrct2/rct12/SawyerChunkWriter.h index 6c194a4a94..94d159de52 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.h +++ b/src/openrct2/rct12/SawyerChunkWriter.h @@ -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 - void WriteChunk(const T* src, SawyerEncoding encoding) + void WriteChunk(const T* src, SawyerCoding::ChunkEncoding encoding) { WriteChunk(src, sizeof(T), encoding); }