From ec2a9bce870799e6934d596219055dea4cfbf8bd Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 23 Dec 2023 12:50:54 -0800 Subject: [PATCH] Fixed serializing area light grid. --- common/object.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/common/object.cpp b/common/object.cpp index 4eed9443..ec9611b3 100644 --- a/common/object.cpp +++ b/common/object.cpp @@ -28,7 +28,7 @@ lcObject::~lcObject() } template -static void SaveFloatValue(QTextStream& Stream, const T& Value) +static void SaveValue(QTextStream& Stream, const T& Value) { constexpr int Count = sizeof(T) / sizeof(float); @@ -36,8 +36,17 @@ static void SaveFloatValue(QTextStream& Stream, const T& Value) Stream << ((const float*)&Value)[ValueIndex] << ' '; } +template<> +void SaveValue(QTextStream& Stream, const lcVector2i& Value) +{ + constexpr int Count = sizeof(lcVector2i) / sizeof(int); + + for (int ValueIndex = 0; ValueIndex < Count; ValueIndex++) + Stream << ((const int*)&Value)[ValueIndex] << ' '; +} + template -static void LoadFloatValue(QTextStream& Stream, T& Value) +static void LoadValue(QTextStream& Stream, T& Value) { constexpr int Count = sizeof(T) / sizeof(float); @@ -45,6 +54,15 @@ static void LoadFloatValue(QTextStream& Stream, T& Value) Stream >> ((float*)&Value)[ValueIdx]; } +template<> +void LoadValue(QTextStream& Stream, lcVector2i& Value) +{ + constexpr int Count = sizeof(lcVector2i) / sizeof(int); + + for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++) + Stream >> ((int*)&Value)[ValueIdx]; +} + template void lcObjectKeyArray::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const { @@ -52,7 +70,7 @@ void lcObjectKeyArray::SaveKeysLDraw(QTextStream& Stream, const char* ObjectN { Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << "_KEY " << Key.Step << ' '; - SaveFloatValue(Stream, Key.Value); + SaveValue(Stream, Key.Value); Stream << QLatin1String("\r\n"); } @@ -180,7 +198,7 @@ void lcObject::SaveAttribute(QTextStream& Stream, const T& Variable, const lcObj { Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << ' '; - SaveFloatValue(Stream, Variable); + SaveValue(Stream, Variable); Stream << QLatin1String("\r\n"); } @@ -193,7 +211,7 @@ bool lcObject::LoadAttribute(QTextStream& Stream, const QString& Token, T& Varia { if (Token == VariableName) { - LoadFloatValue(Stream, Variable); + LoadValue(Stream, Variable); Keys.ChangeKey(Variable, 1, true); return true;