summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Timeline/Bindings
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2018-05-11 14:34:55 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2018-05-14 07:44:08 +0000
commitd8951711c3f5a2f52c24715f15f9a446ca7ae755 (patch)
tree247fbb9a2ec323d6d7a825c86131b1ab4a15a797 /src/Authoring/Studio/Palettes/Timeline/Bindings
parent4f3612e4c2c79ec61269de8581138b44267608b5 (diff)
Optimize iterating through child objects
GetAssetChildrenInTimeParent was getting called unnecessarily much, as it was called every time GetChildrenCount or GetChild was called. According to profiling it was responsible for vast majority of the time spent when changing a slide. Optimized various loops that iterate through object's children to only call this function once. Task-number: QT3DS-1601 Change-Id: Ia006acb76bd818c390a36f6fe9f1656660974c0e Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io> Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Palettes/Timeline/Bindings')
-rw-r--r--src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h1
-rw-r--r--src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp156
-rw-r--r--src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h2
-rw-r--r--src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp11
-rw-r--r--src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h1
-rw-r--r--src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp41
-rw-r--r--src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h1
7 files changed, 134 insertions, 79 deletions
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h
index 9469981d..9a5f7e3e 100644
--- a/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h
+++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h
@@ -99,6 +99,7 @@ public:
// Hierarchy
virtual long GetChildrenCount() = 0;
virtual ITimelineItemBinding *GetChild(long inIndex) = 0;
+ virtual QList<ITimelineItemBinding *> GetChildren() = 0;
virtual ITimelineItemBinding *GetParent() = 0;
virtual void SetParent(ITimelineItemBinding *parent) = 0;
// Properties
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp
index 7cd9bfe6..9b11c389 100644
--- a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp
+++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.cpp
@@ -131,9 +131,6 @@ EStudioObjectType CLayerTimelineItemBinding::GetObjectType() const
ITimelineItemBinding *CLayerTimelineItemBinding::GetChild(long inIndex)
{
- static const TCharStr theLayerPrefix(L"Layer_");
- qt3dsdm::IPropertySystem *thePropertySystem = m_TransMgr->GetStudioSystem()->GetPropertySystem();
-
qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance();
if (theInstance.Valid()) {
Q3DStudio::CGraphIterator theChildren;
@@ -141,74 +138,29 @@ ITimelineItemBinding *CLayerTimelineItemBinding::GetChild(long inIndex)
GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(),
theChildren, theActiveSlide);
theChildren += inIndex;
+ return GetOrCreateBinding(theChildren.GetCurrent());
+ }
+ return nullptr;
+}
- qt3dsdm::Qt3DSDMInstanceHandle theChildInstance = theChildren.GetCurrent();
- if (theChildInstance.Valid()) {
- std::shared_ptr<IDataCore> theDataCore =
- m_TransMgr->GetStudioSystem()->GetFullSystem()->GetCoreSystem()->GetDataCore();
- ISlideSystem *theSlideSystem = m_TransMgr->GetStudioSystem()->GetSlideSystem();
- ISlideCore *theSlideCore = m_TransMgr->GetStudioSystem()->GetSlideCore();
-
- size_t theSlotCursor = (size_t)-1;
- {
-
- qt3dsdm::IPropertySystem *thePropertySystem =
- m_TransMgr->GetStudioSystem()->GetPropertySystem();
- qt3dsdm::SLong4 theGuid;
- {
- Qt3DSDMPropertyHandle theTypeProperty =
- thePropertySystem->GetAggregateInstancePropertyByName(theChildInstance,
- L"id");
- SValue theIdValue;
- thePropertySystem->GetInstancePropertyValue(theChildInstance, theTypeProperty,
- theIdValue);
- theGuid = qt3dsdm::get<qt3dsdm::SLong4>(theIdValue);
- }
- for (size_t theSlotIndex = 0, theSlotCount = m_ImageNameFormalNamePairs.size();
- theSlotIndex < theSlotCount; ++theSlotIndex) {
- bool theIsMatch = false;
- qt3dsdm::Qt3DSDMPropertyHandle theProperty =
- std::get<2>(m_ImageNameFormalNamePairs[theSlotIndex]);
- SValue theValue;
- const Qt3DSDMPropertyDefinition &theDefinition(
- theDataCore->GetProperty(theProperty));
- if (theDefinition.m_Type == DataModelDataType::Long4) {
- SValue theDCValue;
- if (theDataCore->GetInstancePropertyValue(theInstance, theProperty,
- theDCValue)) {
- SLong4 thePropGuid = get<SLong4>(theDCValue);
- if (thePropGuid == theGuid)
- theIsMatch = true;
- }
- Qt3DSDMSlideHandle theSlide =
- theSlideSystem->GetAssociatedSlide(theChildInstance);
- Qt3DSDMSlideHandle theMasterSlide = theSlideSystem->GetMasterSlide(theSlide);
- if (theIsMatch == false && theSlide.Valid()
- && theSlideCore->GetSpecificInstancePropertyValue(
- theSlide, theInstance, theProperty, theValue)) {
- SLong4 thePropGuid = get<SLong4>(theValue);
- if (thePropGuid == theGuid)
- theIsMatch = true;
- }
- }
- if (theIsMatch) {
- theSlotCursor = theSlotIndex;
- break;
- }
- }
- }
- if (theSlotCursor != (size_t)-1) {
- Qt3DSDMPropertyHandle theImageProperty =
- thePropertySystem->GetAggregateInstancePropertyByName(
- m_DataHandle, std::get<0>(m_ImageNameFormalNamePairs[theSlotCursor]));
- return GetOrCreateImageBinding(
- theImageProperty,
- std::get<1>(m_ImageNameFormalNamePairs[theSlotCursor]).wide_str());
- } else
- return m_TransMgr->GetOrCreate(theChildInstance);
+QList<ITimelineItemBinding *> CLayerTimelineItemBinding::GetChildren()
+{
+ QList<ITimelineItemBinding *> retlist;
+ qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance();
+ if (theInstance.Valid()) {
+ Q3DStudio::CGraphIterator theChildren;
+ Qt3DSDMSlideHandle theActiveSlide = m_TransMgr->GetDoc()->GetActiveSlide();
+ GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(),
+ theChildren, theActiveSlide);
+ int childCount = int(theChildren.GetCount());
+ retlist.reserve(childCount);
+ for (int i = 0; i < childCount; ++i) {
+ retlist.append(GetOrCreateBinding(theChildren.GetCurrent()));
+ ++theChildren;
}
}
- return nullptr;
+
+ return retlist;
}
void CLayerTimelineItemBinding::OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance)
@@ -315,3 +267,71 @@ CLayerTimelineItemBinding::GetOrCreateImageBinding(qt3dsdm::Qt3DSDMPropertyHandl
}
return theImageTimelineRow;
}
+
+ITimelineItemBinding *CLayerTimelineItemBinding::GetOrCreateBinding(Qt3DSDMInstanceHandle instance)
+{
+ if (instance.Valid()) {
+ qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance();
+ qt3dsdm::IPropertySystem *thePropertySystem =
+ m_TransMgr->GetStudioSystem()->GetPropertySystem();
+ std::shared_ptr<IDataCore> theDataCore =
+ m_TransMgr->GetStudioSystem()->GetFullSystem()->GetCoreSystem()->GetDataCore();
+ ISlideSystem *theSlideSystem = m_TransMgr->GetStudioSystem()->GetSlideSystem();
+ ISlideCore *theSlideCore = m_TransMgr->GetStudioSystem()->GetSlideCore();
+
+ size_t theSlotCursor = (size_t)-1;
+ {
+ qt3dsdm::IPropertySystem *thePropertySystem =
+ m_TransMgr->GetStudioSystem()->GetPropertySystem();
+ qt3dsdm::SLong4 theGuid;
+ {
+ Qt3DSDMPropertyHandle theTypeProperty =
+ thePropertySystem->GetAggregateInstancePropertyByName(instance, L"id");
+ SValue theIdValue;
+ thePropertySystem->GetInstancePropertyValue(instance, theTypeProperty, theIdValue);
+ theGuid = qt3dsdm::get<qt3dsdm::SLong4>(theIdValue);
+ }
+ for (size_t theSlotIndex = 0, theSlotCount = m_ImageNameFormalNamePairs.size();
+ theSlotIndex < theSlotCount; ++theSlotIndex) {
+ bool theIsMatch = false;
+ qt3dsdm::Qt3DSDMPropertyHandle theProperty =
+ std::get<2>(m_ImageNameFormalNamePairs[theSlotIndex]);
+ SValue theValue;
+ const Qt3DSDMPropertyDefinition &theDefinition(
+ theDataCore->GetProperty(theProperty));
+ if (theDefinition.m_Type == DataModelDataType::Long4) {
+ SValue theDCValue;
+ if (theDataCore->GetInstancePropertyValue(theInstance, theProperty,
+ theDCValue)) {
+ SLong4 thePropGuid = get<SLong4>(theDCValue);
+ if (thePropGuid == theGuid)
+ theIsMatch = true;
+ }
+ Qt3DSDMSlideHandle theSlide =
+ theSlideSystem->GetAssociatedSlide(instance);
+ Qt3DSDMSlideHandle theMasterSlide = theSlideSystem->GetMasterSlide(theSlide);
+ if (theIsMatch == false && theSlide.Valid()
+ && theSlideCore->GetSpecificInstancePropertyValue(
+ theSlide, theInstance, theProperty, theValue)) {
+ SLong4 thePropGuid = get<SLong4>(theValue);
+ if (thePropGuid == theGuid)
+ theIsMatch = true;
+ }
+ }
+ if (theIsMatch) {
+ theSlotCursor = theSlotIndex;
+ break;
+ }
+ }
+ }
+ if (theSlotCursor != (size_t)-1) {
+ Qt3DSDMPropertyHandle theImageProperty =
+ thePropertySystem->GetAggregateInstancePropertyByName(
+ m_DataHandle, std::get<0>(m_ImageNameFormalNamePairs[theSlotCursor]));
+ return GetOrCreateImageBinding(
+ theImageProperty,
+ std::get<1>(m_ImageNameFormalNamePairs[theSlotCursor]).wide_str());
+ } else
+ return m_TransMgr->GetOrCreate(instance);
+ }
+}
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h
index 3d74625e..74630a64 100644
--- a/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h
+++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/LayerTimelineItemBinding.h
@@ -64,6 +64,7 @@ public: // Qt3DSDMTimelineItemBinding
EStudioObjectType GetObjectType() const override;
// Hierarchy
ITimelineItemBinding *GetChild(long inIndex) override;
+ QList<ITimelineItemBinding *> GetChildren() override;
void OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance) override;
// Event callback
void OnPropertyChanged(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle) override;
@@ -72,6 +73,7 @@ protected:
qt3dsdm::Qt3DSDMInstanceHandle GetImage(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle);
ITimelineItemBinding *GetOrCreateImageBinding(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle,
const wchar_t *inName);
+ ITimelineItemBinding *GetOrCreateBinding(qt3dsdm::Qt3DSDMInstanceHandle instance);
};
#endif // INCLUDED_LAYER_TIMELINEITEM_BINDING_H
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp
index 0d4bfde5..55598353 100644
--- a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp
+++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.cpp
@@ -160,6 +160,17 @@ ITimelineItemBinding *CMaterialTimelineItemBinding::GetChild(long inIndex)
theImageProperty, std::get<1>(m_ImageNameFormalNamePairs[theSlotCursor]).wide_str());
}
+QList<ITimelineItemBinding *> CMaterialTimelineItemBinding::GetChildren()
+{
+ int childCount = GetChildrenCount();
+ QList<ITimelineItemBinding *> retlist;
+ retlist.reserve(childCount);
+ for (int i = 0; i < childCount; ++i)
+ retlist.append(GetChild(i));
+
+ return retlist;
+}
+
void CMaterialTimelineItemBinding::OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance)
{
using namespace qt3dsdm;
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h
index 252363e2..80e7bc47 100644
--- a/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h
+++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/MaterialTimelineItemBinding.h
@@ -69,6 +69,7 @@ public: // Qt3DSDMTimelineItemBinding
// Hierarchy
long GetChildrenCount() override;
ITimelineItemBinding *GetChild(long inIndex) override;
+ QList<ITimelineItemBinding *> GetChildren() override;
void OnAddChild(qt3dsdm::Qt3DSDMInstanceHandle inInstance) override;
// Event callback
void OnPropertyChanged(qt3dsdm::Qt3DSDMPropertyHandle inPropertyHandle) override;
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp
index dd2989fa..9592b8ba 100644
--- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp
+++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp
@@ -180,13 +180,10 @@ void ToggleChildrenLock(Q3DStudio::ScopedDocumentEditor &scopedDocEditor,
{
scopedDocEditor->SetInstancePropertyValue(inTimelineItemBinding->GetInstanceHandle(),
inSceneAsset.m_Locked, inLocked);
- long childrenCount = inTimelineItemBinding->GetChildrenCount();
- if (childrenCount == 0)
- return;
- for (long i = 0; i < childrenCount; ++i) {
- Qt3DSDMTimelineItemBinding *child =
- static_cast<Qt3DSDMTimelineItemBinding *>(inTimelineItemBinding->GetChild(i));
- ToggleChildrenLock(scopedDocEditor, child, inSceneAsset, inLocked);
+ const QList<ITimelineItemBinding *> children = inTimelineItemBinding->GetChildren();
+ for (auto child : children) {
+ ToggleChildrenLock(scopedDocEditor, static_cast<Qt3DSDMTimelineItemBinding *>(child),
+ inSceneAsset, inLocked);
}
}
@@ -466,6 +463,29 @@ ITimelineItemBinding *Qt3DSDMTimelineItemBinding::GetChild(long inIndex)
return nullptr;
}
+QList<ITimelineItemBinding *> Qt3DSDMTimelineItemBinding::GetChildren()
+{
+ QList<ITimelineItemBinding *> retlist;
+ qt3dsdm::Qt3DSDMInstanceHandle theInstance = GetInstance();
+ if (theInstance.Valid()) {
+ Q3DStudio::CGraphIterator theChildren;
+ Qt3DSDMSlideHandle theActiveSlide = m_TransMgr->GetDoc()->GetActiveSlide();
+ GetAssetChildrenInTimeParent(theInstance, m_TransMgr->GetDoc(), AmITimeParent(),
+ theChildren, theActiveSlide);
+ int childCount = int(theChildren.GetCount());
+ retlist.reserve(childCount);
+
+ for (int i = 0; i < childCount; ++i) {
+ qt3dsdm::Qt3DSDMInstanceHandle theChildInstance = theChildren.GetCurrent();
+ if (theChildInstance.Valid())
+ retlist.append(m_TransMgr->GetOrCreate(theChildInstance));
+ ++theChildren;
+ }
+ }
+
+ return retlist;
+}
+
ITimelineItemBinding *Qt3DSDMTimelineItemBinding::GetParent()
{
return m_Parent;
@@ -890,11 +910,10 @@ void Qt3DSDMTimelineItemBinding::RefreshStateRow(bool inRefreshChildren)
theRow->OnTimeChange();
theRow->setDirty(false);
if (inRefreshChildren) {
- long theChildrenCount = GetChildrenCount();
- for (long theIndex = 0; theIndex < theChildrenCount; ++theIndex) {
- ITimelineItemBinding *theChild = GetChild(theIndex);
+ const QList<ITimelineItemBinding *> children = GetChildren();
+ for (auto child : children) {
Qt3DSDMTimelineItemBinding *theBinding =
- dynamic_cast<Qt3DSDMTimelineItemBinding *>(theChild);
+ static_cast<Qt3DSDMTimelineItemBinding *>(child);
if (theBinding)
theBinding->RefreshStateRow(inRefreshChildren);
}
diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h
index b79d1a96..2e253fbe 100644
--- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h
+++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.h
@@ -135,6 +135,7 @@ public:
// Hierarchy
long GetChildrenCount() override;
ITimelineItemBinding *GetChild(long inIndex) override;
+ QList<ITimelineItemBinding *> GetChildren() override;
ITimelineItemBinding *GetParent() override;
void SetParent(ITimelineItemBinding *parent) override;
// Properties