1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Refactoring of serialization versioning handling

- Removed 'version' field from serialize() method
- Handler classes - Binary(De)Serializer now have 'version' field
- Serialization versioning now uses named enum

Save compatibility with 1.4.X saves should be intact
This commit is contained in:
Ivan Savenko
2024-01-20 20:34:51 +02:00
parent 6b760089a4
commit 0c07384293
129 changed files with 498 additions and 473 deletions

View File

@@ -12,7 +12,7 @@
VCMI_LIB_NAMESPACE_BEGIN
CLoadFile::CLoadFile(const boost::filesystem::path & fname, int minimalVersion)
CLoadFile::CLoadFile(const boost::filesystem::path & fname, ESerializationVersion minimalVersion)
: serializer(this)
{
openNextFile(fname, minimalVersion);
@@ -27,10 +27,10 @@ int CLoadFile::read(void * data, unsigned size)
return size;
}
void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalVersion)
void CLoadFile::openNextFile(const boost::filesystem::path & fname, ESerializationVersion minimalVersion)
{
assert(!serializer.reverseEndianess);
assert(minimalVersion <= SERIALIZATION_VERSION);
assert(minimalVersion <= ESerializationVersion::CURRENT);
try
{
@@ -47,19 +47,19 @@ void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalV
if(std::memcmp(buffer, "VCMI", 4) != 0)
THROW_FORMAT("Error: not a VCMI file(%s)!", fName);
serializer & serializer.fileVersion;
if(serializer.fileVersion < minimalVersion)
serializer & serializer.version;
if(serializer.version < minimalVersion)
THROW_FORMAT("Error: too old file format (%s)!", fName);
if(serializer.fileVersion > SERIALIZATION_VERSION)
if(serializer.version > ESerializationVersion::CURRENT)
{
logGlobal->warn("Warning format version mismatch: found %d when current is %d! (file %s)\n", serializer.fileVersion, SERIALIZATION_VERSION , fName);
logGlobal->warn("Warning format version mismatch: found %d when current is %d! (file %s)\n", vstd::to_underlying(serializer.version), vstd::to_underlying(ESerializationVersion::CURRENT), fName);
auto * versionptr = reinterpret_cast<char *>(&serializer.fileVersion);
auto * versionptr = reinterpret_cast<char *>(&serializer.version);
std::reverse(versionptr, versionptr + 4);
logGlobal->warn("Version number reversed is %x, checking...", serializer.fileVersion);
logGlobal->warn("Version number reversed is %x, checking...", vstd::to_underlying(serializer.version));
if(serializer.fileVersion == SERIALIZATION_VERSION)
if(serializer.version == ESerializationVersion::CURRENT)
{
logGlobal->warn("%s seems to have different endianness! Entering reversing mode.", fname.string());
serializer.reverseEndianess = true;
@@ -86,7 +86,7 @@ void CLoadFile::clear()
{
sfile = nullptr;
fName.clear();
serializer.fileVersion = 0;
serializer.version = ESerializationVersion::NONE;
}
void CLoadFile::checkMagicBytes(const std::string &text)