From d6499bfeb059c0f257780d5caaafaa1259581080 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Mon, 15 Jan 2024 16:48:09 -0800 Subject: [PATCH] Don't create default key frame for all properties. --- common/lc_objectproperty.cpp | 22 ++++++++++++++-------- common/lc_objectproperty.h | 22 ++-------------------- common/piece.cpp | 7 ++----- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/common/lc_objectproperty.cpp b/common/lc_objectproperty.cpp index 22554ae6..d192185b 100644 --- a/common/lc_objectproperty.cpp +++ b/common/lc_objectproperty.cpp @@ -5,7 +5,7 @@ #define LC_OBJECT_PROPERTY(T) \ template void lcObjectProperty::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const; \ template void lcObjectProperty::LoadKeysLDraw(QTextStream& Stream); \ - template const T& lcObjectProperty::CalculateKey(lcStep Step) const; \ + template void lcObjectProperty::Update(lcStep Step); \ template void lcObjectProperty::ChangeKey(const T& Value, lcStep Step, bool AddKey); \ template void lcObjectProperty::InsertTime(lcStep Start, lcStep Time); \ template void lcObjectProperty::RemoveTime(lcStep Start, lcStep Time); \ @@ -87,8 +87,11 @@ void lcObjectProperty::LoadKeysLDraw(QTextStream& Stream) } template -const T& lcObjectProperty::CalculateKey(lcStep Step) const +void lcObjectProperty::Update(lcStep Step) { + if (mKeys.empty()) + return; + const lcObjectPropertyKey* PreviousKey = &mKeys[0]; for (const lcObjectPropertyKey& Key : mKeys) @@ -99,12 +102,19 @@ const T& lcObjectProperty::CalculateKey(lcStep Step) const PreviousKey = &Key; } - return PreviousKey->Value; + mValue = PreviousKey->Value; } template void lcObjectProperty::ChangeKey(const T& Value, lcStep Step, bool AddKey) { + if (!AddKey && mKeys.empty()) + { + mValue = Value; + + return; + } + for (typename std::vector>::iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end(); KeyIt++) { if (KeyIt->Step < Step) @@ -187,9 +197,6 @@ void lcObjectProperty::RemoveTime(lcStep Start, lcStep Time) template bool lcObjectProperty::HasKeyFrame(lcStep Time) const { - if (mKeys.size() <= 1) - return false; - for (typename std::vector>::const_iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end(); KeyIt++) { if (KeyIt->Step == Time) @@ -204,7 +211,7 @@ bool lcObjectProperty::HasKeyFrame(lcStep Time) const template void lcObjectProperty::Save(QTextStream& Stream, const char* ObjectName, const char* VariableName) const { - if (GetSize() == 1) + if (mKeys.empty()) { Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << ' '; @@ -222,7 +229,6 @@ bool lcObjectProperty::Load(QTextStream& Stream, const QString& Token, const if (Token == VariableName) { lcObjectPropertyLoadValue(Stream, mValue); - ChangeKey(mValue, 1, true); return true; } diff --git a/common/lc_objectproperty.h b/common/lc_objectproperty.h index 8caa02d4..3c70ef0d 100644 --- a/common/lc_objectproperty.h +++ b/common/lc_objectproperty.h @@ -64,7 +64,6 @@ public: explicit lcObjectProperty(const T& DefaultValue) : mValue(DefaultValue) { - ChangeKey(mValue, 1, true); } operator const T& () const @@ -72,33 +71,18 @@ public: return mValue; } - int GetSize() const - { - return static_cast(mKeys.size()); - } - - bool IsEmpty() const - { - return mKeys.empty(); - } - - void Update(lcStep Step) - { - mValue = CalculateKey(Step); - } - void Reset() { mKeys.clear(); - ChangeKey(mValue, 1, true); } void Reset(const T& Value) { mValue = Value; - Reset(); + mKeys.clear(); } + void Update(lcStep Step); void ChangeKey(const T& Value, lcStep Step, bool AddKey); void InsertTime(lcStep Start, lcStep Time); void RemoveTime(lcStep Start, lcStep Time); @@ -110,8 +94,6 @@ public: void LoadKeysLDraw(QTextStream& Stream); protected: - const T& CalculateKey(lcStep Step) const; - T mValue; std::vector> mKeys; }; diff --git a/common/piece.cpp b/common/piece.cpp index 775033b5..cd4eb674 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -118,11 +118,8 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const Stream << LineEnding; } - if (mPosition.GetSize() > 1) - mPosition.SaveKeysLDraw(Stream, "PIECE", "POSITION"); - - if (mRotation.GetSize() > 1) - mRotation.SaveKeysLDraw(Stream, "PIECE", "ROTATION"); + mPosition.SaveKeysLDraw(Stream, "PIECE", "POSITION"); + mRotation.SaveKeysLDraw(Stream, "PIECE", "ROTATION"); Stream << "1 " << mColorCode << ' ';