Don't create default key frame for all properties.

This commit is contained in:
Leonardo Zide 2024-01-15 16:48:09 -08:00
parent cba4dfb468
commit d6499bfeb0
3 changed files with 18 additions and 33 deletions

View file

@ -5,7 +5,7 @@
#define LC_OBJECT_PROPERTY(T) \ #define LC_OBJECT_PROPERTY(T) \
template void lcObjectProperty<T>::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const; \ template void lcObjectProperty<T>::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const; \
template void lcObjectProperty<T>::LoadKeysLDraw(QTextStream& Stream); \ template void lcObjectProperty<T>::LoadKeysLDraw(QTextStream& Stream); \
template const T& lcObjectProperty<T>::CalculateKey(lcStep Step) const; \ template void lcObjectProperty<T>::Update(lcStep Step); \
template void lcObjectProperty<T>::ChangeKey(const T& Value, lcStep Step, bool AddKey); \ template void lcObjectProperty<T>::ChangeKey(const T& Value, lcStep Step, bool AddKey); \
template void lcObjectProperty<T>::InsertTime(lcStep Start, lcStep Time); \ template void lcObjectProperty<T>::InsertTime(lcStep Start, lcStep Time); \
template void lcObjectProperty<T>::RemoveTime(lcStep Start, lcStep Time); \ template void lcObjectProperty<T>::RemoveTime(lcStep Start, lcStep Time); \
@ -87,8 +87,11 @@ void lcObjectProperty<T>::LoadKeysLDraw(QTextStream& Stream)
} }
template<typename T> template<typename T>
const T& lcObjectProperty<T>::CalculateKey(lcStep Step) const void lcObjectProperty<T>::Update(lcStep Step)
{ {
if (mKeys.empty())
return;
const lcObjectPropertyKey<T>* PreviousKey = &mKeys[0]; const lcObjectPropertyKey<T>* PreviousKey = &mKeys[0];
for (const lcObjectPropertyKey<T>& Key : mKeys) for (const lcObjectPropertyKey<T>& Key : mKeys)
@ -99,12 +102,19 @@ const T& lcObjectProperty<T>::CalculateKey(lcStep Step) const
PreviousKey = &Key; PreviousKey = &Key;
} }
return PreviousKey->Value; mValue = PreviousKey->Value;
} }
template<typename T> template<typename T>
void lcObjectProperty<T>::ChangeKey(const T& Value, lcStep Step, bool AddKey) void lcObjectProperty<T>::ChangeKey(const T& Value, lcStep Step, bool AddKey)
{ {
if (!AddKey && mKeys.empty())
{
mValue = Value;
return;
}
for (typename std::vector<lcObjectPropertyKey<T>>::iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end(); KeyIt++) for (typename std::vector<lcObjectPropertyKey<T>>::iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end(); KeyIt++)
{ {
if (KeyIt->Step < Step) if (KeyIt->Step < Step)
@ -187,9 +197,6 @@ void lcObjectProperty<T>::RemoveTime(lcStep Start, lcStep Time)
template<typename T> template<typename T>
bool lcObjectProperty<T>::HasKeyFrame(lcStep Time) const bool lcObjectProperty<T>::HasKeyFrame(lcStep Time) const
{ {
if (mKeys.size() <= 1)
return false;
for (typename std::vector<lcObjectPropertyKey<T>>::const_iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end(); KeyIt++) for (typename std::vector<lcObjectPropertyKey<T>>::const_iterator KeyIt = mKeys.begin(); KeyIt != mKeys.end(); KeyIt++)
{ {
if (KeyIt->Step == Time) if (KeyIt->Step == Time)
@ -204,7 +211,7 @@ bool lcObjectProperty<T>::HasKeyFrame(lcStep Time) const
template<typename T> template<typename T>
void lcObjectProperty<T>::Save(QTextStream& Stream, const char* ObjectName, const char* VariableName) const void lcObjectProperty<T>::Save(QTextStream& Stream, const char* ObjectName, const char* VariableName) const
{ {
if (GetSize() == 1) if (mKeys.empty())
{ {
Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << ' '; Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << ' ';
@ -222,7 +229,6 @@ bool lcObjectProperty<T>::Load(QTextStream& Stream, const QString& Token, const
if (Token == VariableName) if (Token == VariableName)
{ {
lcObjectPropertyLoadValue(Stream, mValue); lcObjectPropertyLoadValue(Stream, mValue);
ChangeKey(mValue, 1, true);
return true; return true;
} }

View file

@ -64,7 +64,6 @@ public:
explicit lcObjectProperty(const T& DefaultValue) explicit lcObjectProperty(const T& DefaultValue)
: mValue(DefaultValue) : mValue(DefaultValue)
{ {
ChangeKey(mValue, 1, true);
} }
operator const T& () const operator const T& () const
@ -72,33 +71,18 @@ public:
return mValue; return mValue;
} }
int GetSize() const
{
return static_cast<int>(mKeys.size());
}
bool IsEmpty() const
{
return mKeys.empty();
}
void Update(lcStep Step)
{
mValue = CalculateKey(Step);
}
void Reset() void Reset()
{ {
mKeys.clear(); mKeys.clear();
ChangeKey(mValue, 1, true);
} }
void Reset(const T& Value) void Reset(const T& Value)
{ {
mValue = Value; mValue = Value;
Reset(); mKeys.clear();
} }
void Update(lcStep Step);
void ChangeKey(const T& Value, lcStep Step, bool AddKey); void ChangeKey(const T& Value, lcStep Step, bool AddKey);
void InsertTime(lcStep Start, lcStep Time); void InsertTime(lcStep Start, lcStep Time);
void RemoveTime(lcStep Start, lcStep Time); void RemoveTime(lcStep Start, lcStep Time);
@ -110,8 +94,6 @@ public:
void LoadKeysLDraw(QTextStream& Stream); void LoadKeysLDraw(QTextStream& Stream);
protected: protected:
const T& CalculateKey(lcStep Step) const;
T mValue; T mValue;
std::vector<lcObjectPropertyKey<T>> mKeys; std::vector<lcObjectPropertyKey<T>> mKeys;
}; };

View file

@ -118,11 +118,8 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
Stream << LineEnding; Stream << LineEnding;
} }
if (mPosition.GetSize() > 1) mPosition.SaveKeysLDraw(Stream, "PIECE", "POSITION");
mPosition.SaveKeysLDraw(Stream, "PIECE", "POSITION"); mRotation.SaveKeysLDraw(Stream, "PIECE", "ROTATION");
if (mRotation.GetSize() > 1)
mRotation.SaveKeysLDraw(Stream, "PIECE", "ROTATION");
Stream << "1 " << mColorCode << ' '; Stream << "1 " << mColorCode << ' ';