diff --git a/src/common.pri b/src/common.pri index d6543680..6b53b816 100644 --- a/src/common.pri +++ b/src/common.pri @@ -14,10 +14,10 @@ HEADERS += \ $$PWD/XCAssert.h DEFINES += "AE_MAJOR_VERSION=1" -DEFINES += "AE_MINOR_VERSION=2" +DEFINES += "AE_MINOR_VERSION=3" DEFINES += "AE_PROJECT_FORMAT_MAJOR_VERSION=0" -DEFINES += "AE_PROJECT_FORMAT_MINOR_VERSION=4" +DEFINES += "AE_PROJECT_FORMAT_MINOR_VERSION=5" DEFINES += "AE_PROJECT_FORMAT_OLDEST_MAJOR_VERSION=0" DEFINES += "AE_PROJECT_FORMAT_OLDEST_MINOR_VERSION=4" diff --git a/src/core/Deserializer.cpp b/src/core/Deserializer.cpp index cca6fc9f..69926fdd 100644 --- a/src/core/Deserializer.cpp +++ b/src/core/Deserializer.cpp @@ -9,6 +9,7 @@ Deserializer::Deserializer( util::LEStreamReader& aIn, IDSolverType& aSolver, size_t aMaxFileSize, + QVersionNumber aVersion, const gl::DeviceInfo& aGLDeviceInfo, util::IProgressReporter& aReporter, int aRShiftCount) @@ -19,6 +20,7 @@ Deserializer::Deserializer( , mLog() , mValue() , mMaxFileSize(aMaxFileSize) + , mVersion(aVersion) , mGLDeviceInfo(aGLDeviceInfo) , mReporter(aReporter) , mRShiftCount(aRShiftCount) diff --git a/src/core/Deserializer.h b/src/core/Deserializer.h index 8a8528b5..891a3c10 100644 --- a/src/core/Deserializer.h +++ b/src/core/Deserializer.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "XC.h" #include "util/Segment2D.h" #include "util/Easing.h" @@ -37,10 +38,13 @@ class Deserializer util::LEStreamReader& aIn, IDSolverType& aSolver, size_t aMaxFileSize, + QVersionNumber aVersion, const gl::DeviceInfo& aGLDeviceInfo, util::IProgressReporter& aRepoter, int aRShiftCount); + QVersionNumber version() const { return mVersion; } + void read(bool& aValue); void read(int& aValue); void read(float& aValue); @@ -124,6 +128,7 @@ class Deserializer QStringList mLog; QString mValue; size_t mMaxFileSize; + QVersionNumber mVersion; gl::DeviceInfo mGLDeviceInfo; util::IProgressReporter& mReporter; int mRShiftCount; diff --git a/src/core/GridMesh.cpp b/src/core/GridMesh.cpp index 91046d0e..068eadf7 100644 --- a/src/core/GridMesh.cpp +++ b/src/core/GridMesh.cpp @@ -547,6 +547,9 @@ bool GridMesh::serialize(Serializer& aOut) const aOut.write(XCMemBlock((uint8*)mHexaConnections.data(), connectSize)); } + // vertex rect + aOut.write(mVertexRect); + aOut.endBlock(pos); return !aOut.failure(); @@ -611,6 +614,28 @@ bool GridMesh::deserialize(Deserializer& aIn) return aIn.errored("failed to read connections"); } } + + // vertex rect + if (aIn.version() >= QVersionNumber(0, 5)) + { + aIn.read(mVertexRect); + } + else + { + // note: the bug on version 0.4 or lower. mVertexRect doesn't be serialized. + auto positions = mPositions.data(); + float l, t, r, b = 0.0f; + for (int i = 0; i < mVertexCount; ++i) + { + auto pos = positions[i]; + l = std::min(l, pos.x - 1); + t = std::min(t, pos.y - 1); + r = std::max(r, pos.x + 1); + b = std::max(b, pos.y + 1); + } + mVertexRect = QRect(l, t, r - l, b - t); + } + // initialize mesh buffer getMeshBuffer(); diff --git a/src/ctrl/ProjectLoader.cpp b/src/ctrl/ProjectLoader.cpp index 143cab2c..18d3bad5 100644 --- a/src/ctrl/ProjectLoader.cpp +++ b/src/ctrl/ProjectLoader.cpp @@ -8,6 +8,7 @@ namespace ctrl ProjectLoader::ProjectLoader() : mLog() + , mVersion() { } @@ -60,8 +61,8 @@ bool ProjectLoader::load( core::Deserializer::IDSolverType idSolver; core::Deserializer deserializer( - in, idSolver, maxFileSize, aGLDeviceInfo, - aReporter, rShiftCount); + in, idSolver, maxFileSize, mVersion, + aGLDeviceInfo, aReporter, rShiftCount); deserializer.reportCurrent(); // resources block @@ -144,6 +145,8 @@ bool ProjectLoader::readHeader(util::LEStreamReader& aIn) return false; } + mVersion = QVersionNumber(majorVersion, minorVersion); + // reserved if (!aIn.skipZeroArea(16)) return false; diff --git a/src/ctrl/ProjectLoader.h b/src/ctrl/ProjectLoader.h index cb709337..7aaeeb6c 100644 --- a/src/ctrl/ProjectLoader.h +++ b/src/ctrl/ProjectLoader.h @@ -2,6 +2,7 @@ #define CTRL_PROJECTLOADER_H #include +#include #include "util/StreamReader.h" #include "util/IProgressReporter.h" #include "gl/DeviceInfo.h" @@ -26,6 +27,7 @@ class ProjectLoader bool readHeader(util::LEStreamReader& aReader); bool readGlobalBlock(util::LEStreamReader& aReader, core::Project& aProject); QStringList mLog; + QVersionNumber mVersion; }; } // namespace ctrl