summaryrefslogtreecommitdiffstats
path: root/src/runtime/Qt3DSElementSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/Qt3DSElementSystem.cpp')
-rw-r--r--src/runtime/Qt3DSElementSystem.cpp167
1 files changed, 102 insertions, 65 deletions
diff --git a/src/runtime/Qt3DSElementSystem.cpp b/src/runtime/Qt3DSElementSystem.cpp
index 27bca95..3234e09 100644
--- a/src/runtime/Qt3DSElementSystem.cpp
+++ b/src/runtime/Qt3DSElementSystem.cpp
@@ -44,6 +44,8 @@
#include "foundation/IOStreams.h"
#include "foundation/Qt3DSIndexableLinkedList.h"
#include "Qt3DSAnimationSystem.h"
+#include "Qt3DSRenderRuntimeBindingImpl.h"
+#include "Qt3DSRenderGraphObject.h"
using namespace qt3ds::runtime::element;
using namespace qt3ds;
@@ -65,7 +67,7 @@ struct SPropertyDescSorter
{
bool operator()(const TPropertyDescAndValue &lhs, const TPropertyDescAndValue &rhs) const
{
- return strcmp(lhs.first.m_Name.c_str(), rhs.first.m_Name.c_str()) < 0;
+ return strcmp(lhs.first.name().c_str(), rhs.first.name().c_str()) < 0;
}
};
QT3DSU32 GetNumValueAllocations(const STypeDesc &inTypeDesc)
@@ -165,7 +167,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
GetIgnoredProperties();
const bool isImage = inType == m_StringTable.RegisterStr("Image");
for (QT3DSU32 idx = 0, end = inPropertyDescriptions.size(); idx < end; ++idx) {
- QT3DSU32 nameHash = inPropertyDescriptions[idx].first.GetNameHash();
+ QT3DSU32 nameHash = inPropertyDescriptions[idx].first.nameHash();
// Make image instances explicitly not participate in the timegraph. This way their
// default start/end time does not have impact into lifetimes of their parents.
// This fixes QT3DS-3669 where image default end time overrode parent endtime when
@@ -175,7 +177,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
participatesInTimeGraph = true;
}
if (eastl::find(m_IgnoredProperties.begin(), m_IgnoredProperties.end(),
- inPropertyDescriptions[idx].first.m_Name)
+ inPropertyDescriptions[idx].first.name())
== m_IgnoredProperties.end()) {
m_TempPropertyDescsAndValues.push_back(inPropertyDescriptions[idx]);
}
@@ -210,19 +212,11 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
SElement *retval = inIsComponent ? m_Components.construct(theTypeDesc, __FILE__, __LINE__)
: m_Elements.construct(theTypeDesc, __FILE__, __LINE__);
retval->m_BelongedPresentation = inPresentation;
- retval->m_Name = inName;
+ retval->setName(inName);
// children
- if (inParent) {
- retval->m_Parent = inParent;
- if (inParent->m_Child == NULL) {
- inParent->m_Child = retval;
- } else {
- SElement *lastChild = inParent->m_Child;
- while (lastChild->m_Sibling)
- lastChild = lastChild->m_Sibling;
- lastChild->m_Sibling = retval;
- }
- }
+ if (inParent)
+ retval->setParent(inParent);
+
while (FindElementByHandle(m_NextElementHandle)) {
++m_NextElementHandle;
if (!m_NextElementHandle)
@@ -264,25 +258,13 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
void ReleaseElement(SElement &inElement, bool inRecurse) override
{
if (inRecurse) {
- while (inElement.m_Child)
- ReleaseElement(*inElement.m_Child, true);
+ const auto children = inElement.children();
+ for (auto child : children)
+ ReleaseElement(*child, true);
}
// Trim out the element.
- if (inElement.m_Parent) {
- SElement *theParent = inElement.m_Parent;
- if (theParent->m_Child == &inElement)
- theParent->m_Child = inElement.m_Sibling;
- else {
- SElement *thePreviousChild = NULL;
- // Empty loop to find the previous child
- for (thePreviousChild = theParent->m_Child;
- thePreviousChild->m_Sibling != &inElement && thePreviousChild;
- thePreviousChild = thePreviousChild->m_Sibling) {
- }
- if (thePreviousChild)
- thePreviousChild->m_Sibling = inElement.m_Sibling;
- }
- }
+ if (inElement.GetParent())
+ inElement.GetParent()->removeChild(&inElement);
m_HandleToElements.erase(inElement.m_Handle);
@@ -369,7 +351,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
newProp = (SPropertyDesc *)m_AutoAllocator.allocate(allocSize, "SPropertyDesc",
__FILE__, __LINE__, 0);
- newProp->m_Name = inName;
+ newProp->setName(inName);
// convert to appropriate type
if (thePropertyType == Q3DStudio::ERuntimeDataModelDataTypeFloat) {
@@ -377,7 +359,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
element.m_TypeDescription->m_TypeName, theWorkSpaceString,
element.m_TypeDescription->m_SubtypeName);
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_FLOAT;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_FLOAT);
Q3DStudio::UVariant theValue;
theValue.m_FLOAT = value;
@@ -389,7 +371,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
qt3ds::QT3DSVec2 value = theMetaData.GetPropertyValueVector2(
element.m_TypeDescription->m_TypeName, theWorkSpaceString,
element.m_TypeDescription->m_SubtypeName);
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_FLOAT;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_FLOAT);
Q3DStudio::UVariant theVarValue;
theVarValue.m_FLOAT = value[extIndex];
@@ -404,7 +386,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
element.m_TypeDescription->m_SubtypeName);
if (separateProperties) {
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_FLOAT;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_FLOAT);
Q3DStudio::UVariant theVarValue;
theVarValue.m_FLOAT = value[extIndex];
@@ -412,7 +394,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
SPropertyDesc(theWorkSpaceString, Q3DStudio::ATTRIBUTETYPE_FLOAT),
theVarValue));
} else {
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_FLOAT3;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_FLOAT3);
Q3DStudio::UVariant theVarValue;
theVarValue.m_FLOAT3[0] = value[0];
@@ -429,7 +411,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
element.m_TypeDescription->m_TypeName, theWorkSpaceString,
element.m_TypeDescription->m_SubtypeName);
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_INT32;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_INT32);
Q3DStudio::UVariant theVarValue;
theVarValue.m_INT32 = value;
@@ -443,7 +425,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
element.m_TypeDescription->m_TypeName, theWorkSpaceString,
element.m_TypeDescription->m_SubtypeName);
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_BOOL;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_BOOL);
Q3DStudio::UVariant theVarValue;
theVarValue.m_INT32 = value;
@@ -456,7 +438,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
element.m_TypeDescription->m_TypeName, theWorkSpaceString,
element.m_TypeDescription->m_SubtypeName);
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_STRING;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_STRING);
CStringHandle theString = m_StringTable.GetHandle(theRuntimeStr->c_str());
Q3DStudio::UVariant theVarValue;
@@ -467,7 +449,7 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
theTypeDesc->m_DynamicProperties.push_back(*newProp);
} else {
- newProp->m_Type = Q3DStudio::ATTRIBUTETYPE_FLOAT;
+ newProp->setType(Q3DStudio::ATTRIBUTETYPE_FLOAT);
theTypeDesc->m_DynamicProperties.push_back(*newProp);
}
@@ -494,6 +476,19 @@ struct SElementAllocator : public qt3ds::runtime::IElementAllocator
return NULL;
}
+ SElement *FindElementById(CRegisteredString elementId) override
+ {
+ auto iter = m_HandleToElements.begin();
+ auto end = m_HandleToElements.end();
+ for (; iter != end; iter++) {
+ SElement *elem = iter->second;
+ auto *translator = static_cast<Qt3DSTranslator *>(elem->GetAssociation());
+ if (translator && translator->RenderObject().m_Id == elementId)
+ return elem;
+ }
+ return nullptr;
+ }
+
// Returns an element pointer that when added to the return value of load will be a valid
// element.
SElement *GetRemappedElementAddress(SElement *inElement) const override
@@ -539,7 +534,7 @@ bool STypeDesc::operator==(const STypeDesc &inOther) const
for (QT3DSU32 idx = 0, end = m_Properties.size(); idx < end; ++idx) {
const SPropertyDesc &lhs = m_Properties[idx];
const SPropertyDesc &rhs = inOther.m_Properties[idx];
- if (lhs.m_Name != rhs.m_Name || lhs.m_Type != rhs.m_Type)
+ if (lhs.name() != rhs.name() || lhs.type() != rhs.type())
return false;
}
return true;
@@ -551,7 +546,7 @@ Option<QT3DSU32> STypeDesc::FindProperty(QT3DSU32 inNameHash) const
{
for (QT3DSU32 idx = 0, end = m_Properties.size(); idx < end; ++idx) {
const SPropertyDesc &theDesc = m_Properties[idx];
- if (Q3DStudio::CHash::HashAttribute(theDesc.m_Name) == inNameHash)
+ if (theDesc.nameHash() == inNameHash)
return idx;
}
return Empty();
@@ -559,19 +554,15 @@ Option<QT3DSU32> STypeDesc::FindProperty(QT3DSU32 inNameHash) const
Option<QT3DSU32> STypeDesc::FindProperty(CRegisteredString inName) const
{
- for (QT3DSU32 idx = 0, end = m_Properties.size(); idx < end; ++idx) {
- const SPropertyDesc &theDesc = m_Properties[idx];
- if (theDesc.m_Name == inName)
- return idx;
- }
- return Empty();
+ const auto hash = Q3DStudio::CHash::HashAttribute(inName);
+ return FindProperty(hash);
}
Option<QT3DSU32> STypeDesc::FindDynamicProperty(QT3DSU32 inNameHash) const
{
for (QT3DSU32 idx = 0, end = m_DynamicProperties.size(); idx < end; ++idx) {
const SPropertyDesc &theDesc = m_DynamicProperties[idx];
- if (Q3DStudio::CHash::HashAttribute(theDesc.m_Name) == inNameHash)
+ if (theDesc.nameHash() == inNameHash)
return idx;
}
return Empty();
@@ -581,16 +572,29 @@ void STypeDesc::SetHashValue()
{
size_t typeDescHash = m_TypeName.hash() ^ m_SubtypeName.hash();
for (QT3DSU32 idx = 0, end = m_Properties.size(); idx < end; ++idx) {
- typeDescHash = typeDescHash ^ m_Properties[idx].m_Name.hash();
- typeDescHash = typeDescHash ^ eastl::hash<QT3DSU32>()(m_Properties[idx].m_Type);
+ typeDescHash = typeDescHash ^ m_Properties[idx].name().hash();
+ typeDescHash = typeDescHash ^ eastl::hash<QT3DSU32>()(m_Properties[idx].type());
}
// TODO check 64 bit compatibility
m_HashValue = (QT3DSU32)typeDescHash;
}
-QT3DSU32 SPropertyDesc::GetNameHash() const
+SPropertyDesc::SPropertyDesc(CRegisteredString inStr, Q3DStudio::EAttributeType inType)
+ : m_Name(inStr)
+ , m_nameHash(Q3DStudio::CHash::HashAttribute(inStr.c_str()))
+ , m_Type(inType)
+{
+}
+
+void SPropertyDesc::setName(CRegisteredString name)
{
- return Q3DStudio::CHash::HashAttribute(m_Name.c_str());
+ m_Name = name;
+ m_nameHash = Q3DStudio::CHash::HashAttribute(name.c_str());
+}
+
+QT3DSU32 SPropertyDesc::nameHash() const
+{
+ return m_nameHash;
}
Q3DStudio::SAttributeKey SPropertyDesc::GetAttributeKey() const
@@ -598,7 +602,7 @@ Q3DStudio::SAttributeKey SPropertyDesc::GetAttributeKey() const
Q3DStudio::SAttributeKey retval;
memZero(&retval, sizeof(retval));
retval.m_Type = m_Type;
- retval.m_Hash = GetNameHash();
+ retval.m_Hash = nameHash();
return retval;
}
@@ -644,10 +648,13 @@ void SElement::SetAttribute(const Q3DStudio::TAttributeHash inKey,
const Q3DStudio::UVariant inValue)
{
Option<TPropertyDescAndValuePtr> existing = FindProperty(inKey);
- if (existing.hasValue() == false) {
+ if (!existing.hasValue()) {
if (Q3DStudio::ATTRIBUTE_EYEBALL == inKey)
SetFlag(Q3DStudio::ELEMENTFLAG_EXPLICITACTIVE, inValue.m_INT32 ? true : false);
- return;
+ else
+ existing = FindDynamicProperty(inKey);
+ if (!existing.hasValue())
+ return;
}
SetAttribute(*existing, inValue);
}
@@ -667,9 +674,9 @@ void SElement::stopAnimations(QT3DSU32 propHash)
void SElement::SetAttribute(TPropertyDescAndValuePtr inKey, const Q3DStudio::UVariant inValue,
bool forceSet)
{
- Q3DStudio::EAttributeType theType = inKey.first.m_Type;
+ Q3DStudio::EAttributeType theType = inKey.first.type();
Q3DStudio::UVariant *currentValue = inKey.second;
- QT3DSU32 attHash = inKey.first.GetNameHash();
+ QT3DSU32 attHash = inKey.first.nameHash();
// If there is an active animation for this property, disable it. Otherwise the set value
// gets overwritten immediately as animation update takes place.
@@ -716,10 +723,44 @@ void SElement::SetAttribute(TPropertyDescAndValuePtr inKey, const Q3DStudio::UVa
SetDirty();
}
+void SElement::setParent(SElement *parent)
+{
+ if (m_Parent)
+ m_Parent->removeChild(this);
+ m_Parent = parent;
+ if (m_Parent)
+ m_Parent->addChild(this);
+}
+void SElement::addChild(SElement *child)
+{
+ m_children.insert(child->GetNameHash(), child);
+}
+
+void SElement::removeChild(SElement *child)
+{
+ auto key = m_children.key(child);
+ m_children.remove(key);
+}
+
+void SElement::updateChildName(SElement *child)
+{
+ auto key = m_children.key(child);
+ m_children.remove(key);
+ m_children.insert(child->GetNameHash(), child);
+}
+
+void SElement::setName(CRegisteredString name)
+{
+ m_Name = name;
+ m_nameHash = Q3DStudio::CHash::HashString(name);
+ if (m_Parent)
+ m_Parent->updateChildName(this);
+}
+
// SElement implementation
QT3DSU32 SElement::GetNameHash() const
{
- return Q3DStudio::CHash::HashString(m_Name.c_str());
+ return m_nameHash;
}
// Q3DStudio::CHash::HashAttribute
@@ -845,11 +886,7 @@ const SElement &SElement::GetComponentParent() const
SElement *SElement::FindChild(QT3DSU32 inNameHash)
{
- for (SElement *theChild = m_Child; theChild; theChild = theChild->m_Sibling) {
- if (theChild->GetNameHash() == inNameHash)
- return theChild;
- }
- return NULL;
+ return m_children.value(inNameHash);
}
Q3DStudio::TTimeUnit SElement::GetInnerTime() const