Start new save format

This commit is contained in:
Ted John 2018-12-15 00:37:15 +00:00
parent e46a779c00
commit 7353225b7f
2 changed files with 101 additions and 0 deletions

59
src/openrct2/ParkFile.cpp Normal file
View File

@ -0,0 +1,59 @@
#include "ParkFile.h"
#include "Version.h"
using namespace OpenRCT2;
constexpr uint32_t PARK_FILE_MAGIC = 0x4B526550; // PARK
// Current version that is saved.
constexpr uint32_t PARK_FILE_CURRENT_VERSION = 0x0;
// The minimum version that is forwards compatible with the current version.
constexpr uint32_t PARK_FILE_MIN_VERSION = 0x0;
constexpr uint32_t COMPRESSION_NONE = 0;
constexpr uint32_t COMPRESSION_GZIP = 1;
namespace ParkFileChunkType
{
// clang-format off
constexpr uint32_t RESERVED_0 = 0x00;
constexpr uint32_t AUTHORING = 0x01;
constexpr uint32_t OBJECTS = 0x02;
constexpr uint32_t SCENARIO = 0x03;
constexpr uint32_t GENERAL = 0x04;
constexpr uint32_t INTERFACE = 0x05;
constexpr uint32_t CLIMATE = 0x06;
constexpr uint32_t PARK = 0x07;
constexpr uint32_t HISTORY = 0x08;
constexpr uint32_t INVENTIONS = 0x09;
constexpr uint32_t TILES = 0x0A;
constexpr uint32_t THINGS = 0x0B;
constexpr uint32_t RIDES = 0x0C;
constexpr uint32_t BANNERS = 0x0D;
constexpr uint32_t ANIMATIONS = 0x0E;
constexpr uint32_t STAFF = 0x0F;
constexpr uint32_t STRINGS = 0x10;
constexpr uint32_t EDITOR = 0x11;
constexpr uint32_t DERIVED = 0x12;
// clang-format on
}; // namespace ParkFileChunkType
void ParkFile::Save(const std::string_view& path)
{
_header = {};
_header.Magic = PARK_FILE_MAGIC;
_header.TargetVersion = PARK_FILE_CURRENT_VERSION;
_header.MinVersion = PARK_FILE_MIN_VERSION;
_header.Compression = COMPRESSION_NONE;
}
void ParkFile::WriteHeader(std::ostream& stream, const Header& header, const std::vector<ChunkEntry>& chunks)
{
stream.seekp(0);
stream.write((const char*)&header, sizeof(header));
for (const auto& chunk : chunks)
{
stream.write((const char*)&chunk, sizeof(chunk));
}
}

42
src/openrct2/ParkFile.h Normal file
View File

@ -0,0 +1,42 @@
#include <cstdint>
#include <fstream>
#include <string_view>
#include <vector>
namespace OpenRCT2
{
class ParkFile
{
public:
void Save(const std::string_view& path);
private:
#pragma pack(push, 1)
struct Header
{
uint32_t Magic{};
uint32_t TargetVersion{};
uint32_t MinVersion{};
uint32_t NumChunks{};
uint64_t UncompressedSize{};
uint32_t Compression{};
uint8_t Sha1{};
};
struct ChunkEntry
{
uint32_t Id{};
uint64_t Offset{};
uint64_t Length{};
};
#pragma pack(pop)
Header _header;
std::vector<ChunkEntry> _chunks;
ChunkEntry _currentChunk;
void WriteHeader(std::ostream& stream, const Header& header, const std::vector<ChunkEntry>& chunks);
void BeginChunk(std::ostream& stream);
uint64_t EndChunk();
};
} // namespace OpenRCT2