Skip to content

Commit

Permalink
Fixed bug mVertexRect doesn't be serialized.
Browse files Browse the repository at this point in the history
Fixed bug mVertexRect in GridMesh doesn't be serialized.
  • Loading branch information
hidefuku committed Apr 14, 2017
1 parent 2668012 commit 0b3ed1b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/core/Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -19,6 +20,7 @@ Deserializer::Deserializer(
, mLog()
, mValue()
, mMaxFileSize(aMaxFileSize)
, mVersion(aVersion)
, mGLDeviceInfo(aGLDeviceInfo)
, mReporter(aReporter)
, mRShiftCount(aRShiftCount)
Expand Down
5 changes: 5 additions & 0 deletions src/core/Deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QMatrix4x4>
#include <QPolygonF>
#include <QGL>
#include <QVersionNumber>
#include "XC.h"
#include "util/Segment2D.h"
#include "util/Easing.h"
Expand All @@ -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);
Expand Down Expand Up @@ -124,6 +128,7 @@ class Deserializer
QStringList mLog;
QString mValue;
size_t mMaxFileSize;
QVersionNumber mVersion;
gl::DeviceInfo mGLDeviceInfo;
util::IProgressReporter& mReporter;
int mRShiftCount;
Expand Down
25 changes: 25 additions & 0 deletions src/core/GridMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
7 changes: 5 additions & 2 deletions src/ctrl/ProjectLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace ctrl

ProjectLoader::ProjectLoader()
: mLog()
, mVersion()
{
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -144,6 +145,8 @@ bool ProjectLoader::readHeader(util::LEStreamReader& aIn)
return false;
}

mVersion = QVersionNumber(majorVersion, minorVersion);

// reserved
if (!aIn.skipZeroArea(16)) return false;

Expand Down
2 changes: 2 additions & 0 deletions src/ctrl/ProjectLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CTRL_PROJECTLOADER_H

#include <QStringList>
#include <QVersionNumber>
#include "util/StreamReader.h"
#include "util/IProgressReporter.h"
#include "gl/DeviceInfo.h"
Expand All @@ -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
Expand Down

0 comments on commit 0b3ed1b

Please sign in to comment.