mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-27 00:34:46 +01:00
Move Sawyer coding into its own namespace
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "scenario/Scenario.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
|
||||
static bool TryClassifyAsPark(OpenRCT2::IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsS6(OpenRCT2::IStream* stream, ClassifiedFileInfo* result);
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
|
||||
struct IFileDataRetriever
|
||||
{
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
#include <vector>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
|
||||
static constexpr ObjectEntryIndex ObjectEntryIndexIgnore = 254;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <cassert>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
using OpenRCT2::RCT12::TD46MazeElement;
|
||||
using OpenRCT2::RCT12::TD46Version;
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
#include <mutex>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
|
||||
namespace OpenRCT2::RCT2
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <functional>
|
||||
|
||||
using OpenRCT2::RCT12::TD46MazeElementType;
|
||||
using OpenRCT2::SawyerCoding::SawyerChunkWriter;
|
||||
|
||||
namespace OpenRCT2::RCT2
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ using namespace OpenRCT2;
|
||||
|
||||
using OpenRCT2::RCT12::TD46MazeElement;
|
||||
using OpenRCT2::RCT12::TD46Version;
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
|
||||
namespace OpenRCT2::RCT2
|
||||
{
|
||||
|
||||
@@ -11,11 +11,13 @@
|
||||
|
||||
#include "SawyerChunkReader.h"
|
||||
|
||||
namespace OpenRCT2
|
||||
#include <utility>
|
||||
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
SawyerChunk::SawyerChunk(SawyerCoding::ChunkEncoding encoding, MemoryStream&& data)
|
||||
SawyerChunk::SawyerChunk(ChunkEncoding encoding, MemoryStream&& data)
|
||||
: _data(std::move(data))
|
||||
, _encoding(encoding)
|
||||
{
|
||||
}
|
||||
} // namespace OpenRCT2
|
||||
} // namespace OpenRCT2::SawyerCoding
|
||||
|
||||
@@ -13,29 +13,26 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OpenRCT2
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
namespace SawyerCoding
|
||||
/**
|
||||
* The type of encoding / compression for a sawyer encoded chunk.
|
||||
*/
|
||||
enum class ChunkEncoding : uint8_t
|
||||
{
|
||||
/**
|
||||
* The type of encoding / compression for a sawyer encoded chunk.
|
||||
*/
|
||||
enum class ChunkEncoding : uint8_t
|
||||
{
|
||||
none,
|
||||
rle,
|
||||
rleCompressed,
|
||||
rotate,
|
||||
};
|
||||
none,
|
||||
rle,
|
||||
rleCompressed,
|
||||
rotate,
|
||||
};
|
||||
#pragma pack(push, 1)
|
||||
struct ChunkHeader
|
||||
{
|
||||
ChunkEncoding encoding;
|
||||
uint32_t length;
|
||||
};
|
||||
static_assert(sizeof(ChunkHeader) == 5);
|
||||
struct ChunkHeader
|
||||
{
|
||||
ChunkEncoding encoding;
|
||||
uint32_t length;
|
||||
};
|
||||
static_assert(sizeof(ChunkHeader) == 5);
|
||||
#pragma pack(pop)
|
||||
} // namespace SawyerCoding
|
||||
|
||||
/**
|
||||
* Represents a sawyer encoded chunk.
|
||||
@@ -44,7 +41,7 @@ namespace OpenRCT2
|
||||
{
|
||||
private:
|
||||
OpenRCT2::MemoryStream _data;
|
||||
SawyerCoding::ChunkEncoding _encoding = SawyerCoding::ChunkEncoding::none;
|
||||
ChunkEncoding _encoding = ChunkEncoding::none;
|
||||
|
||||
public:
|
||||
const void* GetData() const
|
||||
@@ -55,11 +52,11 @@ namespace OpenRCT2
|
||||
{
|
||||
return _data.GetLength();
|
||||
}
|
||||
SawyerCoding::ChunkEncoding GetEncoding() const
|
||||
ChunkEncoding GetEncoding() const
|
||||
{
|
||||
return _encoding;
|
||||
}
|
||||
|
||||
SawyerChunk(SawyerCoding::ChunkEncoding encoding, OpenRCT2::MemoryStream&& data);
|
||||
SawyerChunk(ChunkEncoding encoding, OpenRCT2::MemoryStream&& data);
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
} // namespace OpenRCT2::SawyerCoding
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
#include "../core/MemoryStream.h"
|
||||
#include "../core/Numerics.hpp"
|
||||
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
|
||||
namespace OpenRCT2
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
// Allow chunks to be uncompressed to a maximum of 16 MiB
|
||||
constexpr size_t kMaxUncompressedChunkSize = 16 * 1024 * 1024;
|
||||
@@ -289,4 +287,4 @@ namespace OpenRCT2
|
||||
|
||||
return buf;
|
||||
}
|
||||
} // namespace OpenRCT2
|
||||
} // namespace OpenRCT2::SawyerCoding
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
namespace OpenRCT2
|
||||
{
|
||||
struct IStream;
|
||||
}
|
||||
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
class SawyerChunkException : public IOException
|
||||
{
|
||||
public:
|
||||
@@ -86,4 +89,4 @@ namespace OpenRCT2
|
||||
return result;
|
||||
}
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
} // namespace OpenRCT2::SawyerCoding
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
#include "../core/Numerics.hpp"
|
||||
#include "../sawyer_coding/SawyerCoding.h"
|
||||
|
||||
using namespace OpenRCT2::SawyerCoding;
|
||||
|
||||
namespace OpenRCT2
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
// Maximum buffer size to store compressed data, maximum of 16 MiB
|
||||
constexpr size_t MAX_COMPRESSED_CHUNK_SIZE = 16 * 1024 * 1024;
|
||||
@@ -32,12 +30,12 @@ namespace OpenRCT2
|
||||
|
||||
void SawyerChunkWriter::WriteChunk(const void* src, size_t length, ChunkEncoding encoding)
|
||||
{
|
||||
SawyerCoding::ChunkHeader header;
|
||||
ChunkHeader header;
|
||||
header.encoding = encoding;
|
||||
header.length = static_cast<uint32_t>(length);
|
||||
|
||||
auto data = std::make_unique<uint8_t[]>(MAX_COMPRESSED_CHUNK_SIZE);
|
||||
size_t dataLength = SawyerCoding::WriteChunkBuffer(data.get(), static_cast<const uint8_t*>(src), header);
|
||||
size_t dataLength = WriteChunkBuffer(data.get(), static_cast<const uint8_t*>(src), header);
|
||||
|
||||
_stream->Write(data.get(), dataLength);
|
||||
}
|
||||
@@ -111,4 +109,4 @@ namespace OpenRCT2
|
||||
_stream->Write(data.get(), dataLength);
|
||||
_stream->WriteValue<uint32_t>(checksum);
|
||||
}
|
||||
} // namespace OpenRCT2
|
||||
} // namespace OpenRCT2::SawyerCoding
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
namespace OpenRCT2
|
||||
{
|
||||
struct IStream;
|
||||
}
|
||||
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
/**
|
||||
* Writes sawyer encoding chunks to a data stream. This can be used to write
|
||||
* SC6 and SV6 files.
|
||||
@@ -39,7 +42,7 @@ namespace OpenRCT2
|
||||
* @param src The source buffer.
|
||||
* @param length The size of the source buffer.
|
||||
*/
|
||||
void WriteChunk(const void* src, size_t length, SawyerCoding::ChunkEncoding encoding);
|
||||
void WriteChunk(const void* src, size_t length, ChunkEncoding encoding);
|
||||
|
||||
/**
|
||||
* Writes a track chunk to the stream containing the given buffer.
|
||||
@@ -52,9 +55,9 @@ namespace OpenRCT2
|
||||
* Writes a chunk to the stream containing the given type.
|
||||
*/
|
||||
template<typename T>
|
||||
void WriteChunk(const T* src, SawyerCoding::ChunkEncoding encoding)
|
||||
void WriteChunk(const T* src, ChunkEncoding encoding)
|
||||
{
|
||||
WriteChunk(src, sizeof(T), encoding);
|
||||
}
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
} // namespace OpenRCT2::SawyerCoding
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace OpenRCT2
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
// TODO: make enum class in SawyerCoding namespace
|
||||
enum
|
||||
@@ -29,10 +29,7 @@ namespace OpenRCT2
|
||||
FILE_TYPE_SV4 = (1 << 2),
|
||||
FILE_TYPE_SC4 = (2 << 2)
|
||||
};
|
||||
} // namespace OpenRCT2
|
||||
|
||||
namespace OpenRCT2::SawyerCoding
|
||||
{
|
||||
uint32_t CalculateChecksum(const uint8_t* buffer, size_t length);
|
||||
size_t WriteChunkBuffer(uint8_t* dst_file, const uint8_t* src_buffer, ChunkHeader chunkHeader);
|
||||
size_t DecodeSV4(const uint8_t* src, uint8_t* dst, size_t length, size_t bufferLength);
|
||||
|
||||
Reference in New Issue
Block a user