diff options
author | Antti Määttä <antti.maatta@qt.io> | 2019-06-14 14:49:34 +0300 |
---|---|---|
committer | Antti Määttä <antti.maatta@qt.io> | 2019-06-17 10:37:40 +0300 |
commit | 3701e1641213480228dff268b4a8b7fcb46c5213 (patch) | |
tree | b08cfe59f8e02d62c905084fb82526b68567f26d | |
parent | e5dbab5c14fa871b22ae63629ca75032c87836a1 (diff) |
Fix eyeball using setAttribute
Do not create dynamic property for the eyeball, but use the explicit set
flag instead, which is also used by the slide system.
Task-number: QT3DS-3655
Change-Id: I9390c8a9b8b20a55596b948d394a74aa66da98c6
Reviewed-by: Jari Karppinen <jari.karppinen@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r-- | src/runtime/Qt3DSElementSystem.cpp | 48 | ||||
-rw-r--r-- | src/runtime/Qt3DSElementSystem.h | 3 | ||||
-rw-r--r-- | src/runtime/Qt3DSQmlElementHelper.cpp | 28 | ||||
-rw-r--r-- | src/runtime/Qt3DSQmlElementHelper.h | 3 | ||||
-rw-r--r-- | src/runtime/Qt3DSQmlEngine.cpp | 4 |
5 files changed, 47 insertions, 39 deletions
diff --git a/src/runtime/Qt3DSElementSystem.cpp b/src/runtime/Qt3DSElementSystem.cpp index d8e1833..f87f4fd 100644 --- a/src/runtime/Qt3DSElementSystem.cpp +++ b/src/runtime/Qt3DSElementSystem.cpp @@ -637,36 +637,42 @@ void SElement::SetAttribute(const Q3DStudio::TAttributeHash inKey, const Q3DStudio::UVariant inValue) { Option<TPropertyDescAndValuePtr> existing = FindProperty(inKey); - if (existing.hasValue() == false) + if (existing.hasValue() == false) { + if (Q3DStudio::ATTRIBUTE_EYEBALL == inKey) + SetFlag(Q3DStudio::ELEMENTFLAG_EXPLICITACTIVE, inValue.m_INT32 ? true : false); return; + } SetAttribute(*existing, inValue); } -void SElement::SetAttribute(TPropertyDescAndValuePtr inKey, const Q3DStudio::UVariant inValue) +void SElement::SetAttribute(TPropertyDescAndValuePtr inKey, const Q3DStudio::UVariant inValue, + bool forceSet) { Q3DStudio::EAttributeType theType = inKey.first.m_Type; Q3DStudio::UVariant *currentValue = inKey.second; QT3DSU32 attHash = inKey.first.GetNameHash(); - switch (theType) { - case Q3DStudio::ATTRIBUTETYPE_FLOAT: // Early return - if (fabs(currentValue->m_FLOAT - inValue.m_FLOAT) < SmallestDifference()) - return; - break; - case Q3DStudio::ATTRIBUTETYPE_FLOAT3: // Early return - if (fabs(currentValue->m_FLOAT3[0] - inValue.m_FLOAT3[0]) < SmallestDifference() - && fabs(currentValue->m_FLOAT3[1] - inValue.m_FLOAT3[1]) < SmallestDifference() - && fabs(currentValue->m_FLOAT3[2] - inValue.m_FLOAT3[2]) < SmallestDifference()) { - return; + if (!forceSet) { + switch (theType) { + case Q3DStudio::ATTRIBUTETYPE_FLOAT: // Early return + if (fabs(currentValue->m_FLOAT - inValue.m_FLOAT) < SmallestDifference()) + return; + break; + case Q3DStudio::ATTRIBUTETYPE_FLOAT3: // Early return + if (fabs(currentValue->m_FLOAT3[0] - inValue.m_FLOAT3[0]) < SmallestDifference() + && fabs(currentValue->m_FLOAT3[1] - inValue.m_FLOAT3[1]) < SmallestDifference() + && fabs(currentValue->m_FLOAT3[2] - inValue.m_FLOAT3[2]) < SmallestDifference()) { + return; + } + break; + case Q3DStudio::ATTRIBUTETYPE_STRING: + if (currentValue->m_StringHandle == inValue.m_StringHandle) + return; + break; + default: // Early return + if (Q3DStudio::ATTRIBUTE_EYEBALL != attHash && currentValue->m_INT32 == inValue.m_INT32) + return; + break; } - break; - case Q3DStudio::ATTRIBUTETYPE_STRING: - if (currentValue->m_StringHandle == inValue.m_StringHandle) - return; - break; - default: // Early return - if (currentValue->m_INT32 == inValue.m_INT32) - return; - break; } *currentValue = inValue; diff --git a/src/runtime/Qt3DSElementSystem.h b/src/runtime/Qt3DSElementSystem.h index 12ebebd..6e61a02 100644 --- a/src/runtime/Qt3DSElementSystem.h +++ b/src/runtime/Qt3DSElementSystem.h @@ -322,7 +322,8 @@ namespace runtime { void SetAttribute(const Q3DStudio::TAttributeHash inKey, const Q3DStudio::UVariant inValue); // Triggers updating various subcomponents without requiring a new property lookup. - void SetAttribute(TPropertyDescAndValuePtr inKey, const Q3DStudio::UVariant inNewValue); + void SetAttribute(TPropertyDescAndValuePtr inKey, const Q3DStudio::UVariant inNewValue, + bool forceSet = false); // Q3DStudio::CHash::HashAttribute Option<QT3DSU32> FindPropertyIndex(QT3DSU32 inNameHash) const; diff --git a/src/runtime/Qt3DSQmlElementHelper.cpp b/src/runtime/Qt3DSQmlElementHelper.cpp index 9b58a73..81649f2 100644 --- a/src/runtime/Qt3DSQmlElementHelper.cpp +++ b/src/runtime/Qt3DSQmlElementHelper.cpp @@ -150,10 +150,11 @@ TElement *CQmlElementHelper::GetElement(qt3ds::runtime::IApplication &inApplicat } bool CQmlElementHelper::SetAttribute(TElement *theElement, const char *theAttName, - const void *value, bool inDelay) + const void *value) { SAttributeKey theAttributeKey; theAttributeKey.m_Hash = CHash::HashAttribute(theAttName); + bool force = false; // Early out for our single 'read only' attribute if (ATTRIBUTE_URI == theAttributeKey.m_Hash) { @@ -165,7 +166,8 @@ bool CQmlElementHelper::SetAttribute(TElement *theElement, const char *theAttNam Option<qt3ds::runtime::element::TPropertyDescAndValuePtr> thePropertyInfo = theElement->FindProperty(theAttributeKey.m_Hash); - if (!thePropertyInfo.hasValue()) { + // Do not create property for eyeball, it uses the explicit activity flag + if (!thePropertyInfo.hasValue() && theAttributeKey.m_Hash != Q3DStudio::ATTRIBUTE_EYEBALL) { // if not search in the dynamic properties thePropertyInfo = theElement->FindDynamicProperty(theAttributeKey.m_Hash); if (!thePropertyInfo.hasValue()) { @@ -178,10 +180,15 @@ bool CQmlElementHelper::SetAttribute(TElement *theElement, const char *theAttNam theElement->GetBelongedPresentation()->GetApplication().GetMetaData(); thePropertyInfo = theElemAllocator.CreateDynamicProperty( theMetaData, *theElement, theStringTable.RegisterStr(theAttName)); + force = true; } } - if (thePropertyInfo.hasValue()) { + if (theAttributeKey.m_Hash == Q3DStudio::ATTRIBUTE_EYEBALL) { + UVariant theNewValue; + theNewValue.m_INT32 = *(INT32 *)value; + theElement->SetAttribute(theAttributeKey.m_Hash, theNewValue); + } else if (thePropertyInfo.hasValue()) { UVariant theNewValue; QString name(thePropertyInfo->first.m_Name.c_str()); EAttributeType theAttributeType = thePropertyInfo->first.m_Type; @@ -239,15 +246,7 @@ bool CQmlElementHelper::SetAttribute(TElement *theElement, const char *theAttNam break; } - if (inDelay) { - UVariant arg1; - arg1.m_INT32 = theAttributeKey.m_Hash; - theElement->GetBelongedPresentation()->FireCommand( - COMMAND_SETPROPERTY, theElement, &arg1, &theNewValue, ATTRIBUTETYPE_HASH, - theAttributeType); - } else { - theElement->SetAttribute(*thePropertyInfo, theNewValue); - } + theElement->SetAttribute(*thePropertyInfo, theNewValue, force); } else { return false; } @@ -266,7 +265,10 @@ bool CQmlElementHelper::GetAttribute(TElement *inElement, const char *inAttribut if (!thePropertyInfo.hasValue()) thePropertyInfo = inElement->FindDynamicProperty(theAttributeKey.m_Hash); - if (thePropertyInfo.hasValue()) { + if (theAttributeKey.m_Hash == Q3DStudio::ATTRIBUTE_EYEBALL) { + INT32 val = inElement->IsExplicitActive() ? 1 : 0; + *(INT32 *)value = val; + } else if (thePropertyInfo.hasValue()) { UVariant *theValuePtr = thePropertyInfo->second; EAttributeType theAttributeType = thePropertyInfo->first.m_Type; switch (theAttributeType) { diff --git a/src/runtime/Qt3DSQmlElementHelper.h b/src/runtime/Qt3DSQmlElementHelper.h index ec36c8e..c7b2b08 100644 --- a/src/runtime/Qt3DSQmlElementHelper.h +++ b/src/runtime/Qt3DSQmlElementHelper.h @@ -48,8 +48,7 @@ public: IPresentation *inDefaultPresentation, const char *inPath, TElement *inStartElement = NULL); - static bool SetAttribute(TElement *inElement, const char *inAttribute, const void *value, - bool inDelay); + static bool SetAttribute(TElement *inElement, const char *inAttribute, const void *value); static bool GetAttribute(TElement *inElement, const char *inAttribute, void *value); }; } diff --git a/src/runtime/Qt3DSQmlEngine.cpp b/src/runtime/Qt3DSQmlEngine.cpp index 9fe75e0..0f5a2f5 100644 --- a/src/runtime/Qt3DSQmlEngine.cpp +++ b/src/runtime/Qt3DSQmlEngine.cpp @@ -601,7 +601,7 @@ void CQmlEngineImpl::SetAttribute(TElement *target, const char *attName, const c { QML_ENGINE_MULTITHREAD_PROTECT_METHOD; if (target) { - bool success = CQmlElementHelper::SetAttribute(target, attName, value, false); + bool success = CQmlElementHelper::SetAttribute(target, attName, value); if (!success) { qCCritical(qt3ds::INVALID_OPERATION) << "CQmlEngineImpl::SetAttribute: " @@ -617,7 +617,7 @@ void CQmlEngineImpl::SetAttribute(const char *element, const char *attName, cons TElement *theTarget = getTarget(element); if (theTarget) { - bool success = CQmlElementHelper::SetAttribute(theTarget, attName, value, false); + bool success = CQmlElementHelper::SetAttribute(theTarget, attName, value); if (!success) { qCCritical(qt3ds::INVALID_OPERATION) << "CQmlEngineImpl::SetAttribute: " |